Add more tests

This commit is contained in:
Shkar T. Noori 2022-06-18 12:43:02 +03:00
parent 1b0cd984f8
commit ab80dad816
No known key found for this signature in database
GPG Key ID: C5E1A00F3BB78732

View File

@ -11,6 +11,7 @@ public class WorkflowConditionTests
public void SingleConditionTests() public void SingleConditionTests()
{ {
var phone = new PhoneCall(Active: false); var phone = new PhoneCall(Active: false);
var meta = "String";
var a = "b"; var a = "b";
@ -24,10 +25,14 @@ public class WorkflowConditionTests
.From(PhoneState.Ringing) .From(PhoneState.Ringing)
.On(PhoneCommand.Decline) .On(PhoneCommand.Decline)
.When((res) => a == "b" && res.Active is false) .When((res) => a == "b" && res.Active is false)
.WithMeta(meta)
.To(PhoneState.OnHold); .To(PhoneState.OnHold);
Assert.Empty(builder1.Build().GetAllowedTransitions(phone, PhoneState.Ringing)); Assert.Empty(builder1.Build().GetAllowedTransitions(phone, PhoneState.Ringing));
Assert.Single(builder2.Build().GetAllowedTransitions(phone, PhoneState.Ringing)); Assert.Single(builder2.Build().GetAllowedTransitions(phone, PhoneState.Ringing));
// Check meta
Assert.Equal(meta, builder2.Build().GetAllowedTransitions(phone, PhoneState.Ringing).First().Meta);
} }
[Fact] [Fact]
@ -55,4 +60,13 @@ public class WorkflowConditionTests
Assert.Empty(builder1.Build().GetAllowedTransitions(phone, from: PhoneState.OnHold)); Assert.Empty(builder1.Build().GetAllowedTransitions(phone, from: PhoneState.OnHold));
Assert.Single(builder2.Build().GetAllowedTransitions(phone, from: PhoneState.OnHold)); Assert.Single(builder2.Build().GetAllowedTransitions(phone, from: PhoneState.OnHold));
} }
[Fact]
public void EmptyBuildThrowsError()
{
var builder1 = (WorkflowDefinitionBuilder<PhoneState, PhoneCommand, PhoneCall>)GetDefaultBuilder();
Assert.Throws<InvalidOperationException>(() => builder1.Build());
}
} }