Пример #1
0
		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);
		}
Пример #2
0
        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);
        }
Пример #3
0
		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);
		}
Пример #4
0
		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);
		}
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
		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();
		}
Пример #8
0
        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();
        }