public void InitializeWithNullTypeThrows()
 {
     // Fixture setup
     var dummyQuery = new DelegatingMethodQuery();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         new ConstructorCustomization(null, dummyQuery));
     // Teardown
 }
 public void QueryIsCorrect()
 {
     // Fixture setup
     var expectedPicker = new DelegatingMethodQuery();
     var sut = new MethodInvoker(expectedPicker);
     // Exercise system
     IMethodQuery result = sut.Query;
     // Verify outcome
     Assert.Equal(expectedPicker, result);
     // Teardown
 }
 public void CustomizeNullFixtureThrows()
 {
     // Fixture setup
     var dummyType = typeof(object);
     var dummyQuery = new DelegatingMethodQuery();
     var sut = new ConstructorCustomization(dummyType, dummyQuery);
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.Customize(null));
     // Teardown
 }
 public void SutIsCustomization()
 {
     // Fixture setup
     var dummyType = typeof(object);
     var dummyQuery = new DelegatingMethodQuery();
     // Exercise system
     var sut = new ConstructorCustomization(dummyType, dummyQuery);
     // Verify outcome
     Assert.IsAssignableFrom<ICustomization>(sut);
     // Teardown
 }
Beispiel #5
0
        public void QueryIsCorrect()
        {
            // Fixture setup
            var expectedPicker = new DelegatingMethodQuery();
            var sut            = new MethodInvoker(expectedPicker);
            // Exercise system
            IMethodQuery result = sut.Query;

            // Verify outcome
            Assert.Equal(expectedPicker, result);
            // Teardown
        }
 public void QueryIsCorrect()
 {
     // Fixture setup
     var dummyType = typeof(object);
     var expectedQuery = new DelegatingMethodQuery();
     var sut = new ConstructorCustomization(dummyType, expectedQuery);
     // Exercise system
     IMethodQuery result = sut.Query;
     // Verify outcome
     Assert.Equal(expectedQuery, result);
     // Teardown
 }
 public void TargetTypeIsCorrect()
 {
     // Fixture setup
     var expectedType = typeof(string);
     var dummyQuery = new DelegatingMethodQuery();
     var sut = new ConstructorCustomization(expectedType, dummyQuery);
     // Exercise system
     Type result = sut.TargetType;
     // Verify outcome
     Assert.Equal(expectedType, result);
     // Teardown
 }
Beispiel #8
0
        public void CreateReturnsCorrectResultWhenQueryReturnsEmptyConstructors()
        {
            // Fixture setup
            var dummyRequest = typeof(object);
            var query        = new DelegatingMethodQuery {
                OnSelectMethods = t => Enumerable.Empty <IMethod>()
            };
            var sut = new MethodInvoker(query);
            // Exercise system
            var dummyContext = new DelegatingSpecimenContext();
            var result       = sut.Create(dummyRequest, dummyContext);
            // Verify outcome
            var expectedResult = new NoSpecimen(dummyRequest);

            Assert.Equal(expectedResult, result);
            // Teardown
        }
Beispiel #9
0
        public void CreateFromTypeWillUseFirstConstructorItCanSatisfy()
        {
            // Fixture setup
            var requestedType = typeof(MultiUnorderedConstructorType);
            var ctor1         = requestedType.GetConstructor(new[] { typeof(MultiUnorderedConstructorType.ParameterObject) });
            var ctor2         = requestedType.GetConstructor(new[] { typeof(string), typeof(int) });

            var picker = new DelegatingMethodQuery {
                OnSelectMethods = t => new IMethod[] { new ConstructorMethod(ctor1), new ConstructorMethod(ctor2) }
            };
            var sut = new MethodInvoker(picker);

            var ctor2Params    = ctor2.GetParameters();
            var expectedText   = "Anonymous text";
            var expectedNumber = 14;

            var context = new DelegatingSpecimenContext();

            context.OnResolve = r =>
            {
                if (ctor2Params.Any(r.Equals))
                {
                    var pType = ((ParameterInfo)r).ParameterType;
                    if (typeof(string) == pType)
                    {
                        return(expectedText);
                    }
                    if (typeof(int) == pType)
                    {
                        return(expectedNumber);
                    }
                }
#pragma warning disable 618
                return(new NoSpecimen(r));

#pragma warning restore 618
            };
            // Exercise system
            var result = sut.Create(requestedType, context);
            // Verify outcome
            var actual = Assert.IsAssignableFrom <MultiUnorderedConstructorType>(result);
            Assert.Equal(expectedText, actual.Text);
            Assert.Equal(expectedNumber, actual.Number);
            // Teardown
        }
 public void CreateReturnsCorrectResultWhenQueryReturnsEmptyConstructors()
 {
     // Fixture setup
     var dummyRequest = typeof(object);
     var query = new DelegatingMethodQuery { OnSelectMethods = t => Enumerable.Empty<IMethod>() };
     var sut = new MethodInvoker(query);
     // Exercise system
     var dummyContext = new DelegatingSpecimenContext();
     var result = sut.Create(dummyRequest, dummyContext);
     // Verify outcome
     #pragma warning disable 618
     var expectedResult = new NoSpecimen(dummyRequest);
     #pragma warning restore 618
     Assert.Equal(expectedResult, result);
     // Teardown
 }
        public void CreateFromTypeWillUseFirstConstructorItCanSatisfy()
        {
            // Fixture setup
            var requestedType = typeof(MultiUnorderedConstructorType);
            var ctor1 = requestedType.GetConstructor(new[] { typeof(MultiUnorderedConstructorType.ParameterObject) });
            var ctor2 = requestedType.GetConstructor(new[] { typeof(string), typeof(int) });

            var picker = new DelegatingMethodQuery { OnSelectMethods = t => new IMethod[] { new ConstructorMethod(ctor1), new ConstructorMethod(ctor2) } };
            var sut = new MethodInvoker(picker);

            var ctor2Params = ctor2.GetParameters();
            var expectedText = "Anonymous text";
            var expectedNumber = 14;

            var context = new DelegatingSpecimenContext();
            context.OnResolve = r =>
            {
                if (ctor2Params.Any(r.Equals))
                {
                    var pType = ((ParameterInfo)r).ParameterType;
                    if (typeof(string) == pType)
                    {
                        return expectedText;
                    }
                    if (typeof(int) == pType)
                    {
                        return expectedNumber;
                    }
                }
            #pragma warning disable 618
                return new NoSpecimen(r);
            #pragma warning restore 618
            };
            // Exercise system
            var result = sut.Create(requestedType, context);
            // Verify outcome
            var actual = Assert.IsAssignableFrom<MultiUnorderedConstructorType>(result);
            Assert.Equal(expectedText, actual.Text);
            Assert.Equal(expectedNumber, actual.Number);
            // Teardown
        }