public async Task OnMessageReceivedSadPath2()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var mockDatabase = new Mock <IDatabase>();

            var service = new ExampleService(mockReceiver.Object, mockDatabase.Object);

            await service.StartAsync(CancellationToken.None);

            var fakeMessage = new FakeReceiverMessage("MyPayload")
            {
                Headers = { ["operation"] = "invalid" }
            };

            await service.Receiver.MessageHandler.OnMessageReceivedAsync(mockReceiver.Object, fakeMessage);

            fakeMessage.HandledBy.Should().Be(nameof(fakeMessage.RejectAsync));

            mockDatabase.Verify(m => m.CreateAsync("MyPayload"), Times.Never());
            mockDatabase.Verify(m => m.UpdateAsync("MyPayload"), Times.Never());
            mockDatabase.Verify(m => m.DeleteAsync("MyPayload"), Times.Never());

            // TODO: Verify that the error log was sent
        }
        public async Task StopAsyncHappyPath()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var database = new Mock <IDatabase>().Object;

            var service = new ExampleService(mockReceiver.Object, database);

            await service.StartAsync(CancellationToken.None);

            await service.StopAsync(CancellationToken.None);

            mockReceiver.Verify(m => m.Dispose(), Times.Once());
        }
        public async Task StartAsyncHappyPath()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var mockDatabase = new Mock <IDatabase>();

            var receiver = mockReceiver.Object;

            var service = new ExampleService(receiver, mockDatabase.Object);

            receiver.MessageHandler.Should().BeNull();

            await service.StartAsync(CancellationToken.None);

            receiver.MessageHandler.Should().NotBeNull();

            mockReceiver.Verify(m => m.Dispose(), Times.Never());
        }
        public async Task OnMessageReceivedHappyPath1()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var mockDatabase = new Mock <IDatabase>();

            var service = new ExampleService(mockReceiver.Object, mockDatabase.Object);

            await service.StartAsync(CancellationToken.None);

            var fakeMessage = new FakeReceiverMessage("MyPayload")
            {
                Headers = { ["operation"] = "create" }
            };

            await service.Receiver.MessageHandler.OnMessageReceivedAsync(mockReceiver.Object, fakeMessage);

            mockDatabase.Verify(m => m.CreateAsync("MyPayload"), Times.Once());
            fakeMessage.HandledBy.Should().Be(nameof(fakeMessage.AcknowledgeAsync));

            mockDatabase.Verify(m => m.UpdateAsync("MyPayload"), Times.Never());
            mockDatabase.Verify(m => m.DeleteAsync("MyPayload"), Times.Never());
        }