public void CreateFromTypeWhenParentCanGenerateBothParametersWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedParameterValues = new object[] { 1, 2m };
            var parameterQueue          = new Queue <object>(expectedParameterValues);

            var requestedType = typeof(DoubleParameterType <int, decimal>);
            var parameters    = requestedType.GetConstructors().Single().GetParameters();

            var container = new DelegatingSpecimenContainer();

            container.OnCreate = r =>
            {
                if (parameters.Any(r.Equals))
                {
                    return(parameterQueue.Dequeue());
                }
                return(null);
            };

            var sut = new ModestConstructorInvoker();
            // Exercise system
            var result = sut.Create(requestedType, container);
            // Verify outcome
            var actual = (DoubleParameterType <int, decimal>)result;

            Assert.AreEqual(expectedParameterValues[0], actual.Parameter1, "Create");
            Assert.AreEqual(expectedParameterValues[1], actual.Parameter2, "Create");
            // Teardown
        }
        public void CreateWillReturnFirstNonNullResultFromBuilders()
        {
            // Fixture setup
            var expectedResult = new object();
            var builders       = new ISpecimenBuilder[]
            {
                new DelegatingSpecimenBuilder {
                    OnCreate = (r, c) => null
                },
                new DelegatingSpecimenBuilder {
                    OnCreate = (r, c) => expectedResult
                },
                new DelegatingSpecimenBuilder {
                    OnCreate = (r, c) => new object()
                }
            };
            var sut = new CompositeSpecimenBuilder(builders);
            // Exercise system
            var anonymousRequest = new object();
            var dummyContainer   = new DelegatingSpecimenContainer();
            var result           = sut.Create(anonymousRequest, dummyContainer);

            // Verify outcome
            Assert.AreEqual(expectedResult, result, "Create");
            // Teardown
        }
        public void CreateWillReturnNullIfAllBuildersReturnNull()
        {
            // Fixture setup
            var builders = new ISpecimenBuilder[]
            {
                new DelegatingSpecimenBuilder {
                    OnCreate = (r, c) => null
                },
                new DelegatingSpecimenBuilder {
                    OnCreate = (r, c) => null
                },
                new DelegatingSpecimenBuilder {
                    OnCreate = (r, c) => null
                }
            };
            var sut = new CompositeSpecimenBuilder(builders);
            // Exercise system
            var anonymousRequest = new object();
            var dummyContainer   = new DelegatingSpecimenContainer();
            var result           = sut.Create(anonymousRequest, dummyContainer);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromTypeWillInvokeContainerCorrectly()
        {
            // Fixture setup
            var requestedType = typeof(DoubleParameterType <long, short>);
            var parameters    = requestedType.GetConstructors().Single().GetParameters();

            var mockVerified  = false;
            var containerMock = new DelegatingSpecimenContainer();

            containerMock.OnCreate = r =>
            {
                if (parameters.Any(r.Equals))
                {
                    mockVerified = true;
                    var pType = ((ParameterInfo)r).ParameterType;
                    if (typeof(long) == pType)
                    {
                        return(new long());
                    }
                    if (typeof(short) == pType)
                    {
                        return(new short());
                    }
                }
                throw new AssertFailedException("Unexpected container request.");
            };

            var sut = new ModestConstructorInvoker();

            // Exercise system
            sut.Create(requestedType, containerMock);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
 public void CreateWithNullRequestWillReturnNull()
 {
     // Fixture setup
     var sut = new ParameterRequestTranslator();
     // Exercise system
     var dummyContainer = new DelegatingSpecimenContainer();
     var result = sut.Create(null, dummyContainer);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
 public void CreateFromTypeWithNoPublicConstructorWhenContainerCanSatisfyRequestWillReturnNull()
 {
     // Fixture setup
     var container = new DelegatingSpecimenContainer { OnCreate = r => new object() };
     var sut = new ModestConstructorInvoker();
     // Exercise system
     var result = sut.Create(typeof(AbstractType), container);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
 public void CreateFromNonTypeRequestWillReturnNull()
 {
     // Fixture setup
     var nonTypeRequest = new object();
     var dummyContainer = new DelegatingSpecimenContainer();
     var sut = new ModestConstructorInvoker();
     // Exercise system
     var result = sut.Create(nonTypeRequest, dummyContainer);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
 public void CreateFromSeedWhenContainerCannotSatisfyWrappedRequestWillReturnNull()
 {
     // Fixture setup
     var anonymousSeed = new SeededRequest(typeof(object), new object());
     var unableContainer = new DelegatingSpecimenContainer { OnCreate = r => null };
     var sut = new ValueIgnoringSeedUnwrapper();
     // Exercise system
     var result = sut.Create(anonymousSeed, unableContainer);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
 public void CreateFromParameterRequestWillReturnNullWhenContainerCannotSatisfyRequest()
 {
     // Fixture setup
     var parameterInfo = typeof(SingleParameterType<string>).GetConstructors().First().GetParameters().First();
     var container = new DelegatingSpecimenContainer { OnCreate = r => null };
     var sut = new ParameterRequestTranslator();
     // Exercise system
     var result = sut.Create(parameterInfo, container);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
        public void CreateWithNullRequestWillReturnNull()
        {
            // Fixture setup
            var sut = new ParameterRequestTranslator();
            // Exercise system
            var dummyContainer = new DelegatingSpecimenContainer();
            var result         = sut.Create(null, dummyContainer);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
 public void CreateFromTypeRequestWhenContainerCannotSatisfyParameterRequestWillReturnNull()
 {
     // Fixture setup
     var type = typeof(string);
     var container = new DelegatingSpecimenContainer { OnCreate = r => null };
     var sut = new ModestConstructorInvoker();
     // Exercise system
     var result = sut.Create(type, container);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
 public void CreateFromParameterRequestWillReturnCorrectResultWhenContainerCanSatisfyRequest()
 {
     // Fixture setup
     var expectedSpecimen = new object();
     var parameterInfo = typeof(SingleParameterType<string>).GetConstructors().First().GetParameters().First();
     var container = new DelegatingSpecimenContainer { OnCreate = r => expectedSpecimen };
     var sut = new ParameterRequestTranslator();
     // Exercise system
     var result = sut.Create(parameterInfo, container);
     // Verify outcome
     Assert.AreEqual(expectedSpecimen, result, "Create");
     // Teardown
 }
        public void CreateFromNonTypeRequestWillReturnNull()
        {
            // Fixture setup
            var nonTypeRequest = new object();
            var dummyContainer = new DelegatingSpecimenContainer();
            var sut            = new ModestConstructorInvoker();
            // Exercise system
            var result = sut.Create(nonTypeRequest, dummyContainer);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromTypeWithNoPublicConstructorWhenContainerCanSatisfyRequestWillReturnNull()
        {
            // Fixture setup
            var container = new DelegatingSpecimenContainer {
                OnCreate = r => new object()
            };
            var sut = new ModestConstructorInvoker();
            // Exercise system
            var result = sut.Create(typeof(AbstractType), container);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromTypeRequestWhenContainerCannotSatisfyParameterRequestWillReturnNull()
        {
            // Fixture setup
            var type      = typeof(string);
            var container = new DelegatingSpecimenContainer {
                OnCreate = r => null
            };
            var sut = new ModestConstructorInvoker();
            // Exercise system
            var result = sut.Create(type, container);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromTypeWhenParentCanGenerateOneParameterButNotTheOtherWillReturnCorrectNull()
        {
            // Fixture setup
            var requestedType = typeof(DoubleParameterType <string, int>);
            var container     = new DelegatingSpecimenContainer {
                OnCreate = r => typeof(string) == r ? new object() : null
            };
            var sut = new ModestConstructorInvoker();
            // Exercise system
            var result = sut.Create(requestedType, container);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromSeedWhenContainerCannotSatisfyWrappedRequestWillReturnNull()
        {
            // Fixture setup
            var anonymousSeed   = new SeededRequest(typeof(object), new object());
            var unableContainer = new DelegatingSpecimenContainer {
                OnCreate = r => null
            };
            var sut = new ValueIgnoringSeedUnwrapper();
            // Exercise system
            var result = sut.Create(anonymousSeed, unableContainer);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromParameterRequestWillReturnNullWhenContainerCannotSatisfyRequest()
        {
            // Fixture setup
            var parameterInfo = typeof(SingleParameterType <string>).GetConstructors().First().GetParameters().First();
            var container     = new DelegatingSpecimenContainer {
                OnCreate = r => null
            };
            var sut = new ParameterRequestTranslator();
            // Exercise system
            var result = sut.Create(parameterInfo, container);

            // Verify outcome
            Assert.IsNull(result, "Create");
            // Teardown
        }
        public void CreateFromSeedWhenContainerCanSatisfyWrappedRequestWillReturnCorrectResult()
        {
            // Fixture setup
            var anonymousSeed = new SeededRequest(typeof(object), new object());

            var expectedResult = new object();
            var container = new DelegatingSpecimenContainer { OnCreate = r => expectedResult };

            var sut = new ValueIgnoringSeedUnwrapper();
            // Exercise system
            var result = sut.Create(anonymousSeed, container);
            // Verify outcome
            Assert.AreEqual(expectedResult, result, "Create");
            // Teardown
        }
        public void CreateFromParameterRequestWillReturnCorrectResultWhenContainerCanSatisfyRequest()
        {
            // Fixture setup
            var expectedSpecimen = new object();
            var parameterInfo    = typeof(SingleParameterType <string>).GetConstructors().First().GetParameters().First();
            var container        = new DelegatingSpecimenContainer {
                OnCreate = r => expectedSpecimen
            };
            var sut = new ParameterRequestTranslator();
            // Exercise system
            var result = sut.Create(parameterInfo, container);

            // Verify outcome
            Assert.AreEqual(expectedSpecimen, result, "Create");
            // Teardown
        }
        public void CreateFromSeedWhenContainerCanSatisfyWrappedRequestWillReturnCorrectResult()
        {
            // Fixture setup
            var anonymousSeed = new SeededRequest(typeof(object), new object());

            var expectedResult = new object();
            var container      = new DelegatingSpecimenContainer {
                OnCreate = r => expectedResult
            };

            var sut = new ValueIgnoringSeedUnwrapper();
            // Exercise system
            var result = sut.Create(anonymousSeed, container);

            // Verify outcome
            Assert.AreEqual(expectedResult, result, "Create");
            // Teardown
        }
        public void CreateFromSeedWillCorrectlyInvokeContainer()
        {
            // Fixture setup
            var sut           = new ValueIgnoringSeedUnwrapper();
            var seededRequest = new SeededRequest(typeof(int), 1);

            var mockVerified  = false;
            var containerMock = new DelegatingSpecimenContainer();

            containerMock.OnCreate = r =>
            {
                Assert.AreEqual(typeof(int), r, "Create");
                mockVerified = true;
                return(null);
            };
            // Exercise system
            sut.Create(seededRequest, containerMock);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
        public void CreateFromParameterRequestWillCorrectlyInvokeContainer()
        {
            // Fixture setup
            var sut             = new ParameterRequestTranslator();
            var parameterInfo   = typeof(SingleParameterType <string>).GetConstructors().First().GetParameters().First();
            var expectedRequest = new SeededRequest(parameterInfo.ParameterType, parameterInfo.Name);

            var mockVerified  = false;
            var containerMock = new DelegatingSpecimenContainer();

            containerMock.OnCreate = r =>
            {
                Assert.AreEqual(expectedRequest, r, "Create");
                mockVerified = true;
                return(null);
            };
            // Exercise system
            sut.Create(parameterInfo, containerMock);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
        public void CreateWillInvokeBuilderWithCorrectContainer()
        {
            // Fixture setup
            var expectedContainer = new DelegatingSpecimenContainer();

            var mockVerified = false;
            var builderMock  = new DelegatingSpecimenBuilder();

            builderMock.OnCreate = (r, c) =>
            {
                Assert.AreEqual(expectedContainer, c, "Create");
                mockVerified = true;
                return(new object());
            };

            var sut = new CompositeSpecimenBuilder(builderMock);
            // Exercise system
            var dummyRequest = new object();

            sut.Create(dummyRequest, expectedContainer);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
 public void CreateWillReturnNullIfAllBuildersReturnNull()
 {
     // Fixture setup
     var builders = new ISpecimenBuilder[]
     {
         new DelegatingSpecimenBuilder { OnCreate = (r, c) => null },
         new DelegatingSpecimenBuilder { OnCreate = (r, c) => null },
         new DelegatingSpecimenBuilder { OnCreate = (r, c) => null }
     };
     var sut = new CompositeSpecimenBuilder(builders);
     // Exercise system
     var anonymousRequest = new object();
     var dummyContainer = new DelegatingSpecimenContainer();
     var result = sut.Create(anonymousRequest, dummyContainer);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
        public void CreateFromParameterRequestWillCorrectlyInvokeContainer()
        {
            // Fixture setup
            var sut = new ParameterRequestTranslator();
            var parameterInfo = typeof(SingleParameterType<string>).GetConstructors().First().GetParameters().First();
            var expectedRequest = new SeededRequest(parameterInfo.ParameterType, parameterInfo.Name);

            var mockVerified = false;
            var containerMock = new DelegatingSpecimenContainer();
            containerMock.OnCreate = r =>
            {
                Assert.AreEqual(expectedRequest, r, "Create");
                mockVerified = true;
                return null;
            };
            // Exercise system
            sut.Create(parameterInfo, containerMock);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
        public void CreateWillInvokeBuilderWithCorrectContainer()
        {
            // Fixture setup
            var expectedContainer = new DelegatingSpecimenContainer();

            var mockVerified = false;
            var builderMock = new DelegatingSpecimenBuilder();
            builderMock.OnCreate = (r, c) =>
                {
                    Assert.AreEqual(expectedContainer, c, "Create");
                    mockVerified = true;
                    return new object();
                };

            var sut = new CompositeSpecimenBuilder(builderMock);
            // Exercise system
            var dummyRequest = new object();
            sut.Create(dummyRequest, expectedContainer);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
 public void CreateWillReturnFirstNonNullResultFromBuilders()
 {
     // Fixture setup
     var expectedResult = new object();
     var builders = new ISpecimenBuilder[]
     {
         new DelegatingSpecimenBuilder { OnCreate = (r, c) => null },
         new DelegatingSpecimenBuilder { OnCreate = (r, c) => expectedResult },
         new DelegatingSpecimenBuilder { OnCreate = (r, c) => new object() }
     };
     var sut = new CompositeSpecimenBuilder(builders);
     // Exercise system
     var anonymousRequest = new object();
     var dummyContainer = new DelegatingSpecimenContainer();
     var result = sut.Create(anonymousRequest, dummyContainer);
     // Verify outcome
     Assert.AreEqual(expectedResult, result, "Create");
     // Teardown
 }
        public void CreateFromSeedWillCorrectlyInvokeContainer()
        {
            // Fixture setup
            var sut = new ValueIgnoringSeedUnwrapper();
            var seededRequest = new SeededRequest(typeof(int), 1);

            var mockVerified = false;
            var containerMock = new DelegatingSpecimenContainer();
            containerMock.OnCreate = r =>
            {
                Assert.AreEqual(typeof(int), r, "Create");
                mockVerified = true;
                return null;
            };
            // Exercise system
            sut.Create(seededRequest, containerMock);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }
        public void CreateFromTypeWhenParentCanGenerateBothParametersWillReturnCorrectResult()
        {
            // Fixture setup
            var expectedParameterValues = new object[] { 1, 2m };
            var parameterQueue = new Queue<object>(expectedParameterValues);

            var requestedType = typeof(DoubleParameterType<int, decimal>);
            var parameters = requestedType.GetConstructors().Single().GetParameters();

            var container = new DelegatingSpecimenContainer();
            container.OnCreate = r =>
            {
                if (parameters.Any(r.Equals))
                {
                    return parameterQueue.Dequeue();
                }
                return null;
            };

            var sut = new ModestConstructorInvoker();
            // Exercise system
            var result = sut.Create(requestedType, container);
            // Verify outcome
            var actual = (DoubleParameterType<int, decimal>)result;
            Assert.AreEqual(expectedParameterValues[0], actual.Parameter1, "Create");
            Assert.AreEqual(expectedParameterValues[1], actual.Parameter2, "Create");
            // Teardown
        }
 public void CreateFromTypeWhenParentCanGenerateOneParameterButNotTheOtherWillReturnCorrectNull()
 {
     // Fixture setup
     var requestedType = typeof(DoubleParameterType<string, int>);
     var container = new DelegatingSpecimenContainer { OnCreate = r => typeof(string) == r ? new object() : null };
     var sut = new ModestConstructorInvoker();
     // Exercise system
     var result = sut.Create(requestedType, container);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
        public void CreateFromTypeWillInvokeContainerCorrectly()
        {
            // Fixture setup
            var requestedType = typeof(DoubleParameterType<long, short>);
            var parameters = requestedType.GetConstructors().Single().GetParameters();

            var mockVerified = false;
            var containerMock = new DelegatingSpecimenContainer();
            containerMock.OnCreate = r =>
                {
                    if (parameters.Any(r.Equals))
                    {
                        mockVerified = true;
                        var pType = ((ParameterInfo)r).ParameterType;
                        if (typeof(long) == pType)
                        {
                            return new long();
                        }
                        if (typeof(short) == pType)
                        {
                            return new short();
                        }
                    }
                    throw new AssertFailedException("Unexpected container request.");
                };

            var sut = new ModestConstructorInvoker();
            // Exercise system
            sut.Create(requestedType, containerMock);
            // Verify outcome
            Assert.IsTrue(mockVerified, "Mock verification");
            // Teardown
        }