public void ItShouldUseTheTriggersEventCode(Event trigger, IState targetState, State sut) { // Arrange var expected = trigger.Code; // Act sut.AddTransition(trigger, targetState); // Assert sut.HasTransition(expected).Should().BeTrue(); }
public void ItShouldAddTheExpectedTransition(Event trigger, IState targetState, State sut) { // Arrange var likeness = sut.AsSource() .OfLikeness<Transition>() .OmitAutoComparison() .With(x => x.Source).EqualsWhen((inputState, transition) => transition.Source == inputState) .With(x => x.Target).EqualsWhen((inputState, transition) => transition.Target == targetState) .With(x => x.Trigger).EqualsWhen((inputState, transition) => transition.Trigger == trigger); // Act sut.AddTransition(trigger, targetState); // Assert sut.Transitions.Should().HaveCount(1); likeness.ShouldEqual(sut.Transitions.Single()); }
public SecretPanelSemanticModel() { _doorOpened = new Event("DoorOpened", "D1OP"); _doorClosed = new Event("DoorClosed", "D1CL"); _drawerOpened = new Event("DrawerOpened", "D2OP"); _lightOn = new Event("LightOn", "L1ON"); _panelClosed = new Event("PanelClosed", "PNCL"); _lockPanelCmd = new Command("LockPanel", "PNLK"); _unlockPanelCmd = new Command("UnlockPanel", "PNUL"); _lockDoorCmd = new Command("LockDoor", "D1LK"); _unlockDoorCmd = new Command("UnlockDoor", "D1UL"); _idleState = new State("Idle"); _activeState = new State("Active"); _waitingForLightState = new State("WaitingForLight"); _waitingForDrawerState = new State("WaitingForDrawer"); _unlockedPanelState = new State("UnlockedPanel"); SetupTransitions(); }
public void ItShouldReturnTrueIfTheStateContainsTheTransition(Event trigger, IState targetState, State sut) { // Arrange sut.AddTransition(trigger, targetState); // Act var result = sut.HasTransition(trigger.Code); // Assert result.Should().BeTrue(); }
public void ItShouldCallTheCommandChannelsSendMethodWithTheCorrectCommandCodes(List<Command> commands, [Frozen]ICommandChannel commandChannel, State sut) { // Arrange commands.ForEach(sut.AddAction); var expected = commands.Select(x => x.Code); var actual = new List<string>(); A.CallTo(() => commandChannel.Send(A<string>._)).Invokes(x => { var a = x.GetArgument<string>(0); actual.Add(a); }); // Act sut.ExecuteActions(commandChannel); // Assert actual.Should().Equal(expected); }
public void ItShouldAddThePassedInCommandAsAnAction(ICommandChannel commandChannel, Command command, State sut) { // Arrange // Act sut.AddAction(command); sut.ExecuteActions(commandChannel); // Assert A.CallTo(() => commandChannel.Send(command.Code)).MustHaveHappened(Repeated.Exactly.Once); }
public void ItShouldThrowAKeyNotFoundExceptionIfTheEventCodeIsNotUsed(string eventCode, State sut) { // Arrange // Act Action action = () => sut.FindTargetState(eventCode); // Assert action.ShouldThrow<KeyNotFoundException>(); }
public void ItShouldReturnTheExpectedTargetStateIfTheEventCodeIsUsed(Event trigger, IState targetState, State sut) { // Arrange sut.AddTransition(trigger, targetState); // Act var result = sut.FindTargetState(trigger.Code); // Assert result.Should().BeSameAs(targetState); }
public void ItShouldReturnFalseIfTheStateDoesNotContainTheTransition(string eventCode, State sut) { // Arrange // Act var result = sut.HasTransition(eventCode); // Assert result.Should().BeFalse(); }