Skip to content

Commit

Permalink
Add support for null as argument for the NUnit3 InlineAutoDataAttribu…
Browse files Browse the repository at this point in the history
…te (#1129)
  • Loading branch information
mjuen authored and zvirja committed Jun 13, 2019
1 parent bf99694 commit 9eb5953
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
20 changes: 13 additions & 7 deletions Src/AutoFixture.NUnit3.UnitTest/InlineAutoDataAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ namespace AutoFixture.NUnit3.UnitTest
[TestFixture]
public class InlineAutoDataAttributeTest
{
[Test]
public void IfArguementsIsNullThenThrows()
{
Assert.Throws<ArgumentNullException>(() => new InlineAutoDataAttribute(null));
}

[Test]
public void IfExtendedWithNullFixtureThenThrows()
{
Expand Down Expand Up @@ -109,6 +103,18 @@ public void InitializedWithArgumentsHasCorrectArguments()
Assert.AreSame(expectedArguments, result);
}

[Test]
public void ArgumentsIsNullBecomesObjectArrayWithNull()
{
// Arrange
var expectedArguments = new object[] { null };
var sut = new InlineAutoDataAttribute(null);
// Act
var result = sut.Arguments;
// Assert
Assert.AreEqual(expectedArguments, result);
}

[TestCase("CreateWithFrozenAndFavorArrays")]
[TestCase("CreateWithFavorArraysAndFrozen")]
[TestCase("CreateWithFrozenAndFavorEnumerables")]
Expand Down Expand Up @@ -201,4 +207,4 @@ public void ShouldRecognizeAttributesImplementingIParameterCustomizationSource()
Assert.True(customizationLog[0] is TypeWithIParameterCustomizationSourceUsage.Customization);
}
}
}
}
26 changes: 25 additions & 1 deletion Src/AutoFixture.NUnit3.UnitTest/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,29 @@ public void InlineAutoDataCanBeUsedWithFrozen(int p1, int p2, [Frozen]string p3,
{
Assert.True(p.Length == 3);
}

[Test]
[InlineAutoData(null)]
public void InlineAutoDataTakesNullAsParameterValue(string p1)
{
Assert.That(p1, Is.Null);
}

[Test]
[InlineAutoData(null)]
public void InlineAutoDataWithNullArgumentProvidesParameterValuesWhenMissing(string p1, string p2, string p3)
{
Assert.That(p1, Is.Null);
Assert.That(p2, Is.Not.Null);
Assert.That(p3, Is.Not.Null);
}

[Test]
[InlineAutoData(null)]
public void InlineAutoDataWithNullArgumentCanBeUsedWithFrozen(int? p1, int p2, [Frozen]string p3, string p4)
{
Assert.That(p1, Is.Null);
Assert.That(p3, Is.EqualTo(p4));
}
}
}
}
4 changes: 2 additions & 2 deletions Src/AutoFixture.NUnit3/InlineAutoDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected InlineAutoDataAttribute(IFixture fixture, params object[] arguments)
if (fixture == null) throw new ArgumentNullException(nameof(fixture));

this.fixtureLazy = new Lazy<IFixture>(() => fixture, LazyThreadSafetyMode.None);
this.existingParameterValues = arguments ?? throw new ArgumentNullException(nameof(arguments));
this.existingParameterValues = arguments ?? new object[] { null };
}

/// <summary>
Expand All @@ -66,7 +66,7 @@ protected InlineAutoDataAttribute(Func<IFixture> fixtureFactory, params object[]
if (fixtureFactory == null) throw new ArgumentNullException(nameof(fixtureFactory));

this.fixtureLazy = new Lazy<IFixture>(fixtureFactory, LazyThreadSafetyMode.PublicationOnly);
this.existingParameterValues = arguments ?? throw new ArgumentNullException(nameof(arguments));
this.existingParameterValues = arguments ?? new object[] { null };
}

/// <summary>
Expand Down

0 comments on commit 9eb5953

Please sign in to comment.