Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify previous stateid and stateid #174

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions src/Take.Blip.Builder.UnitTests/FlowManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public async Task FlowWithoutConditionsShouldChangeStateAndSendMessage()

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -149,8 +149,8 @@ public async Task FlowWithActionWithVariableShouldBeReplaced()

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -221,8 +221,8 @@ public async Task FlowWithActionWithJsonVariableShouldBeEscapedAndReplaced()

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -289,8 +289,8 @@ public async Task FlowWithActionWithVariableThatNotExistsShouldBeReplacedByEmpty

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -658,7 +658,8 @@ public async Task FlowWithInputVariableShouldSaveInContext()
// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
Context.Received(1).SetVariableAsync(variableName, input.Text, Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Arg.Any<IContext>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Arg.Any<IContext>(), "", "root", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Arg.Any<IContext>(), Arg.Is<String>(i => !i.IsNullOrEmpty()), "root", Arg.Any<CancellationToken>());
}

[Fact]
Expand Down Expand Up @@ -704,7 +705,8 @@ public async Task FlowWithoutInputVariableShouldNotSaveInContext()
// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == Message.Content), flow);
Context.Received(0).SetVariableAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Arg.Any<IContext>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Arg.Any<IContext>(), "first", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Arg.Any<IContext>(), "", "first", Arg.Any<CancellationToken>());
}

[Fact]
Expand Down Expand Up @@ -881,9 +883,10 @@ public async Task FlowWithContextConditionsShouldChangeStateAndSendMessage()
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "marco", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "marco", "root", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "marco", "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -1070,11 +1073,11 @@ public async Task FlowWithInputContextConditionsSatisfiedShouldKeepStateAndWaitN
await target.ProcessInputAsync(inputOk, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "Start", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "error", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "Ok", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "NOk", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "Start", "root", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "", Arg.Any<String>(), Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "error", Arg.Any<String>(), Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "Ok", Arg.Any<String>(), Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "NOk", Arg.Any<String>(), Arg.Any<CancellationToken>());

Sender
.DidNotReceive()
Expand Down Expand Up @@ -1257,11 +1260,11 @@ public async Task FlowWithInputContextConditionsNotSatisfiedShouldChangeStateAnd
await target.ProcessInputAsync(inputNOk, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "Start", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "error", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "NOk", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "Ok", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "Start", "root", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "error", Arg.Any<String>(), Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "NOk", "Start", Arg.Any<CancellationToken>());
StateManager.DidNotReceive().SetStateIdAsync(Context, "Ok", Arg.Any<String>(), Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "NOk", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down Expand Up @@ -1391,9 +1394,10 @@ public async Task FlowWithConditionsAndMultipleInputsShouldChangeStatesAndSendMe
await target.ProcessInputAsync(input2, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "marco", Arg.Any<CancellationToken>());
StateManager.Received(2).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "marco", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "marco", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -1520,8 +1524,8 @@ public async Task FlowWithoutIntentConditionsShouldChangeStateAndSendMessage()

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "my-intent", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "my-intent", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "my-intent", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -1643,8 +1647,8 @@ public async Task FlowWithoutEntityConditionsShouldChangeStateAndSendMessage()

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "my-entity", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "my-entity", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "my-entity", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -1823,8 +1827,8 @@ public async Task ActionWithInvalidSettingShouldNotBreakProcessingWhenContinueOn

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
}

#region TemporaryInput
Expand Down Expand Up @@ -1871,7 +1875,7 @@ public async Task FlowWithTemporaryInputShouldScheduleAInputExpirationTimeMessag

// Assert
ContextProvider.Received(1).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
SchedulerExtension
.Received(1)
.ScheduleMessageAsync(
Expand Down Expand Up @@ -1997,8 +2001,8 @@ public async Task FlowWithTemporaryInputShouldCancelScheduleWhenUserSendOtherInp

// Assert
ContextProvider.Received(2).CreateContext(UserIdentity, ApplicationIdentity, Arg.Is<LazyInput>(i => i.Content == input), flow);
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping2", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping2", "ping", Arg.Any<CancellationToken>());
SchedulerExtension
.Received(1)
.ScheduleMessageAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public async Task FlowWithRegexInputValidationShouldChangeStateProperly()
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "state2", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "state2", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "state2", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down Expand Up @@ -157,8 +157,8 @@ public async Task FlowWithInvalidRegexInputValidationShouldFailAndNotChangeState
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(0).SetStateIdAsync(Context, "state2", Arg.Any<CancellationToken>());
StateManager.Received(0).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Context, "state2", "root", Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Context, "", "state2", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down Expand Up @@ -233,8 +233,8 @@ public async Task FlowWithNumberInputValidationShouldChangeStateProperly()
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "state2", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "state2", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "state2", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down Expand Up @@ -309,8 +309,8 @@ public async Task FlowWithInvalidNumberInputValidationShouldFailAndNotChangeStat
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(0).SetStateIdAsync(Context, "state2", Arg.Any<CancellationToken>());
StateManager.Received(0).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Context, "state2", "root", Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Context, "", "state2", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down Expand Up @@ -392,8 +392,8 @@ public async Task FlowWithTypeInputValidationShouldSendMessageWhenInvalid()
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -483,8 +483,8 @@ public async Task FlowWithInvalidTypeInputValidationShouldFailAndNotChangeStateP
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());
Sender
.Received(1)
.SendMessageAsync(
Expand Down Expand Up @@ -577,8 +577,8 @@ public async Task FlowWithDateValidationShouldChangeStateProperly(string format)
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(1).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(1).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(1).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down Expand Up @@ -653,8 +653,8 @@ public async Task FlowWithInvalidDateValidationShouldFailAndNotChangeStateProper
await target.ProcessInputAsync(Message, flow, CancellationToken);

// Assert
StateManager.Received(0).SetStateIdAsync(Context, "ping", Arg.Any<CancellationToken>());
StateManager.Received(0).DeleteStateIdAsync(Context, Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Context, "ping", "root", Arg.Any<CancellationToken>());
StateManager.Received(0).SetStateIdAsync(Context, "", "ping", Arg.Any<CancellationToken>());

Sender
.Received(1)
Expand Down
Loading