Exemplo n.º 1
0
        public void GetDataOrdersCustomizationAttributes(string methodName)
        {
            // Fixture setup
            var method = typeof(TypeWithCustomizationAttributes).GetMethod(methodName, new[] { typeof(ConcreteType) });

            var parameters     = method.GetParameters();
            var parameterTypes = (from pi in parameters
                                  select pi.ParameterType).ToArray();

            var customizationLog = new List <ICustomization>();
            var fixture          = new DelegatingFixture();

            fixture.OnCustomize = c =>
            {
                customizationLog.Add(c);
                return(fixture);
            };
            var sut = new AutoDataAttribute(fixture);

            // Exercise system
            sut.GetData(method, parameterTypes);
            // Verify outcome
            Assert.False(customizationLog[0] is FreezeOnMatchCustomization);
            Assert.True(customizationLog[1] is FreezeOnMatchCustomization);
            // Teardown
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InlineNullRegisterAutoDataAttribute"/> class.
 /// </summary>
 /// <param name="autoDataAttribute">The <see cref="AutoDataAttribute"/> instance that provides auto-generated data specimens.</param>
 /// <param name="parameterName">Name of the null parameter.</param>
 public InlineNullRegisterAutoDataAttribute(
     AutoDataAttribute autoDataAttribute,
     string parameterName)
     : base(autoDataAttribute)
 {
     _parameterName = parameterName;
 }
Exemplo n.º 3
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.Equal(parameters.Single(), r);
                    Assert.NotNull(c);
                    return(expectedResult);
                }
            };
            var composer = new DelegatingFixture {
                OnCreate = builder.OnCreate
            };

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

            // Verify outcome
            Assert.True(new[] { expectedResult }.SequenceEqual(result.Single()));
            // Teardown
        }
Exemplo n.º 4
0
        public void GetArgumentsWithNullMethodThrows()
        {
            // Arrange
            var sut = new AutoDataAttribute();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.GetData(null));
        }
 public void SutIsDataAttribute()
 {
     // Fixture setup
     // Exercise system
     var sut = new AutoDataAttribute();
     // Verify outcome
     Assert.IsAssignableFrom<DataAttribute>(sut);
     // Teardown
 }
        public void SutIsDataAttribute()
        {
            // Arrange
            // Act
            var sut = new AutoDataAttribute();

            // Assert
            Assert.IsAssignableFrom <DataAttribute>(sut);
        }
Exemplo n.º 7
0
        public void SutIsDataAttribute()
        {
            // Arrange
            // Act
            var sut = new AutoDataAttribute();

            // Assert
            Assert.IsInstanceOf <DataAttribute>(sut);
        }
        public void GetDataWithNullMethodThrows()
        {
            // Arrange
            var sut        = new AutoDataAttribute();
            var dummyTypes = Type.EmptyTypes;

            // Act & assert
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.GetData(null));
        }
Exemplo n.º 9
0
        public void GetArgumentsWithNullMethodThrows()
        {
            // Fixture setup
            var sut = new AutoDataAttribute();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.GetData(null));
            // Teardown
        }
Exemplo n.º 10
0
        public void AutoDataAttributeUsesRealValueByDefault()
        {
            // Arrange
            // Act
            var sut = new AutoDataAttribute();

            // Assert
            Assert.That(sut.TestMethodBuilder,
                        Is.TypeOf <FixedNameTestMethodBuilder>());
        }
Exemplo n.º 11
0
        public void SutIsDataAttribute()
        {
            // Fixture setup
            // Exercise system
            var sut = new AutoDataAttribute();

            // Verify outcome
            Assert.IsAssignableFrom <DataAttribute>(sut);
            // Teardown
        }
 public void InitializedWithDefaultConstructorHasCorrectFixture()
 {
     // Fixture setup
     var sut = new AutoDataAttribute();
     // Exercise system
     IFixture result = sut.Fixture;
     // Verify outcome
     Assert.IsAssignableFrom<Fixture>(result);
     // Teardown
 }
Exemplo n.º 13
0
        public void SutIsDataAttribute()
        {
            // Fixture setup
            // Exercise system
            var sut = new AutoDataAttribute();

            // Verify outcome
            Assert.IsInstanceOfType(sut, typeof(DataAttribute));
            // Teardown
        }
