* Trivial - Add VS Code workspace * Trivial - Add VSCode build task & extra ignore On GNU/Linux, auto-generated .directory files should be ignored. * WIP #485 - Boilerplate for unit test project * WIP #485 - Add test coverage (Remove/RemoveAll) * WIP #485 - Implement RemoveAll * Remove redundant logic, covered by IDictionary Per the following, the contract for a generic IDictionary, the Remove method already deals with non-existent keys. https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.idictionary-2.remove?view=net-5.0#System_Collections_Generic_IDictionary_2_Remove__0_ * Resolve #485 - Add PurgeVariables methods These are convenience methods upon ActivityExecutionContext and WorkflowExecutionContext, consistent with their current APIs. Also in this commit are tests for those simple methods. There's a bit of test-scaffold as well included, such as: * Autofixture Xunit2 integration * New project for unit tests * Customize attribute for avoiding crashes on Autofixture recursion * Reusable specimen builder for creating IServiceProvider which resolves services from Autofixture * Custonize attribute for a parameter to use that ^^ specimen builder
60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using Xunit;
|
|
|
|
namespace Elsa.Models
|
|
{
|
|
public class VariablesTests
|
|
{
|
|
[Theory(DisplayName = "The Remove method should remove a variable if such a variable exists"), AutoMoqData]
|
|
public void Remove_removes_a_variable_by_name_if_present(string variableName, object variableData)
|
|
{
|
|
var sut = new Variables(new Dictionary<string,object> { { variableName, variableData } });
|
|
|
|
sut.Remove(variableName);
|
|
|
|
Assert.Empty(sut.Data);
|
|
}
|
|
|
|
[Theory(DisplayName = "The Remove method should not throw if used with a non-existent variable"), AutoMoqData]
|
|
public void Remove_does_not_throw_when_trying_to_remove_a_variable_which_does_not_exist(string variableName)
|
|
{
|
|
var sut = new Variables();
|
|
|
|
sut.Remove(variableName);
|
|
|
|
// No assertion, if the line about doesn't throw then this test passed
|
|
}
|
|
|
|
[Theory(DisplayName = "The Remove method should support call-chaining by returning a self-reference"), AutoMoqData]
|
|
public void Remove_returns_a_reference_to_itself(Variables sut, string variableName)
|
|
{
|
|
var result = sut.Remove(variableName);
|
|
Assert.Same(sut, result);
|
|
}
|
|
|
|
[Theory(DisplayName = "The RemoveAll method should leave the variables collection empty"), AutoMoqData]
|
|
public void RemoveAll_clears_all_variables(string variableName1,
|
|
string variableName2,
|
|
string variableName3,
|
|
object variableData)
|
|
{
|
|
var sut = new Variables(new Dictionary<string,object> {
|
|
{ variableName1, variableData },
|
|
{ variableName2, variableData },
|
|
{ variableName3, variableData },
|
|
});
|
|
|
|
sut.RemoveAll();
|
|
|
|
Assert.Empty(sut.Data);
|
|
}
|
|
|
|
[Theory(DisplayName = "The RemoveAll method should support call-chaining by returning a self-reference"), AutoMoqData]
|
|
public void RemoveAll_returns_a_reference_to_itself(Variables sut)
|
|
{
|
|
var result = sut.RemoveAll();
|
|
Assert.Same(sut, result);
|
|
}
|
|
|
|
}
|
|
} |