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 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 CreateWithNullContainerWillThrow()
 {
     // Fixture setup
     var sut = new ModestConstructorInvoker();
     // Exercise system
     var dummyRequest = new object();
     sut.Create(dummyRequest, null);
     // Verify outcome (expected exception)
     // Teardown
 }
 public void CreateWithNullRequestWillReturnNull()
 {
     // Fixture setup
     var sut = new ModestConstructorInvoker();
     // Exercise system
     var dummyContainer = new DelegatingSpecimenContainer();
     var result = sut.Create(null, dummyContainer);
     // Verify outcome
     Assert.IsNull(result, "Create");
     // Teardown
 }
        public void CreateWithNullContainerWillThrow()
        {
            // Fixture setup
            var sut = new ModestConstructorInvoker();
            // Exercise system
            var dummyRequest = new object();

            sut.Create(dummyRequest, null);
            // Verify outcome (expected exception)
            // 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 CreateWithNullRequestWillReturnNull()
        {
            // Fixture setup
            var sut = new ModestConstructorInvoker();
            // 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 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 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 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 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 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
        }