Exemplo n.º 14
0
        public void AutoDataAttributeIsCorrectWhenCreatedExplicitlyByConstructor()
        {
            // Arrange
            var expected = new AutoDataAttribute();
            var sut      = new DerivedInlineAutoDataAttribute(expected);
            // Act
            var result = sut.AutoDataAttribute;

            // Assert
            Assert.Equal(expected, result);
        }
Exemplo n.º 15
0
        public void ExecuteShouldAutoGenerateReferenceTypeArgument(AutoDataAttribute sut)
        {
            // Arrange


            // Act


            // Assert
            Assert.IsNotNull(sut);
        }
Exemplo n.º 16
0
        public void AttributesContainsAttributeWhenConstructedWithExplicitAutoDataAttribute()
        {
            // Arrange
            var autoDataAttribute = new AutoDataAttribute();
            var sut = new DerivedInlineAutoDataAttribute(autoDataAttribute);
            // Act
            var result = sut.Attributes;

            // Assert
            Assert.Contains(autoDataAttribute, result);
        }
Exemplo n.º 17
0
        public void InitializedWithDefaultConstructorHasCorrectFixture()
        {
            // Fixture setup
            var sut = new AutoDataAttribute();
            // Exercise system
            IFixture result = sut.Fixture;

            // Verify outcome
            Assert.IsInstanceOfType(result, typeof(Fixture));
            // Teardown
        }
Exemplo n.º 18
0
        public void AutoDataAttributeUsesRealValueByDefault()
        {
            // Fixture setup
            // Exercise system
            var sut = new AutoDataAttribute();

            // Verify outcome
            Assert.That(sut.TestMethodBuilder,
                        Is.TypeOf <FixedNameTestMethodBuilder>());
            // Teardown
        }
        public void ExecuteShouldAutoGenerateReferenceTypeArgument(AutoDataAttribute sut)
        {
            // Arrange


            // Act


            // Assert
            sut.ShouldNotBeNull();
        }
        public void InitializedWithCorrectComposerTypeHasCorrectComposer()
        {
            // Arrange
            var composerType = typeof(DelegatingFixture);
            var sut          = new AutoDataAttribute(composerType);
            // Act
            var result = sut.Fixture;

            // Assert
            Assert.IsAssignableFrom(composerType, result);
        }
        public void FixtureTypeIsCorrect()
        {
            // Arrange
            var composerType = typeof(DelegatingFixture);
            var sut          = new AutoDataAttribute(composerType);
            // Act
            var result = sut.FixtureType;

            // Assert
            Assert.Equal(composerType, result);
        }
