Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void ShouldFailForNullContext()
        {
            // Arrange
            var sut     = new EnumRangedRequestRelay();
            var request = new object();

            // Act & Assert
            Assert.ThrowsAny <ArgumentNullException>(() =>
                                                     sut.Create(request, null));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }