public void ShouldRespectContractNames() { var mocker = new MockExportProvider(); mocker.Arrange<IMessage>("msg", msg => msg.Message).Returns("yep"); var reader = mocker.Compose<MessageReader>("reader"); Assert.AreEqual("yep", reader.Message); }
public void ShouldRespectContractNames() { var mocker = new MockExportProvider(); mocker.Arrange <IMessage>("msg", msg => msg.Message).Returns("yep"); var reader = mocker.Compose <MessageReader>("reader"); Assert.AreEqual("yep", reader.Message); }
public void ShouldAssignMetadataOnImports() { var container = new MockExportProvider(); container.ExportMock<IMessage>(metadata: new Dictionary<string, object> { { "Severity", Severity.Warning } }) .Arrange(message => message.Message).Returns("Be careful"); container.ExportMock<IMessage>(metadata: new Dictionary<string, object> { { "Severity", Severity.Error } }) .Arrange(message => message.Message).Returns("Failed"); var printer = container.Compose<MessagePrinter>(); var result = printer.Print(); var expected = "Error: Failed\nWarning: Be careful"; Assert.AreEqual(expected, result); }
public void UntypedMockExportProvider() { string msg = null; var mocker = new MockExportProvider(); mocker.Arrange<ILogger>(log => log.Log(Arg.AnyString)).DoInstead((string log) => msg = log); mocker.Arrange<IMessage>(message => message.Message).Returns("foo"); mocker.ExportMock<ICounter>(); var greeter = mocker.Compose<Greeter>(); greeter.Greet(); Assert.AreEqual("0: foo", msg); }
public void UntypedMockExportProvider() { string msg = null; var mocker = new MockExportProvider(); mocker.Arrange <ILogger>(log => log.Log(Arg.AnyString)).DoInstead((string log) => msg = log); mocker.Arrange <IMessage>(message => message.Message).Returns("foo"); mocker.ExportMock <ICounter>(); var greeter = mocker.Compose <Greeter>(); greeter.Greet(); Assert.AreEqual("0: foo", msg); }
public void ShouldAssignMetadataOnImports() { var container = new MockExportProvider(); container.ExportMock <IMessage>(metadata: new Dictionary <string, object> { { "Severity", Severity.Warning } }) .Arrange(message => message.Message).Returns("Be careful"); container.ExportMock <IMessage>(metadata: new Dictionary <string, object> { { "Severity", Severity.Error } }) .Arrange(message => message.Message).Returns("Failed"); var printer = container.Compose <MessagePrinter>(); var result = printer.Print(); var expected = "Error: Failed\nWarning: Be careful"; Assert.AreEqual(expected, result); }
public void ShouldAssertExpectationsOnAllMocks() { var mocker = new MockExportProvider(); mocker.ExportMock<IMessage>(); mocker.Arrange<ICounter>(counter => counter.Next).Returns(5); mocker.Arrange<ILogger>(log => log.Log(Arg.AnyString)).MustBeCalled(); AssertEx.Throws<AssertFailedException>(() => mocker.Assert()); AssertEx.Throws<AssertFailedException>(() => mocker.AssertAll()); AssertEx.Throws<AssertFailedException>(() => mocker.Assert<ILogger>()); mocker.ExportMock<ICounter>().Assert(); AssertEx.Throws<AssertFailedException>(() => mocker.ExportMock<ICounter>().AssertAll()); var greeter = mocker.Compose<Greeter>(); greeter.Greet(); mocker.Assert(); mocker.AssertAll(); mocker.Assert<ILogger>(); mocker.ExportMock<ICounter>().Assert(); mocker.ExportMock<ICounter>().AssertAll(); }
public void ShouldAssertExpectationsOnAllMocks() { var mocker = new MockExportProvider(); mocker.ExportMock <IMessage>(); mocker.Arrange <ICounter>(counter => counter.Next).Returns(5); mocker.Arrange <ILogger>(log => log.Log(Arg.AnyString)).MustBeCalled(); AssertEx.Throws <AssertFailedException>(() => mocker.Assert()); AssertEx.Throws <AssertFailedException>(() => mocker.AssertAll()); AssertEx.Throws <AssertFailedException>(() => mocker.Assert <ILogger>()); mocker.ExportMock <ICounter>().Assert(); AssertEx.Throws <AssertFailedException>(() => mocker.ExportMock <ICounter>().AssertAll()); var greeter = mocker.Compose <Greeter>(); greeter.Greet(); mocker.Assert(); mocker.AssertAll(); mocker.Assert <ILogger>(); mocker.ExportMock <ICounter>().Assert(); mocker.ExportMock <ICounter>().AssertAll(); }