public void WhenParameterlessConstructorIsInvoked_ThenFixtureAndAttributeProviderAreCreated() { // Arrange // Act var attribute = new AutoMockDataAttribute(); // Assert attribute.Fixture.Should().NotBeNull(); attribute.Provider.Should().NotBeNull(); attribute.IgnoreVirtualMembers.Should().BeFalse(); }
public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ignoreVirtualMembers) { // Arrange var data = new[] { new object[] { 1, 2, 3 }, new object[] { 4, 5, 6 }, new object[] { 7, 8, 9 }, }; var fixture = A.Fake <IFixture>(); var customizations = new List <ICustomization>(); A.CallTo(() => fixture.Customize(A <ICustomization> ._)) .Invokes((ICustomization customization) => customizations.Add(customization)) .Returns(fixture); var dataAttribute = A.Fake <DataAttribute>(); A.CallTo(() => dataAttribute.GetData(A <MethodInfo> ._)).Returns(data); var provider = A.Fake <IAutoFixtureAttributeProvider>(); A.CallTo(() => provider.GetAttribute(A <IFixture> ._)).Returns(dataAttribute); var attribute = new AutoMockDataAttribute(fixture, provider) { IgnoreVirtualMembers = ignoreVirtualMembers, }; var methodInfo = typeof(AutoMockDataAttributeTests).GetMethod(nameof(this.TestMethod), BindingFlags.Instance | BindingFlags.NonPublic); // Act var result = attribute.GetData(methodInfo); // Assert result.Should().BeSameAs(data); A.CallTo(() => provider.GetAttribute(A <IFixture> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => dataAttribute.GetData(A <MethodInfo> ._)).MustHaveHappenedOnceExactly(); customizations.Count.Should().Be(2); customizations[0] .Should() .BeOfType <AutoDataCommonCustomization>() .Which.IgnoreVirtualMembers.Should() .Be(ignoreVirtualMembers); customizations[1].Should().BeOfType <AutoFakeItEasyCustomization>(); }
public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ignoreVirtualMembers) { // Arrange var data = new[] { new object[] { 1, 2, 3 }, new object[] { 4, 5, 6 }, new object[] { 7, 8, 9 } }; var fixture = new Mock <IFixture>(); var customizations = new List <ICustomization>(); fixture.Setup(x => x.Customize(It.IsAny <ICustomization>())) .Callback <ICustomization>(customization => customizations.Add(customization)) .Returns(fixture.Object); var dataAttribute = new Mock <DataAttribute>(); dataAttribute.Setup(a => a.GetData(It.IsAny <MethodInfo>())).Returns(data); var provider = new Mock <IAutoFixtureAttributeProvider>(); provider.Setup(p => p.GetAttribute(It.IsAny <IFixture>())).Returns(dataAttribute.Object); var attribute = new AutoMockDataAttribute(fixture.Object, provider.Object) { IgnoreVirtualMembers = ignoreVirtualMembers }; var methodInfo = typeof(AutoMockDataAttributeTests).GetMethod(nameof(this.TestMethod), BindingFlags.Instance | BindingFlags.NonPublic); // Act var result = attribute.GetData(methodInfo); // Assert result.Should().BeSameAs(data); provider.VerifyAll(); dataAttribute.VerifyAll(); customizations.Count.Should().Be(2); customizations[0] .Should() .BeOfType <AutoDataCommonCustomization>() .Which.IgnoreVirtualMembers.Should() .Be(ignoreVirtualMembers); customizations[1].Should().BeOfType <AutoMoqCustomization>(); }
public void WhenGetDataIsInvoked_ThenFixtureIsConfiguredAndDataReturned(bool ignoreVirtualMembers) { // Arrange var data = new[] { new object[] { 1, 2, 3 }, new object[] { 4, 5, 6 }, new object[] { 7, 8, 9 } }; var fixture = Substitute.For <IFixture>(); var customizations = new List <ICustomization>(); fixture.Customize(Arg.Do <ICustomization>(customization => customizations.Add(customization))) .Returns(fixture); var dataAttribute = Substitute.For <DataAttribute>(); dataAttribute.GetData(Arg.Any <MethodInfo>()).Returns(data); var provider = Substitute.For <IAutoFixtureAttributeProvider>(); provider.GetAttribute(Arg.Any <IFixture>()).Returns(dataAttribute); var attribute = new AutoMockDataAttribute(fixture, provider) { IgnoreVirtualMembers = ignoreVirtualMembers }; var methodInfo = typeof(AutoMockDataAttributeTests).GetMethod(nameof(this.TestMethod), BindingFlags.Instance | BindingFlags.NonPublic); // Act var result = attribute.GetData(methodInfo); // Assert result.Should().BeSameAs(data); provider.Received(1).GetAttribute(Arg.Any <IFixture>()); dataAttribute.Received(1).GetData(Arg.Any <MethodInfo>()); customizations.Count.Should().Be(2); customizations[0] .Should() .BeOfType <AutoDataCommonCustomization>() .Which.IgnoreVirtualMembers.Should() .Be(ignoreVirtualMembers); customizations[1].Should().BeOfType <AutoNSubstituteCustomization>(); }