Ejemplo n.º 1
0
        public void CtorNoReflection_CorrectNumberOfStatesButDuplicates_Throws()
        {
            // Arrange
            var log        = new StateMachineDiagnosticsLog <TwoStatesID>();
            var stubStates = new StubStateWithDiagnostics <TwoStatesID>[]
            {
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.One, log),
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.One, log),
            };

            // Both "DuplicateStates" and "NotEnoughStates" would be valid errors
            var notEnoughMessage =
                "StateMachine trying to initialize with an invalid set of states. Not enough states passed in. Missing states: Two";

            var duplicatesMessage =
                "StateMachine trying to initialize with an invalid set of states. Duplicate states passed in. Duplicate states: One";

            // Act / Assert
            var exception = Assert.Throws <System.ArgumentException>(
                // ReSharper disable once ObjectCreationAsStatement
                // ReSharper disable once CoVariantArrayConversion
                () => new StateMachine <TwoStatesID>(stubStates, TwoStatesID.One));

            Assert.That(exception.Message,
                        Is.EqualTo(notEnoughMessage).Or.EqualTo(duplicatesMessage));
        }
Ejemplo n.º 2
0
        public void CtorNoReflection_NotEnoughStates_Throws()
        {
            // Arrange
            var log        = new StateMachineDiagnosticsLog <TwoStatesID>();
            var stubStates = new StubStateWithDiagnostics <TwoStatesID>[]
            {
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.One, log)
            };

            var expectedMessage =
                "StateMachine trying to initialize with an invalid set of states. Not enough states passed in. Missing states: Two";

            // Act / Assert
            var exception = Assert.Throws <System.ArgumentException>(
                // ReSharper disable once ObjectCreationAsStatement
                // ReSharper disable once CoVariantArrayConversion
                () => new StateMachine <TwoStatesID>(stubStates, TwoStatesID.One));

            Assert.That(exception.Message, Is.EqualTo(expectedMessage));
        }
Ejemplo n.º 3
0
        public void ChangeState_CurrentState_DoesNothing()
        {
            // Arrange
            var log        = new StateMachineDiagnosticsLog <TwoStatesID>();
            var stubStates = new StubStateWithDiagnostics <TwoStatesID>[]
            {
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.One, log),
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.Two, log),
            };

            var stateMachine = new StateMachine <TwoStatesID>(stubStates, TwoStatesID.One);
            var expectedLog  = new StateMachineDiagnosticsLog <TwoStatesID>();

            expectedLog.AddEntry(StateMachineDiagnosticsLog <TwoStatesID> .LogEntry.Callback.Enter, TwoStatesID.One);

            // Act
            stateMachine.ChangeTo(TwoStatesID.One);

            // Assert
            Assert.That(log, Is.EqualTo(expectedLog));
        }
Ejemplo n.º 4
0
        public void CtorNoReflection_OneState_EnterOnlyInitialState()
        {
            // Arrange
            var log        = new StateMachineDiagnosticsLog <TwoStatesID>();
            var stubStates = new StubStateWithDiagnostics <TwoStatesID>[]
            {
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.One, log),
                new StubStateWithDiagnostics <TwoStatesID>(TwoStatesID.Two, log)
            };

            var expectedLog = new StateMachineDiagnosticsLog <TwoStatesID>();

            expectedLog.AddEntry(StateMachineDiagnosticsLog <TwoStatesID> .LogEntry.Callback.Enter, TwoStatesID.One);

            // Act
            // ReSharper disable once CoVariantArrayConversion
            // ReSharper disable once ObjectCreationAsStatement
            new StateMachine <TwoStatesID>(stubStates, TwoStatesID.One);

            // Assert
            Assert.That(log, Is.EqualTo(expectedLog));
        }