Exemplo n.º 1
0
        public void ShouldGetQuoteFromQuoteEngine()
        {
            var mockQuoteEngine = MockRepository.GenerateMock<IQuotationEngine>();

            var id = Guid.NewGuid();

            var expectedQuote = new Quotation(
                Guid.Empty,
                DateTime.Now,
                new[]
                    {
                        new LineItem("item1", new Quantity("g", 250), new Money("GBP", 2.50)),
                        new LineItem("item2", new Quantity("kg", 2), new Money("GBP", 2.00))
                    });

            mockQuoteEngine.Expect(q => q.GetQuote(id)).Return(expectedQuote);

            var request = new HttpRequestMessage {RequestUri = DefaultUriFactory.Instance.CreateAbsoluteUri<Quote>(BaseAddress, id)};
            var quote = new Quote(DefaultUriFactory.Instance, mockQuoteEngine);
            var response = quote.Get(id.ToString("N"), request);

            var body = response.Content.ReadAsOrDefault();

            Assert.True(body.HasItems);
            Assert.True(Matching.LineItemsMatchItems(expectedQuote.LineItems, body.Items));

            mockQuoteEngine.VerifyAllExpectations();
        }
        private static void AssertQuoteIsCorrect(Quotation quotation)
        {
            Assert.AreEqual(Id, quotation.Id);
            Assert.AreEqual(CreatedDateTime, quotation.CreatedDateTime);

            Assert.AreEqual(2, quotation.LineItems.Count());

            var firstItem = quotation.LineItems.First();
            Assert.AreEqual("Costa Rica Tarrazu", firstItem.Description);
            Assert.AreEqual("g", firstItem.Quantity.Measure);
            Assert.AreEqual(250, firstItem.Quantity.Value);
            Assert.AreEqual(2.50, firstItem.Price.Value);
            Assert.AreEqual("GBP", firstItem.Price.Currency);

            var secondItem = quotation.LineItems.Last();
            Assert.AreEqual("Elephant Beans", secondItem.Description);
            Assert.AreEqual("g", secondItem.Quantity.Measure);
            Assert.AreEqual(300, secondItem.Quantity.Value);
            Assert.AreEqual(3.00, secondItem.Price.Value);
            Assert.AreEqual("GBP", secondItem.Price.Currency);
        }
Exemplo n.º 3
0
        public void ShouldReturnNewQuoteFromQuoteEngine()
        {
            var mockQuoteEngine = MockRepository.GenerateMock<IQuotationEngine>();

            var shop = new ShopBuilder(new Uri("http://localhost/"))
                .AddItem(new Item("item1", new Amount("g", 250)))
                .AddItem(new Item("item2", new Amount("kg", 2)))
                .Build();

            var quote = new Quotation(
                Guid.Empty,
                DateTime.Now,
                new[]
                    {
                        new LineItem("item1", new Quantity("g", 250), new Money("GBP", 2.50)),
                        new LineItem("item2", new Quantity("kg", 2), new Money("GBP", 2.00))
                    });

            mockQuoteEngine.Expect(q => q.CreateQuote(null))
                .Constraints(Is.Matching<QuotationRequest>(qr => Matching.QuoteRequestItemsMatchItems(qr.Items, shop.Items)))
                .Return(quote);

            var quotes = new Quotes(DefaultUriFactory.Instance, mockQuoteEngine);
            var response = quotes.Post(shop, new HttpRequestMessage<Shop>{ RequestUri = new Uri("http://localhost:8080/quotes") });

            var entityBody = response.Content.ReadAsOrDefault();

            Assert.True(entityBody.HasItems);
            Assert.True(Matching.LineItemsMatchItems(quote.LineItems, entityBody.Items));

            mockQuoteEngine.VerifyAllExpectations();
        }