public void NullCasts() { ServiceResult <ArgumentException> result = ServiceResult.Success <ArgumentException>(null); result.Cast <InvalidOperationException>().Value.Should().BeNull(); result.Cast <long?>().Value.Should().BeNull(); }
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)); }
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))); }
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")); }
public void NoValueCasts() { ServiceResult result = ServiceResult.Success(); Assert.Throws <InvalidCastException>(() => result.Cast <object>()); }