public async Task EnterAsyncShouldRaiseEvent() { var invoker = new TestInvoker(context); await sut.EnterAsync(context); invoker.ShouldContainSingle <IBackgroundChangeEvent>(i => i.State.Should().BeSameAs(newState)); }
public async Task OnEnterAsyncShouldRaiseEvent(MoodType moodType, string personName, string protagonist) { var isProtagonist = personName == protagonist; var context = A.Dummy <INavigationContext>(); context.State.PersonName = personName; context.State.ProtagonistName = protagonist; context.State.MoodType = null; var invoker = new TestInvoker(context); var sut = new MoodNode(moodType); var ret = await sut.EnterAsync(context); ret.Should().BeNull(); invoker.ShouldContainSingle <IMoodChangeEvent>( i => i.Should().BeEquivalentTo(new { MoodType = moodType, PersonName = personName, IsProtagonist = isProtagonist }) ); }
public async Task ChoiceMustBeNullWhenAllOptionsAreInvisible() { var when = A.Fake <ICondition>(i => i.Strict()); A.CallTo(() => when.Evaluate(variables)).Returns(false); var choiceNode = new TestChoiceNode { Options = new() { new TestChoiceOptionNode { Key = "a", Text = "Opção1", VisibleWhen = when }, new TestChoiceOptionNode { Key = "b", Text = "Opção2", VisibleWhen = when } } }; var sut = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode); var invoker = new TestInvoker(context); await sut.EnterAsync(context); invoker.ShouldContainSingle <IBalloonTextEvent>( i => i.Should().BeEquivalentTo(new { Text = balloonText, BalloonType = BalloonType.Speech, IsProtagonist = true, Choice = (IChoice)null }) ); }
public async Task ChoiceMustBeNullWhenThereAreNoOptions() { var when = A.Fake <ICondition>(i => i.Strict()); A.CallTo(() => when.Evaluate(variables)).Returns(false); var choiceNode = new TestChoiceNode { Options = new() }; var sut = new BalloonTextNode(textSource, BalloonType.Tutorial, choiceNode); var invoker = new TestInvoker(context); await sut.EnterAsync(context); invoker.ShouldContainSingle <IBalloonTextEvent>( i => i.Should().BeEquivalentTo(new { Text = balloonText, BalloonType = BalloonType.Tutorial, IsProtagonist = true, Choice = (IChoice)null }) ); }
public async Task OnEnterAsyncShouldEvaluateOptionEnabledCondition() { var when1 = A.Fake <ICondition>(i => i.Strict()); A.CallTo(() => when1.Evaluate(variables)).Returns(true); var when2 = A.Fake <ICondition>(i => i.Strict()); A.CallTo(() => when2.Evaluate(variables)).Returns(false); var when3 = A.Fake <ICondition>(i => i.Strict()); A.CallTo(() => when3.Evaluate(variables)).Returns(false); var choiceNode = new TestChoiceNode { Options = new() { new TestChoiceOptionNode { Key = "a", Text = "Opção1", DisabledText = "Inativa", EnabledWhen = when1 }, new TestChoiceOptionNode { Key = "b", Text = "Opção2", DisabledText = "Não ativa", EnabledWhen = when2 }, new TestChoiceOptionNode { Key = "c", Text = "Opção3", EnabledWhen = when3 } } }; var sut = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode); var invoker = new TestInvoker(context); await sut.EnterAsync(context); invoker.ShouldContainSingle <IBalloonTextEvent>( i => i.Should().BeEquivalentTo(new { Text = balloonText, BalloonType = BalloonType.Speech, IsProtagonist = true, Choice = new { TimeLimit = (TimeSpan?)null, Default = (string)null, Options = new[] { new { Key = "a", Text = "Opção1", IsEnabled = true, ImageName = (string)null, HelpText = (string)null }, new { Key = "b", Text = "Não ativa", IsEnabled = false, ImageName = (string)null, HelpText = (string)null }, new { Key = "c", Text = "Opção3", IsEnabled = false, ImageName = (string)null, HelpText = (string)null } } } }) ); A.CallTo(() => when1.Evaluate(variables)).MustHaveHappenedOnceExactly(); A.CallTo(() => when2.Evaluate(variables)).MustHaveHappenedOnceExactly(); A.CallTo(() => when3.Evaluate(variables)).MustHaveHappenedOnceExactly(); }
public async Task ShouldRaiseEventWithStateArg(string stateArg) { var context = A.Dummy <INavigationContext>(); context.State.MusicName = "theme"; var invoker = new TestInvoker(context); var sut = new MusicNode("goodbye", null); await sut.EnterAsync(context, stateArg); invoker.ShouldContainSingle <IMusicChangeEvent>( i => i.Should().BeEquivalentTo(new { MusicName = stateArg }) ); }
public async Task OnEnterShouldRaiseEvent(string currentValue, string newValue) { var context = A.Dummy <INavigationContext>(); context.State.ProtagonistName = currentValue; var invoker = new TestInvoker(context); var sut = new ProtagonistNode(newValue, null); await sut.EnterAsync(context); invoker.ShouldContainSingle <IProtagonistChangeEvent>( i => i.Should().BeEquivalentTo(new { PersonName = newValue }) ); }
public async Task RandomOrder() { var choiceNode = new TestChoiceNode { RandomOrder = true, Options = new() { new TestChoiceOptionNode { Key = "a", Text = "Opção1" }, new TestChoiceOptionNode { Key = "b", Text = "Opção2" } } }; var shuffled = new List <IChoiceOption> { A.Fake <IChoiceOption>(i => i.ConfigureFake(i => { A.CallTo(() => i.IsEnabled).Returns(true); })) }; var randomizer = A.Fake <IRandomizer>(i => i.Strict()); A.CallTo(() => randomizer.Shuffle(A <List <IChoiceOption> > .Ignored)).Returns(shuffled); A.CallTo(() => context.Randomizer).Returns(randomizer); var sut = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode); var invoker = new TestInvoker(context); await sut.EnterAsync(context); invoker.ShouldContainSingle <IBalloonTextEvent>( i => i.Should().BeEquivalentTo(new { Text = balloonText, BalloonType = BalloonType.Speech, IsProtagonist = true, Choice = new { TimeLimit = (TimeSpan?)null, Default = (string)null, Options = shuffled } }) ); }
public async Task EnterAsync() { var context = A.Dummy <INavigationContext>(); var invoker = new TestInvoker(context); var duration = TimeSpan.FromMilliseconds(234567); var sut = new TimedPauseNode(duration, null); var ret = await sut.EnterAsync(context); ret.Should().BeNull(); invoker.ShouldContainSingle <ITimedPauseEvent>( i => i.Should().BeEquivalentTo(new { Duration = duration }) ); }
public async Task ShouldRaiseEventWithStateArg(string stageArg) { var context = A.Dummy <INavigationContext>(); context.State.ProtagonistName = "alpha"; var invoker = new TestInvoker(context); var sut = new ProtagonistNode("beta", null); await sut.EnterAsync(context, stageArg); invoker.ShouldContainSingle <IProtagonistChangeEvent>( i => i.Should().BeEquivalentTo(new { PersonName = stageArg }) ); context.State.ProtagonistName.Should().Be(stageArg); }
public async Task OnEnterAsyncWithChoice() { state.PersonName = "mu"; state.ProtagonistName = "pi"; var choiceNode = new TestChoiceNode { TimeLimit = TimeSpan.FromSeconds(3), Default = "a", Options = new() { new TestChoiceOptionNode { Key = "a", Text = "Opção1" }, new TestChoiceOptionNode { Key = "b", Text = "Opção2", ImageName = "abc", HelpText = "help" } } }; var sut = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode); var invoker = new TestInvoker(context); await sut.EnterAsync(context); invoker.ShouldContainSingle <IBalloonTextEvent>( i => i.Should().BeEquivalentTo(new { Text = balloonText, BalloonType = BalloonType.Speech, IsProtagonist = false, Choice = new { TimeLimit = TimeSpan.FromSeconds(3), Default = "a", Options = new[] { new { Key = "a", Text = "Opção1", IsEnabled = true, ImageName = (string)null, HelpText = (string)null }, new { Key = "b", Text = "Opção2", IsEnabled = true, ImageName = "abc", HelpText = "help" } } } }) ); }
public async Task OnLeaveAsyncShouldRaiseEvent(string personName, string protagonist) { var isProtagonist = personName == protagonist; var context = A.Dummy <INavigationContext>(); context.State.ProtagonistName = protagonist; var invoker = new TestInvoker(context); var childBlock = A.Dummy <IBlock>(); var sut = new PersonNode(personName, childBlock); await sut.LeaveAsync(context); invoker.ShouldContainSingle <IPersonLeaveEvent>( i => i.Should().BeEquivalentTo(new { PersonName = personName, IsProtagonist = isProtagonist }) ); }
public async Task OnEnterAsyncShouldRaiseEvent(BalloonType balloonType, bool isProtagonist) { state.PersonName = "alpha"; state.ProtagonistName = isProtagonist ? "alpha" : "beta"; var sut = new BalloonTextNode(textSource, balloonType, null); var invoker = new TestInvoker(context); var ret = await sut.EnterAsync(context); ret.Should().BeNull(); invoker.ShouldContainSingle <IBalloonTextEvent>( i => i.Should().BeEquivalentTo(new { Text = balloonText, BalloonType = balloonType, IsProtagonist = isProtagonist, Choice = (IChoice)null }) ); }
public async Task OnEnterShouldReturnPreviousMood() { var context = A.Dummy <INavigationContext>(); context.State.MoodType = MoodType.Surprised; context.State.PersonName = "abc"; var invoker = new TestInvoker(context); var sut = new MoodNode(MoodType.Happy); var ret = await sut.EnterAsync(context); ret.Should().Be(MoodType.Surprised); invoker.ShouldContainSingle <IMoodChangeEvent>( i => i.Should().BeEquivalentTo(new { MoodType = MoodType.Happy, PersonName = "abc", IsProtagonist = false }) ); }
public async Task ShouldRaiseEventWithStateArg(MoodType moodType) { var context = A.Dummy <INavigationContext>(); context.State.PersonName = "alpha"; context.State.ProtagonistName = "alpha"; context.State.MoodType = MoodType.Happy; var invoker = new TestInvoker(context); var sut = new MoodNode(MoodType.Happy); await sut.EnterAsync(context, moodType); invoker.ShouldContainSingle <IMoodChangeEvent>( i => i.Should().BeEquivalentTo(new { MoodType = moodType, PersonName = "alpha", IsProtagonist = true }) ); }
public async Task EnterAsync(BackgroundPosition oldPosition, BackgroundPosition newPosition) { var oldState = new BackgroundState("alpha", BackgroundType.Image, oldPosition); var newState = new BackgroundState("alpha", BackgroundType.Image, newPosition); var when = A.Dummy <ICondition>(); var context = A.Dummy <INavigationContext>(); context.State.Background = oldState; var invoker = new TestInvoker(context); var sut = new ScrollNode(when); var ret = await sut.EnterAsync(context); ret.Should().BeNull(); invoker.ShouldContainSingle <IBackgroundScrollEvent>( i => i.Should().BeEquivalentTo(new { Position = newPosition }) ); context.State.Background.Should().Be(newState); }