Ejemplo n.º 1
0
        public void ItPrettyPrintsResult()
        {
            // Arrange
            var deliveryAddress = "Correct Address";
            Delivery delivery = null;
            var apiKey = Guid.Empty;
            var mockDataAccessor = MockRepository.GenerateStub<IDeliveryDataAccessor>();
            mockDataAccessor.Stub(x => x.GetDeliveryPointById(1)).Return(new DeliveryPoint() { Address = deliveryAddress });
            mockDataAccessor.Stub(x => x.AddDelivery(Arg<Delivery>.Is.Anything))
                .Do((Func<Delivery,int>)((d) => 
                    {
                        delivery = d;
                        return 1;
                    }));
            var mockSwiftConnector = MockRepository.GenerateMock<ISwiftConnector>();
            mockSwiftConnector.Expect(x => x.BookDeliveryAsync(Arg<DeliveryPoint>.Is.Anything, Arg<DeliveryPoint>.Matches(dp => dp.Address == deliveryAddress))).Return(Task.FromResult(@"{""foo"":""bar""}"));
            var deliveryService = new DeliveryService(mockSwiftConnector, mockDataAccessor);
            //Act
            var result = deliveryService.BookDeliveryAsync(1).Result;

            //Assert
            Assert.That(delivery, Is.Not.Null);
            Assert.That(delivery.BookingMessage.IndexOf("\n"), Is.GreaterThanOrEqualTo(0));
            Assert.That(result, Is.EqualTo(1));
        }
Ejemplo n.º 2
0
 public HomeController()
 {
     var apiKey = ConfigurationManager.AppSettings["SwiftApiKey"];
     var apiKeyParsed = Guid.Parse(apiKey);
     deliveryDataAccessor = new DeliveryDataAccessor();
     var swiftConnector = new SwiftConnector(apiKeyParsed, new SwiftClient());
     deliveryService = new DeliveryService(swiftConnector, deliveryDataAccessor);
 }
Ejemplo n.º 3
0
        public void ItRequestsDeliveryToCorrectAddress()
        {
            // Arrange
            var deliveryAddress = "Correct Address";
            var apiKey = Guid.Empty;
            var mockDataAccessor = MockRepository.GenerateStub<IDeliveryDataAccessor>();
            mockDataAccessor.Stub(x => x.GetDeliveryPointById(1)).Return(new DeliveryPoint(){Address=deliveryAddress});
            var mockSwiftConnector = MockRepository.GenerateMock<ISwiftConnector>();
            mockSwiftConnector.Expect(x => x.BookDeliveryAsync(Arg<DeliveryPoint>.Is.Anything, Arg<DeliveryPoint>.Matches(dp => dp.Address == deliveryAddress))).Return(Task.FromResult("{}"));
            var deliveryService = new DeliveryService(mockSwiftConnector, mockDataAccessor);
            //Act
            var result = deliveryService.BookDeliveryAsync(1);

            //Assert
            mockSwiftConnector.VerifyAllExpectations();
        }