public PostOrderShould()
 {
     config = new Config
     {
         ExternalSimCardsProviderApiUrl = "http://api:5000"
     };
     options       = Options.Create(config);
     expectedUrl   = new Uri($"{config.ExternalSimCardsProviderApiUrl}/api/orders");
     expectedOrder = new ExternalSimCardOrder
     {
         Name        = "Neil Armstrong",
         PhoneNumber = "07930123456"
     };
     handlerMock = new Mock <DelegatingHandler>();
     handlerMock.Protected()
     .Setup <Task <HttpResponseMessage> >("SendAsync",
                                          ItExpr.Is <HttpRequestMessage>(
                                              x => x.RequestUri == expectedUrl),
                                          ItExpr.IsAny <CancellationToken>())
     .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
     {
         Content = new StringContent(JsonSerializer.Serialize(expectedOrder))
     }
                              ));
     httpClient = new HttpClient(handlerMock.Object);
 }
            public async void ReturnFalseWhenSendOrderFails()
            {
                var expectedExternalSimCardOrder = new ExternalSimCardOrder
                {
                    Name      = receivedEvent.Name,
                    Reference = receivedEvent.MobileId,
                };

                externalSimCardProviderServiceMock.Setup(x => x.PostOrder(It.IsAny <ExternalSimCardOrder>()))
                .Returns(Task.FromResult(false));

                var actual = await sut.Handle(receivedEvent);

                actual.Should().BeFalse();
            }
            public async void RollbackWhenSendOrderFails()
            {
                var expectedExternalSimCardOrder = new ExternalSimCardOrder
                {
                    Name      = receivedEvent.Name,
                    Reference = receivedEvent.MobileId,
                };

                externalSimCardProviderServiceMock.Setup(x => x.PostOrder(It.IsAny <ExternalSimCardOrder>()))
                .Returns(Task.FromResult(false));

                var actual = await sut.Handle(receivedEvent);

                transactionMock.Verify(x => x.Rollback());
            }
            public async void SaveOrder()
            {
                var expectedExternalSimCardOrder = new ExternalSimCardOrder
                {
                    Name      = receivedEvent.Name,
                    Reference = receivedEvent.MobileId,
                };

                externalSimCardProviderServiceMock.Setup(x => x.PostOrder(It.Is <ExternalSimCardOrder>(
                                                                              y => y.Name == expectedExternalSimCardOrder.Name && y.Reference == expectedExternalSimCardOrder.Reference
                                                                              )))
                .Returns(Task.FromResult(true));

                var actual = await sut.Handle(receivedEvent);

                dataStoreMock.Verify(x => x.Add(
                                         It.Is <SimCardOrder>(y => y.Name == expectedExternalSimCardOrder.Name &&
                                                              y.MobileId == expectedExternalSimCardOrder.Reference)));
                transactionMock.Verify(x => x.Dispose());
            }