public void WhenParameterlessConstructorIsInvoked_ThenHasNoValuesButFixtureAndAttributeProviderAreCreated() { // Arrange // Act var attribute = new InlineAutoMockDataAttribute(); // Assert attribute.Fixture.Should().NotBeNull(); attribute.IgnoreVirtualMembers.Should().BeFalse(); attribute.Provider.Should().NotBeNull(); attribute.Values.Should().HaveCount(0); }
public void GivenUninitializedValues_WhenConstructorIsInvoked_ThenHasNoValuesAndFixtureAndAttributeProviderAreCreated() { // Arrange const object[] initialValues = null; // Act var attribute = new InlineAutoMockDataAttribute(initialValues); // Assert attribute.Fixture.Should().NotBeNull(); attribute.IgnoreVirtualMembers.Should().BeFalse(); attribute.Provider.Should().NotBeNull(); attribute.Values.Should().HaveCount(0); }
public void GivenExistingInlineValues_WhenConstructorIsInvoked_ThenHasSpecifiedValuesAndFixtureAndAttributeProviderAreCreated() { // Arrange var initialValues = new[] { "test", 1, new object() }; // Act var attribute = new InlineAutoMockDataAttribute(initialValues[0], initialValues[1], initialValues[2]); // Assert attribute.Fixture.Should().NotBeNull(); attribute.IgnoreVirtualMembers.Should().BeFalse(); attribute.Provider.Should().NotBeNull(); attribute.Values.Should().BeEquivalentTo(initialValues); }
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 <IAutoFixtureInlineAttributeProvider>(); A.CallTo(() => provider.GetAttribute(A <IFixture> ._)).Returns(dataAttribute); var attribute = new InlineAutoMockDataAttribute(fixture, provider) { IgnoreVirtualMembers = ignoreVirtualMembers }; var methodInfo = typeof(InlineAutoMockDataAttributeTests).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 <IAutoFixtureInlineAttributeProvider>(); provider.Setup(p => p.GetAttribute(It.IsAny <IFixture>())).Returns(dataAttribute.Object); var attribute = new InlineAutoMockDataAttribute(fixture.Object, provider.Object) { IgnoreVirtualMembers = ignoreVirtualMembers, }; var methodInfo = typeof(InlineAutoMockDataAttributeTests).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 <IAutoFixtureInlineAttributeProvider>(); provider.GetAttribute(Arg.Any <IFixture>()).Returns(dataAttribute); var attribute = new InlineAutoMockDataAttribute(fixture, provider) { IgnoreVirtualMembers = ignoreVirtualMembers }; var methodInfo = typeof(InlineAutoMockDataAttributeTests).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>(); }