Exemplo n.º 22
0
        public void AutoDataAttributeIsCorrectWhenCreatedWithModestConstructor()
        {
            // Fixture setup
            var sut = new InlineAutoDataAttribute();
            // Exercise system
            AutoDataAttribute result = sut.AutoDataAttribute;

            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
Exemplo n.º 23
0
        public void InitializedWithDefaultConstructorHasCorrectFixture()
        {
            // Fixture setup
            var sut = new AutoDataAttribute();
            // Exercise system
            IFixture result = sut.Fixture;

            // Verify outcome
            Assert.IsAssignableFrom <Fixture>(result);
            // Teardown
        }
 public void InitializedWithComposerHasCorrectComposer()
 {
     // Fixture setup
     var expectedComposer = new DelegatingFixture();
     var sut = new AutoDataAttribute(expectedComposer);
     // Exercise system
     var result = sut.Fixture;
     // Verify outcome
     Assert.Equal(expectedComposer, result);
     // Teardown
 }
 public void AttributesContainsAttributeWhenConstructedWithExplicitAutoDataAttribute()
 {
     // Fixture setup
     var autoDataAttribute = new AutoDataAttribute();
     var sut = new InlineAutoDataAttribute(autoDataAttribute);
     // Exercise system
     var result = sut.Attributes;
     // Verify outcome
     Assert.Contains(autoDataAttribute, result);
     // Teardown
 }
        public void InitializedWithDefaultConstructorHasCorrectFixture()
        {
            // Arrange
            var sut = new AutoDataAttribute();

            // Act
#pragma warning disable 618
            IFixture result = sut.Fixture;
#pragma warning restore 618
            // Assert
            Assert.IsAssignableFrom <Fixture>(result);
        }
Exemplo n.º 27
0
        public void ValuesAreCorrectWhenConstructedWithExplicitAutoDataAttribute()
        {
            // Arrange
            var dummyAutoDataAttribute = new AutoDataAttribute();
            var expectedValues         = new[] { new object(), new object(), new object() };
            var sut = new DerivedInlineAutoDataAttribute(dummyAutoDataAttribute, expectedValues);
            // Act
            var result = sut.Values;

            // Assert
            Assert.True(expectedValues.SequenceEqual(result));
        }
Exemplo n.º 28
0
        public void InitializedWithCorrectComposerTypeHasCorrectComposer()
        {
            // Fixture setup
            var composerType = typeof(DelegatingFixture);
            var sut          = new AutoDataAttribute(composerType);
            // Exercise system
            var result = sut.Fixture;

            // Verify outcome
            Assert.IsAssignableFrom(composerType, result);
            // Teardown
        }
Exemplo n.º 29
0
        public void FixtureTypeIsCorrect()
        {
            // Fixture setup
            var composerType = typeof(DelegatingFixture);
            var sut          = new AutoDataAttribute(composerType);
            // Exercise system
            var result = sut.FixtureType;

            // Verify outcome
            Assert.Equal(composerType, result);
            // Teardown
        }
Exemplo n.º 30
0
        public void AttributesContainsCorrectAttributeTypesWhenConstructorWithExplicitAutoDataAttribute()
        {
            // Arrange
            var autoDataAttribute = new AutoDataAttribute();
            var sut = new InlineAutoDataAttribute(autoDataAttribute);
            // Act
            var result = sut.Attributes;
            // Assert
            var expected = new[] { typeof(InlineDataAttribute), autoDataAttribute.GetType() };

            Assert.True(result.Select(d => d.GetType()).SequenceEqual(expected));
        }
Exemplo n.º 31
0
        public void AttributesContainsAttributeWhenConstructedWithExplicitAutoDataAttribute()
        {
            // Fixture setup
            var autoDataAttribute = new AutoDataAttribute();
            var sut = new InlineAutoDataAttribute(autoDataAttribute);
            // Exercise system
            var result = sut.Attributes;

            // Verify outcome
            Assert.Contains(autoDataAttribute, result);
            // Teardown
        }
 public void AttributesContainsCorrectAttributeTypesWhenConstructorWithExplicitAutoDataAttribute()
 {
     // Fixture setup
     var autoDataAttribute = new AutoDataAttribute();
     var sut = new InlineAutoDataAttribute(autoDataAttribute);
     // Exercise system
     var result = sut.Attributes;
     // Verify outcome
     var expected = new[] { typeof(InlineDataAttribute), autoDataAttribute.GetType() };
     Assert.True(result.Select(d => d.GetType()).SequenceEqual(expected));
     // Teardown
 }
Exemplo n.º 33
0
        public void InitializedWithComposerHasCorrectComposer()
        {
            // Fixture setup
            var expectedComposer = new DelegatingFixture();
            var sut = new AutoDataAttribute(expectedComposer);
            // Exercise system
            var result = sut.Fixture;

            // Verify outcome
            Assert.Equal(expectedComposer, result);
            // Teardown
        }
Exemplo n.º 34
0
        public void AutoDataAttributeIsCorrectWhenCreatedExplicitlyByConstructor()
        {
            // Fixture setup
            var expected = new AutoDataAttribute();
            var sut      = new InlineAutoDataAttribute(expected);
            // Exercise system
            var result = sut.AutoDataAttribute;

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
Exemplo n.º 35
0
        public void ValuesAreCorrectWhenConstructedWithExplicitAutoDataAttribute()
        {
            // Fixture setup
            var dummyAutoDataAttribute = new AutoDataAttribute();
            var expectedValues         = new[] { new object(), new object(), new object() };
            var sut = new InlineAutoDataAttribute(dummyAutoDataAttribute, expectedValues);
            // Exercise system
            var result = sut.Values;

            // Verify outcome
            Assert.True(expectedValues.SequenceEqual(result));
            // Teardown
        }
Exemplo n.º 36
0
        public void BuildFromYieldsRunnableTestMethod()
        {
            // Arrange
            var autoDataAttribute = new AutoDataAttribute();
            var fixtureType = this.GetType();

            var methodWrapper = new MethodWrapper(fixtureType, fixtureType.GetMethod("DummyTestMethod"));
            var testSuite = new TestSuite(fixtureType);

            // Act
            var testMethod = autoDataAttribute.BuildFrom(methodWrapper, testSuite).First();

            // Assert
            Assert.That(testMethod.RunState == RunState.Runnable);
        }
 public void InitializedWithCorrectComposerTypeHasCorrectComposer()
 {
     // Fixture setup
     var composerType = typeof(DelegatingFixture);
     var sut = new AutoDataAttribute(composerType);
     // Exercise system
     var result = sut.Fixture;
     // Verify outcome
     Assert.IsAssignableFrom(composerType, result);
     // Teardown
 }
Exemplo n.º 38
0
        public void FixtureTypeIsCorrect()
        {
            // Fixture setup
            var composerType = typeof(DelegatingFixture);
#pragma warning disable 618
            var sut = new AutoDataAttribute(composerType);
#pragma warning restore 618
            // Exercise system
            var result = sut.FixtureType;
            // Verify outcome
            Assert.AreEqual(composerType, result);
            // Teardown
        }
Exemplo n.º 39
0
 public void ImplementsITestBuilder()
 {
     var autoDataFixture = new AutoDataAttribute();
     Assert.That(autoDataFixture, Is.InstanceOf<ITestBuilder>());
 }
 public void FixtureTypeIsCorrect()
 {
     // Fixture setup
     var composerType = typeof(DelegatingFixture);
     var sut = new AutoDataAttribute(composerType);
     // Exercise system
     var result = sut.FixtureType;
     // Verify outcome
     Assert.Equal(composerType, result);
     // Teardown
 }
Exemplo n.º 41
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
     sut.GetData(method);
     // Verify outcome
     Assert.False(customizationLog[0] is FreezeOnMatchCustomization);
     Assert.True(customizationLog[1] is FreezeOnMatchCustomization);
     // Teardown
 }
 public void GetDataWithNullMethodThrows()
 {
     // Fixture setup
     var sut = new AutoDataAttribute();
     var dummyTypes = Type.EmptyTypes;
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() =>
         sut.GetData(null, dummyTypes));
     // Teardown
 }
 public void ValuesAreCorrectWhenConstructedWithExplicitAutoDataAttribute()
 {
     // Fixture setup
     var dummyAutoDataAttribute = new AutoDataAttribute();
     var expectedValues = new[] { new object(), new object(), new object() };
     var sut = new InlineAutoDataAttribute(dummyAutoDataAttribute, expectedValues);
     // Exercise system
     var result = sut.Values;
     // Verify outcome
     Assert.True(expectedValues.SequenceEqual(result));
     // Teardown
 }
        public void GetDataReturnsCorrectResult()
        {
            // Fixture setup
            var method = typeof(TypeWithOverloadedMembers).GetMethod("DoSomething", new[] { typeof(object) });
            var parameters = method.GetParameters();
            var parameterTypes = (from pi in parameters
                                  select pi.ParameterType).ToArray();

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

            var sut = new AutoDataAttribute(composer);
            // Exercise system
            var result = sut.GetData(method, parameterTypes);
            // Verify outcome
            Assert.True(new[] { expectedResult }.SequenceEqual(result.Single()));
            // Teardown
        }
 public void AutoDataAttributeIsCorrectWhenCreatedExplicitlyByConstructor()
 {
     // Fixture setup
     var expected = new AutoDataAttribute();
     var sut = new InlineAutoDataAttribute(expected);
     // Exercise system
     var result = sut.AutoDataAttribute;
     // Verify outcome
     Assert.Equal(expected, result);
     // Teardown
 }