Beispiel #1
0
        public void GetDataReturnsCorrectResult()
        {
            // Fixture setup
            var method     = typeof(TypeWithOverloadedMembers).GetMethod("DoSomething", new[] { typeof(object) });
            var parameters = method.GetParameters();

            var expectedResult = new object();
            var builder        = new DelegatingSpecimenBuilder
            {
                OnCreate = (r, c) =>
                {
                    Assert.AreEqual(parameters.Single(), r);
                    Assert.IsNotNull(c);
                    return(expectedResult);
                }
            };
            var composer = new DelegatingFixture {
                OnCreate = builder.OnCreate
            };

            var sut = new AutoDataAttribute(composer);
            // Exercise system
            var testMethod = sut.ToTestMethod(method);
            var result     = sut.GetData(testMethod);

            // Verify outcome
            Assert.IsTrue(new[] { expectedResult }.SequenceEqual(result.Single()));
            // Teardown
        }
Beispiel #2
0
        public void InitializedWithComposerHasCorrectComposer()
        {
            // Fixture setup
            var expectedComposer = new DelegatingFixture();
            var sut = new AutoDataAttribute(expectedComposer);
            // Exercise system
            var result = sut.Fixture;

            // Verify outcome
            Assert.AreEqual(expectedComposer, result);
            // Teardown
        }
Beispiel #3
0
        public void GetDataOrdersCustomizationAttributes(string methodName)
        {
            // Fixture setup
            var method           = typeof(TypeWithCustomizationAttributes).GetMethod(methodName, new[] { typeof(ConcreteType) });
            var customizationLog = new List <ICustomization>();
            var fixture          = new DelegatingFixture();

            fixture.OnCustomize = c =>
            {
                customizationLog.Add(c);
                return(fixture);
            };
            var sut = new AutoDataAttribute(fixture);
            // Exercise system
            var testMethod = sut.ToTestMethod(method);
            var result     = sut.GetData(testMethod);

            // Verify outcome
            Assert.IsFalse(customizationLog[0] is FreezeOnMatchCustomization);
            Assert.IsTrue(customizationLog[1] is FreezeOnMatchCustomization);
            // Teardown
        }