Beispiel #1
0
        public void ShouldThrowWhenNullStateFromConfigProvider()
        {
            MockConfigProvider cp = new MockConfigProvider {
                CurrentState = null
            };
            StateCompare sc = new StateCompare(cp);

            StateCompareException ex = Assert.Throws <StateCompareException>(() =>
            {
                sc.ComputeActionsFromState(new NodeState());
            });

            Assert.Equal("Received state from configuration provider is null. Can't compare", ex.Message);
        }
        public void StateCompareExceptionShouldThrowCorrectly()
        {
            StateCompareException ex = new StateCompareException("Test message");
            Action exThrow           = () => throw ex;

            exThrow.Should().Throw <StateCompareException>()
            .WithMessage("Test Message");

            // should serialize
            MemoryStream    mem = new MemoryStream();
            BinaryFormatter b   = new BinaryFormatter();

            Action serialize = () => b.Serialize(mem, ex);

            serialize.Should().NotThrow();

            // deserialize
            mem.Seek(0, SeekOrigin.Begin);
            StateCompareException deserializedEx = null;
            Action deserialize = () => deserializedEx = (StateCompareException)b.Deserialize(mem);

            deserialize.Should().NotThrow();
            deserializedEx.Message.Should().Be(ex.Message);
        }