public void ShouldCorrectPassMinimumAndMaximum() { // Arrange var sut = new EnumRangedRequestRelay(); int minimum = 5; int maximum = 10; var request = new RangedRequest(typeof(EnumType), typeof(int), minimum, maximum); RangedNumberRequest capturedNumericRequest = null; var context = new DelegatingSpecimenContext { OnResolve = r => { capturedNumericRequest = (RangedNumberRequest)r; return(new NoSpecimen()); } }; // Act sut.Create(request, context); // Assert Assert.NotNull(capturedNumericRequest); Assert.Equal(minimum, capturedNumericRequest.Minimum); Assert.Equal(maximum, capturedNumericRequest.Maximum); }
public void ShouldRespectUnderlyingEnumType(Type enumType, Type underlyingType) { // Arrange var sut = new EnumRangedRequestRelay(); var request = new RangedRequest(memberType: enumType, operandType: typeof(int), minimum: 1, maximum: 2); RangedNumberRequest capturedNumericRequest = null; var context = new DelegatingSpecimenContext { OnResolve = r => { capturedNumericRequest = (RangedNumberRequest)r; return(new NoSpecimen()); } }; // Act sut.Create(request, context); // Assert Assert.NotNull(capturedNumericRequest); Assert.Equal(underlyingType, capturedNumericRequest.OperandType); Assert.IsType(underlyingType, capturedNumericRequest.Minimum); Assert.IsType(underlyingType, capturedNumericRequest.Maximum); }
public void ShouldFailForNullContext() { // Arrange var sut = new EnumRangedRequestRelay(); var request = new object(); // Act & Assert Assert.ThrowsAny <ArgumentNullException>(() => sut.Create(request, null)); }
public void ShouldNotHandleRequestIfMemberTypeIsNotEnum() { // Arrange var sut = new EnumRangedRequestRelay(); var request = new RangedRequest(memberType: typeof(object), operandType: typeof(EnumType), minimum: 0, maximum: 1); var context = new DelegatingSpecimenContext(); // Act var result = sut.Create(request, context); // Assert Assert.Equal(new NoSpecimen(), result); }
public void ShouldReturnNoSpecimenIfUnableToSatisfyRangedRequest() { // Arrange var sut = new EnumRangedRequestRelay(); var request = new RangedRequest(memberType: typeof(EnumType), operandType: typeof(int), minimum: 1, maximum: 2); var context = new DelegatingSpecimenContext { OnResolve = _ => new NoSpecimen() }; // Act var result = sut.Create(request, context); // Assert Assert.Equal(new NoSpecimen(), result); }
public void ShouldCorrectlyConvertNumericValue(EnumType expectedResult, int numericValue) { // Arrange var sut = new EnumRangedRequestRelay(); var request = new RangedRequest(memberType: typeof(EnumType), operandType: typeof(int), minimum: 1, maximum: 3); var context = new DelegatingSpecimenContext { OnResolve = _ => numericValue }; // Act var result = sut.Create(request, context); // Assert Assert.Equal(expectedResult, result); }
public void ShouldHandleRequestOfEnumType() { // Arrange var sut = new EnumRangedRequestRelay(); var request = new RangedRequest(memberType: typeof(EnumType), operandType: typeof(int), minimum: 1, maximum: 2); var result = (int)EnumType.Second; var context = new DelegatingSpecimenContext { OnResolve = _ => result }; // Act var actualResult = sut.Create(request, context); // Assert Assert.Equal(EnumType.Second, actualResult); }
public void ShouldSupportRangeForLiteralBoundaries() { // Arrange var sut = new EnumRangedRequestRelay(); var request = new RangedRequest(typeof(EnumType), typeof(EnumType), nameof(EnumType.First), nameof(EnumType.Third)); var result = (int)EnumType.Second; var context = new DelegatingSpecimenContext { OnResolve = r => r is RangedNumberRequest ? (object)result : new NoSpecimen() }; // Act var actualResult = sut.Create(request, context); // Assert Assert.Equal(EnumType.Second, actualResult); }