public void ExecuteShouldNotThrowWhenSpecimenIsValidNonMockSpecimen(object validNonMockSpecimen) { // Fixture setup var context = new Mock<ISpecimenContext>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow( () => sut.Execute(validNonMockSpecimen, context.Object)); // Teardown }
public void ExecuteShouldNotThrowWhenSpecimenIsValidNonMockSpecimen(object validNonMockSpecimen) { // Arrange var context = new Mock <ISpecimenContext>(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Null( Record.Exception(() => sut.Execute(validNonMockSpecimen, context.Object))); }
public void SetupThrowsWhenContextIsNull() { // Arrange var mock = new Mock <object>(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Throws <ArgumentNullException>( () => sut.Execute(mock, null)); }
public void SetupThrowsWhenContextIsNull() { // Fixture setup var mock = new Mock<object>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>( () => sut.Execute(mock, null)); // Teardown }
public void SetupThrowsWhenMockIsNull() { // Fixture setup var context = new Mock<ISpecimenContext>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>( () => sut.Execute(null, context.Object)); // Teardown }
public void ExecuteShouldNotThrowWhenSpecimenIsValidNonMockSpecimen(object validNonMockSpecimen) { // Fixture setup var context = new Mock <ISpecimenContext>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow( () => sut.Execute(validNonMockSpecimen, context.Object)); // Teardown }
public void IgnoresStaticMethods() { // Arrange var fixture = new Fixture(); var mock = new Mock <TypeWithStaticMethod>(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Null(Record.Exception(() => sut.Execute(mock, new SpecimenContext(fixture)))); }
public void IgnoresStaticMethods() { // Fixture setup var fixture = new Fixture(); var mock = new Mock <TypeWithStaticMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(mock, new SpecimenContext(fixture))); }
public void SetupThrowsWhenContextIsNull() { // Fixture setup var mock = new Mock <object>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>( () => sut.Execute(mock, null)); // Teardown }
public void SetupThrowsWhenMockIsNull() { // Fixture setup var context = new Mock <ISpecimenContext>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>( () => sut.Execute(null, context.Object)); // Teardown }
public void IgnoresMethodsWithRefParameters() { // Arrange var fixture = new Fixture(); var mock = new Mock <IInterfaceWithRefMethod>(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Null(Record.Exception(() => sut.Execute(mock, new SpecimenContext(fixture)))); }
public void IgnoresVoidMethods() { // Fixture setup var fixture = new Fixture(); var mock = new Mock <IInterfaceWithVoidMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.Null(Record.Exception(() => sut.Execute(mock, new SpecimenContext(fixture)))); }
public void IgnoresNonMockSpecimens() { // Arrange // The context mock has a strict behaviour - if any of its members are invoked, an exception will be thrown var context = new Mock <ISpecimenContext>(MockBehavior.Strict); var specimen = new TypeWithVirtualMembers(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Null(Record.Exception(() => sut.Execute(specimen, context.Object))); }
public void IgnoresNonMockSpecimens() { // Fixture setup // The context mock has a strict behaviour - if any of its members are invoked, an exception will be thrown var context = new Mock <ISpecimenContext>(MockBehavior.Strict); var specimen = new TypeWithVirtualMembers(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(specimen, context.Object)); }
public void IgnoresGenericMethods() { // Arrange var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <IInterfaceWithGenericMethod>(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Null(Record.Exception(() => sut.Execute(mock, new SpecimenContext(fixture)))); Assert.NotEqual(frozenString, mock.Object.GenericMethod <string>()); }
public void IgnoresGenericMethods() { // Fixture setup var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <IInterfaceWithGenericMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(mock, new SpecimenContext(fixture))); Assert.NotEqual(frozenString, mock.Object.GenericMethod <string>()); }
public void IgnoresSealedMethods() { // Fixture setup var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <TypeWithSealedMembers>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(mock, new SpecimenContext(fixture))); Assert.NotEqual(frozenString, mock.Object.ImplicitlySealedMethod()); Assert.NotEqual(frozenString, mock.Object.ExplicitlySealedMethod()); }
public void IgnoresSealedMethods() { // Arrange var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <TypeWithSealedMembers>(); var sut = new MockVirtualMethodsCommand(); // Act & Assert Assert.Null(Record.Exception(() => sut.Execute(mock, new SpecimenContext(fixture)))); Assert.NotEqual(frozenString, mock.Object.ImplicitlySealedMethod()); Assert.NotEqual(frozenString, mock.Object.ExplicitlySealedMethod()); }
public void SetsUpMethodsLazily() { // Arrange var context = new Mock <ISpecimenContext>(); var mock = new Mock <IInterfaceWithParameterlessMethod>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, context.Object); // Assert context.Verify(ctx => ctx.Resolve(It.IsAny <object>()), Times.Never()); mock.Object.Method(); context.Verify(ctx => ctx.Resolve(It.IsAny <object>()), Times.Once()); }
public void IgnoresVirtualPropertiesWithGettersAndSetters() { // Fixture setup var fixture = new Fixture(); var mock = new Mock <TypeWithVirtualMembers>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome var result = mock.Object; Assert.Null(result.VirtualProperty); }
public void IgnoresPropertiesWithGettersAndSettersFromInheritedInterface() { // Arrange var fixture = new Fixture(); var mock = new Mock <IDerivedInterfaceWithProperty>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert var result = mock.Object; Assert.Null(result.Property); }
public void SetsUpInterfaceNewMethods_ToRetrieveReturnValueFromContext() { // Fixture setup var fixture = new Fixture(); var frozenString = fixture.Freeze<string>(); var mock = new Mock<IInterfaceWithNewMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome var result = mock.Object.Method(0); Assert.Same(frozenString, result); // Teardown }
public void IgnoresVirtualPropertiesWithGettersAndSetters() { // Arrange var fixture = new Fixture(); var mock = new Mock <TypeWithVirtualMembers>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert var result = mock.Object; Assert.Null(result.VirtualProperty); }
public void SetsUpVirtualPropertyGetters_ToRetrieveReturnValueFromContext() { // Arrange var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <TypeWithVirtualMembers>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert var result = mock.Object.VirtualGetOnlyProperty; Assert.Equal(frozenString, result); }
public void SetsUpIndexers() { // Arrange var fixture = new Fixture(); var frozenInt = fixture.Freeze <int>(); var mock = new Mock <IInterfaceWithIndexer>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert int result = mock.Object[3]; Assert.Equal(frozenInt, result); }
public void SetsUpMethodsLazily() { // Fixture setup var context = new Mock <ISpecimenContext>(); var mock = new Mock <IInterfaceWithParameterlessMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, context.Object); // Verify outcome context.Verify(ctx => ctx.Resolve(It.IsAny <object>()), Times.Never()); mock.Object.Method(); context.Verify(ctx => ctx.Resolve(It.IsAny <object>()), Times.Once()); // Teardown }
public void SetsUpMethodsWithParameters() { // Arrange var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <IInterfaceWithMethod>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert var result = mock.Object.Method("hi"); Assert.Same(frozenString, result); }
public void SetsUpInterfaceShadowedMethods_ToRetrieveReturnValueFromContext() { // Arrange var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <IInterfaceWithNewMethod>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert var result = (mock.Object as IInterfaceWithShadowedMethod).Method(0); Assert.Same(frozenString, result); }
public void SetsUpInterfaceBaseMethods_ToRetrieveReturnValueFromContext() { // Arrange var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <IDerivedInterface>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert var result = mock.Object.Method(); Assert.Same(frozenString, result); }
public void SetsUpMethodsWithOutParameters() { // Arrange var fixture = new Fixture(); var frozenInt = fixture.Freeze <int>(); var mock = new Mock <IInterfaceWithOutMethod>(); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, new SpecimenContext(fixture)); // Assert int outResult; mock.Object.Method(out outResult); Assert.Equal(frozenInt, outResult); }
public void SetsUpInterfaceNewMethods_ToRetrieveReturnValueFromContext() { // Fixture setup var fixture = new Fixture(); var frozenString = fixture.Freeze <string>(); var mock = new Mock <IInterfaceWithNewMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome var result = mock.Object.Method(0); Assert.Same(frozenString, result); // Teardown }
public void SetsUpIndexers() { // Fixture setup var fixture = new Fixture(); var frozenInt = fixture.Freeze <int>(); var mock = new Mock <IInterfaceWithIndexer>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome int result = mock.Object[3]; Assert.Equal(frozenInt, result); // Teardown }
public void SetsUpMethodsWithOutParameters() { // Fixture setup var fixture = new Fixture(); var frozenInt = fixture.Freeze <int>(); var mock = new Mock <IInterfaceWithOutMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome int outResult; mock.Object.Method(out outResult); Assert.Equal(frozenInt, outResult); // Teardown }
public void DoesNotSetupMethodsWithOutParametersWhenContextReturnsOmitSpecimen() { // Arrange var contextMock = new Mock <ISpecimenContext>(); contextMock.Setup(ctx => ctx.Resolve(typeof(int))) .Returns(new OmitSpecimen()); var mock = new Mock <IInterfaceWithOutMethod>(MockBehavior.Strict); var sut = new MockVirtualMethodsCommand(); // Act sut.Execute(mock, contextMock.Object); // Assert // The mock has strict behaviour - calling methods that were not setup cause an exception to be thrown int outResult; Assert.Throws <MockException>(() => mock.Object.Method(out outResult)); }
public void SetsUpIndexers() { // Fixture setup var fixture = new Fixture(); var frozenInt = fixture.Freeze<int>(); var mock = new Mock<IInterfaceWithIndexer>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome int result = mock.Object[3]; Assert.Equal(frozenInt, result); // Teardown }
public void SetsUpMethodsWithOutParameters() { // Fixture setup var fixture = new Fixture(); var frozenInt = fixture.Freeze<int>(); var mock = new Mock<IInterfaceWithOutMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, new SpecimenContext(fixture)); // Verify outcome int outResult; mock.Object.Method(out outResult); Assert.Equal(frozenInt, outResult); // Teardown }
public void SetsUpMethodsLazily() { // Fixture setup var context = new Mock<ISpecimenContext>(); var mock = new Mock<IInterfaceWithParameterlessMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, context.Object); // Verify outcome context.Verify(ctx => ctx.Resolve(It.IsAny<object>()), Times.Never()); mock.Object.Method(); context.Verify(ctx => ctx.Resolve(It.IsAny<object>()), Times.Once()); // Teardown }
public void IgnoresSealedMethods() { // Fixture setup var fixture = new Fixture(); var frozenString = fixture.Freeze<string>(); var mock = new Mock<TypeWithSealedMembers>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(mock, new SpecimenContext(fixture))); Assert.NotEqual(frozenString, mock.Object.ImplicitlySealedMethod()); Assert.NotEqual(frozenString, mock.Object.ExplicitlySealedMethod()); }
public void IgnoresGenericMethods() { // Fixture setup var fixture = new Fixture(); var frozenString = fixture.Freeze<string>(); var mock = new Mock<IInterfaceWithGenericMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(mock, new SpecimenContext(fixture))); Assert.NotEqual(frozenString, mock.Object.GenericMethod<string>()); }
public void IgnoresStaticMethods() { // Fixture setup var fixture = new Fixture(); var mock = new Mock<TypeWithStaticMethod>(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(mock, new SpecimenContext(fixture))); }
public void IgnoresNonMockSpecimens() { // Fixture setup // The context mock has a strict behaviour - if any of its members are invoked, an exception will be thrown var context = new Mock<ISpecimenContext>(MockBehavior.Strict); var specimen = new TypeWithVirtualMembers(); var sut = new MockVirtualMethodsCommand(); // Exercise system and verify outcome Assert.DoesNotThrow(() => sut.Execute(specimen, context.Object)); }
public void SetsUpOutParametersWithNullWhenContextReturnsNull() { // Fixture setup var contextMock = new Mock<ISpecimenContext>(); contextMock.Setup(ctx => ctx.Resolve(typeof (string))) .Returns(null); var mock = new Mock<IInterfaceWithMethodWithOutParameterOfReferenceType>(); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, contextMock.Object); // Verify outcome string outResult; mock.Object.Method(out outResult); Assert.Null(outResult); // Teardown }
public void DoesNotSetupMethodsWithOutParametersWhenContextReturnsOmitSpecimen() { // Fixture setup var contextMock = new Mock<ISpecimenContext>(); contextMock.Setup(ctx => ctx.Resolve(typeof (int))) .Returns(new OmitSpecimen()); var mock = new Mock<IInterfaceWithOutMethod>(MockBehavior.Strict); var sut = new MockVirtualMethodsCommand(); // Exercise system sut.Execute(mock, contextMock.Object); // Verify outcome // The mock has strict behaviour - calling methods that were not setup cause an exception to be thrown int outResult; Assert.Throws<MockException>(() => mock.Object.Method(out outResult)); // Teardown }