Exemplo n.º 1
0
        public void ShouldNotInvokeInnerBuilderIfUnableToResolveMemberType()
        {
            // Arrange
            var nonMemberRequest   = new object();
            var memberTypeResolver = new DelegatingRequestMemberTypeResolver
            {
                OnTryGetMemberType = _ => null
            };

            var innerBuilder = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) => throw new InvalidOperationException("Should not be invoked")
            };

            var sut = new UnwrapMemberRequest(innerBuilder)
            {
                MemberTypeResolver = memberTypeResolver
            };

            var ctx = new DelegatingSpecimenContext();

            // Act
            var result = sut.Create(nonMemberRequest, ctx);

            // Assert
            Assert.Equal(new NoSpecimen(), result);
        }
    }
Exemplo n.º 2
0
        public void ShouldPassUnwrappedTypeToInnerBuilder()
        {
            // Arrange
            var memberRequest = new object();
            var memberType    = typeof(List <int>);

            var memberTypeResolver = new DelegatingRequestMemberTypeResolver
            {
                OnTryGetMemberType = r => r == memberRequest ? memberType : null
            };

            var expectedResult = new object();
            var innerBuilder   = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) => memberType.Equals(r) ? expectedResult : new NoSpecimen()
            };

            var sut = new UnwrapMemberRequest(innerBuilder)
            {
                MemberTypeResolver = memberTypeResolver
            };

            var ctx = new DelegatingSpecimenContext();

            // Act
            var result = sut.Create(memberRequest, ctx);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 3
0
        public void DefaultResolverShouldHaveCorrectType()
        {
            // Act
            var sut = new UnwrapMemberRequest(new DelegatingSpecimenBuilder());

            // Assert
            Assert.IsType <RequestMemberTypeResolver>(sut.MemberTypeResolver);
        }
Exemplo n.º 4
0
        public void ShouldThrowIfNullMemberTypeResolverIsAssigned()
        {
            // Arrange
            var sut = new UnwrapMemberRequest(new DelegatingSpecimenBuilder());

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.MemberTypeResolver = null);
        }
Exemplo n.º 5
0
        public void ShouldSaveThePassedBuilderToProperty()
        {
            // Arrange
            var builder = new DelegatingSpecimenBuilder();

            // Act
            var sut = new UnwrapMemberRequest(builder);

            // Assert
            Assert.Same(builder, sut.Builder);
        }