예제 #1
0
        public void CreateWithRangeAttributeRequestReturnsCorrectResult(Type type, object minimum, object maximum)
        {
            // Fixture setup
            var rangeAttribute               = new RangeAttribute(type, minimum.ToString(), maximum.ToString());
            var providedAttribute            = new ProvidedAttribute(rangeAttribute, true);
            ICustomAttributeProvider request = new FakeCustomAttributeProvider(providedAttribute);
            Type conversionType              = rangeAttribute.OperandType;
            var  expectedRequest             = new RangedNumberRequest(
                conversionType,
                Convert.ChangeType(rangeAttribute.Minimum, conversionType, CultureInfo.CurrentCulture),
                Convert.ChangeType(rangeAttribute.Maximum, conversionType, CultureInfo.CurrentCulture)
                );
            var expectedResult = new object();
            var context        = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen(r)
            };
            var sut = new RangeAttributeRelay();
            // Exercise system
            var result = sut.Create(request, context);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
예제 #2
0
        public void CreateWithFieldDecoratedWithRangeAttributeReturnsCorrectResult(
            Type attributeType,
            object attributeMinimum,
            object attributeMaximum)
        {
            // Fixture setup
            var  request = typeof(RangeValidatedType).GetField("Field");
            Type target  = request.FieldType;

            var expectedRequest = new RangedNumberRequest(
                target,
                Convert.ChangeType(RangeValidatedType.Minimum, target, CultureInfo.CurrentCulture),
                Convert.ChangeType(RangeValidatedType.Maximum, target, CultureInfo.CurrentCulture)
                );

            var expectedResult = new object();
            var context        = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen(r)
            };
            var sut = new RangeAttributeRelay();
            // Exercise system
            var result = sut.Create(request, context);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
예제 #3
0
        public void CreateWithPropertyDecoratedWithRangeAttributeReturnsCorrectResult(
            string name,
            object attributeMinimum,
            object attributeMaximum)
        {
            // Fixture setup
            var  request = typeof(RangeValidatedType).GetProperty(name);
            Type target  = Nullable.GetUnderlyingType(request.PropertyType)
                           ?? request.PropertyType;

            var expectedRequest = new RangedNumberRequest(
                target,
                Convert.ChangeType(RangeValidatedType.Minimum, target, CultureInfo.CurrentCulture),
                Convert.ChangeType(RangeValidatedType.Maximum, target, CultureInfo.CurrentCulture)
                );

            var expectedResult = new object();
            var context        = new DelegatingSpecimenContext
            {
#pragma warning disable 618
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen(r)
#pragma warning restore 618
            };
            var sut = new RangeAttributeRelay();
            // Exercise system
            var result = sut.Create(request, context);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
예제 #4
0
        public void CreateWithNullContextThrows()
        {
            // Arrange
            var sut          = new RangeAttributeRelay();
            var dummyRequest = new object();

            // Act & assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Create(dummyRequest, null));
        }
예제 #5
0
        public void CreateWithNullContextThrows()
        {
            // Fixture setup
            var sut          = new RangeAttributeRelay();
            var dummyRequest = new object();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Create(dummyRequest, null));
            // Teardown
        }
예제 #6
0
        public void CreateWithNullRequestReturnsCorrectResult()
        {
            // Arrange
            var sut = new RangeAttributeRelay();
            // Act
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(null, dummyContext);

            // Assert
            Assert.Equal(new NoSpecimen(), result);
        }
예제 #7
0
        public void CreateWithNullRequestReturnsCorrectResult()
        {
            // Fixture setup
            var sut = new RangeAttributeRelay();
            // Exercise system
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(null, dummyContext);

            // Verify outcome
            Assert.Equal(new NoSpecimen(), result);
            // Teardown
        }
예제 #8
0
        public void CreateWithNonRangeAttributeRequestReturnsCorrectResult(object request)
        {
            // Arrange
            var sut = new RangeAttributeRelay();
            // Act
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(request, dummyContext);
            // Assert
            var expectedResult = new NoSpecimen();

            Assert.Equal(expectedResult, result);
        }
예제 #9
0
        public void CreateWithNonRangeAttributeRequestReturnsCorrectResult(object request)
        {
            // Fixture setup
            var sut = new RangeAttributeRelay();
            // Exercise system
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(request, dummyContext);
            // Verify outcome
            var expectedResult = new NoSpecimen(request);

            Assert.Equal(expectedResult, result);
            // Teardown
        }
예제 #10
0
        public void CreateWithAnonymousRequestReturnsCorrectResult()
        {
            // Arrange
            var sut          = new RangeAttributeRelay();
            var dummyRequest = new object();
            // Act
            var dummyContainer = new DelegatingSpecimenContext();
            var result         = sut.Create(dummyRequest, dummyContainer);
            // Assert
            var expectedResult = new NoSpecimen();

            Assert.Equal(expectedResult, result);
        }
예제 #11
0
        public void CreateWithAnonymousRequestReturnsCorrectResult()
        {
            // Fixture setup
            var sut          = new RangeAttributeRelay();
            var dummyRequest = new object();
            // Exercise system
            var dummyContainer = new DelegatingSpecimenContext();
            var result         = sut.Create(dummyRequest, dummyContainer);

            // Verify outcome
#pragma warning disable 618
            var expectedResult = new NoSpecimen(dummyRequest);
#pragma warning restore 618
            Assert.Equal(expectedResult, result);
            // Teardown
        }
예제 #12
0
        public void CreateWithPropertyDecoratedWithRangeAttributeReturnsCorrectResult(
            string name, Type expectedMemberType, Type expectedOperandType)
        {
            // Arrange
            var request = typeof(RangeValidatedType).GetProperty(name);

            var expectedRequest = new RangedRequest(
                expectedMemberType, expectedOperandType, RangeValidatedType.Minimum, RangeValidatedType.Maximum);
            var expectedResult = new object();
            var context        = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen()
            };
            var sut = new RangeAttributeRelay();
            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, result);
        }
예제 #13
0
        public void CreateWithRangeAttributeRequestReturnsCorrectResult(Type type, object minimum, object maximum)
        {
            // Arrange
            var  rangeAttribute    = new RangeAttribute(type, minimum.ToString(), maximum.ToString());
            var  providedAttribute = new ProvidedAttribute(rangeAttribute, true);
            var  request           = new FakeMemberInfo(providedAttribute);
            Type conversionType    = rangeAttribute.OperandType;
            var  expectedRequest   = new RangedRequest(conversionType, conversionType, rangeAttribute.Minimum,
                                                       rangeAttribute.Maximum);
            var expectedResult = new object();
            var context        = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen()
            };
            var sut = new RangeAttributeRelay();
            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, result);
        }
예제 #14
0
        public void CreateWithParameterDecoratedWithRangeAttributeReturnsCorrectResult(
            string methodName, Type expectedMemberType, Type expectedOperandType)
        {
            // Fixture setup
            var request = typeof(RangeValidatedType).GetMethod(methodName).GetParameters().Single();

            var expectedRequest = new RangedRequest(
                expectedMemberType, expectedOperandType, RangeValidatedType.Minimum, RangeValidatedType.Maximum);

            var expectedResult = new object();
            var context        = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen()
            };
            var sut = new RangeAttributeRelay();
            // Exercise system
            var result = sut.Create(request, context);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }