Example #1
0
        public Transition(IState source, Event trigger, IState target)
        {
            if (source == null) throw new ArgumentNullException("source");
            if (trigger == null) throw new ArgumentNullException("trigger");
            if (target == null) throw new ArgumentNullException("target");

            _source = source;
            _trigger = trigger;
            _target = target;
        }
Example #2
0
		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();
		}
Example #3
0
		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();
        }
Example #5
0
        public void AddResetEvent(Event resetEvent)
        {
            if (resetEvent == null) throw new ArgumentNullException("resetEvent");

            _resetEvents.Add(resetEvent);
        }
Example #6
0
		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();
		}
Example #7
0
		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);
		}