示例#1
0
        public void NullCasts()
        {
            ServiceResult <ArgumentException> result = ServiceResult.Success <ArgumentException>(null);

            result.Cast <InvalidOperationException>().Value.Should().BeNull();
            result.Cast <long?>().Value.Should().BeNull();
        }
示例#2
0
        public void ValueCasts()
        {
            ServiceResult <long> result = ServiceResult.Success(1L);

            result.Value.GetType().Should().Be(typeof(long));
            result.Cast <long>().Value.GetType().Should().Be(typeof(long));
            Assert.Throws <InvalidCastException>(() => result.Cast <int>().Value.Should().Be(1));
        }
示例#3
0
        public void ReferenceCasts()
        {
            ServiceResult <ArgumentException> result = ServiceResult.Success <ArgumentException>(new ArgumentNullException());

            result.Value.GetType().Should().Be(typeof(ArgumentNullException));
            result.Cast <ArgumentNullException>().Value.GetType().Should().Be(typeof(ArgumentNullException));
            result.Cast <ArgumentException>().Value.GetType().Should().Be(typeof(ArgumentNullException));
            result.Cast <Exception>().Value.GetType().Should().Be(typeof(ArgumentNullException));
            result.Cast <object>().Value.GetType().Should().Be(typeof(ArgumentNullException));
            Assert.Throws <InvalidCastException>(() => result.Cast <InvalidOperationException>().Value.GetType().Should().Be(typeof(ArgumentNullException)));
        }
示例#4
0
        public void AlwaysCastFailure()
        {
            ServiceResultFailure failure = ServiceResult.Failure(new ServiceErrorDto("Failure"));

            failure.Cast <int>().Error.Should().BeDto(new ServiceErrorDto("Failure"));
            ServiceResult noValue = ServiceResult.Failure(new ServiceErrorDto("NoValue"));

            noValue.Cast <int>().Error.Should().BeDto(new ServiceErrorDto("NoValue"));
            ServiceResult <string> stringValue = ServiceResult.Failure(new ServiceErrorDto("StringValue"));

            stringValue.Cast <int>().Error.Should().BeDto(new ServiceErrorDto("StringValue"));
        }
示例#5
0
        public void NoValueCasts()
        {
            ServiceResult result = ServiceResult.Success();

            Assert.Throws <InvalidCastException>(() => result.Cast <object>());
        }