public void CreateWithStringRequestConstrainedbyMinLengthReturnsCorrectResult(int min)
        {
            // Arrange
            var minLengthAttribute = new MinLengthAttribute(min);

            var request = new FakeMemberInfo(
                new ProvidedAttribute(minLengthAttribute, true));

            var expectedRequest = new ConstrainedStringRequest(min, int.MaxValue);
            var expectedResult  = new object();
            var context         = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen()
            };

            var sut = new MinAndMaxLengthAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = r => typeof(string)
                }
            };

            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void CreateWithNullContextThrows()
        {
            // Arrange
            var sut          = new MinAndMaxLengthAttributeRelay();
            var dummyRequest = new object();

            // Act & assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Create(dummyRequest, null));
        }
        public void CreateWithNullRequestReturnsCorrectResult()
        {
            // Arrange
            var sut = new MinAndMaxLengthAttributeRelay();

            // Act
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(null, dummyContext);

            // Assert
            Assert.Equal(new NoSpecimen(), result);
        }
        public void CreateWithNonConstrainedStringRequestReturnsCorrectResult(object request)
        {
            // Arrange
            var sut = new MinAndMaxLengthAttributeRelay();

            // Act
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(request, dummyContext);

            // Assert
            var expectedResult = new NoSpecimen();

            Assert.Equal(expectedResult, result);
        }
        public void CreateWithFiniteSequenceRequestConstrainedbyMinAndMaxLengthReturnsCorrectResult(int min, int max)
        {
            // Arrange
            var memberType = typeof(string[]);
            var randomNumberWithinRange = (min + max) / 2;

            var minLengthAttribute = new MinLengthAttribute(min);
            var maxLengthAttribute = new MaxLengthAttribute(max);

            var request = new FakeMemberInfo(
                new ProvidedAttribute(minLengthAttribute, true),
                new ProvidedAttribute(maxLengthAttribute, true));

            var expectedRangedNumberRequest   = new RangedNumberRequest(typeof(int), min, max);
            var expectedFiniteSequenceRequest = new FiniteSequenceRequest(
                memberType.GetElementType(),
                randomNumberWithinRange);

            var expectedResult = new List <string>();

            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    if (r.Equals(expectedRangedNumberRequest))
                    {
                        return(randomNumberWithinRange);
                    }
                    if (r.Equals(expectedFiniteSequenceRequest))
                    {
                        return(expectedResult);
                    }
                    return(new NoSpecimen());
                }
            };

            var sut = new MinAndMaxLengthAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = r => memberType
                }
            };

            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void CreateWithAnonymousRequestReturnsCorrectResult()
        {
            // Arrange
            var sut          = new MinAndMaxLengthAttributeRelay();
            var dummyRequest = new object();

            // Act
            var dummyContainer = new DelegatingSpecimenContext();
            var result         = sut.Create(dummyRequest, dummyContainer);

            // Assert
            var expectedResult = new NoSpecimen();

            Assert.Equal(expectedResult, result);
        }
        public void CreateWithRangedSequenceRequestConstrainedByMaxLengthReturnsCorrectResult(int max)
        {
            // Arrange
            var memberType = typeof(string[]);

            var maxLengthAttribute = new MaxLengthAttribute(max);
            var request            = new FakeMemberInfo(
                new ProvidedAttribute(maxLengthAttribute, true));

            var expectedRangedSequenceRequest = new RangedSequenceRequest(typeof(string), 1, max);
            var expectedResult = new List <string>();

            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    if (expectedRangedSequenceRequest.Equals(r))
                    {
                        return(expectedResult);
                    }
                    return(new NoSpecimen());
                }
            };

            var sut = new MinAndMaxLengthAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = r => memberType
                }
            };

            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void WhenMaxValueIsGreaterThen0MinShouldBeEqualToAtLeast1(int min, int max, int expectedMin)
        {
            // Arrange
            var minLengthAttribute = new MinLengthAttribute(min);
            var maxLengthAttribute = new MaxLengthAttribute(max);

            var request = new FakeMemberInfo(
                new ProvidedAttribute(minLengthAttribute, true),
                new ProvidedAttribute(maxLengthAttribute, true));

            ConstrainedStringRequest actualRequest = null;

            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    actualRequest = (ConstrainedStringRequest)r;
                    return(new object());
                }
            };

            var sut = new MinAndMaxLengthAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = r => typeof(string)
                }
            };

            // Act
            sut.Create(request, context);

            // Assert
            var expectedRequest = new ConstrainedStringRequest(expectedMin, max);

            Assert.Equal(expectedRequest, actualRequest);
        }