コード例 #1
0
ファイル: QuotesTests.cs プロジェクト: iansrobinson/Restbucks
        public void ShouldReturn400BadRequestWhenShopIsNull()
        {
            try
            {
                var quotes = new Quotes(DefaultUriFactory.Instance, DummyQuotationEngine.Instance);
                quotes.Post(null, new HttpRequestMessage<Shop> { RequestUri = new Uri("http://localhost:8080/quotes") });
                Assert.Fail();

            }
            catch (HttpResponseException ex)
            {
                var response = ex.Response;

                Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
                Assert.AreEqual("no-store, no-cache", response.Headers.CacheControl.ToString());
                Assert.AreEqual("text/plain", response.Content.Headers.ContentType.MediaType);
                Assert.AreEqual("Bad request: empty or malformed data.", response.Content.ReadAsString());
            }
        }
コード例 #2
0
ファイル: QuotesTests.cs プロジェクト: iansrobinson/Restbucks
        private static Shop ExecuteRequestReturnEntityBody()
        {
            var quotes = new Quotes(DefaultUriFactory.Instance, DummyQuotationEngine.Instance);

            var request = new HttpRequestMessage<Shop> {RequestUri = DefaultUriFactory.Instance.CreateAbsoluteUri<Quotes>(BaseAddress)};
            var response = quotes.Post(new ShopBuilder(new Uri("http://localhost")).Build(), request);

            return response.Content.ReadAsOrDefault();
        }
コード例 #3
0
ファイル: QuotesTests.cs プロジェクト: iansrobinson/Restbucks
        private static HttpResponseMessage ExecuteRequestReturnResponse()
        {
            var quotes = new Quotes(DefaultUriFactory.Instance, DummyQuotationEngine.Instance);

            var request = new HttpRequestMessage<Shop> {RequestUri = DefaultUriFactory.Instance.CreateAbsoluteUri<Quotes>(BaseAddress)};
            return quotes.Post(new ShopBuilder(new Uri("http://localhost")).Build(), request);
        }
コード例 #4
0
ファイル: QuotesTests.cs プロジェクト: iansrobinson/Restbucks
        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();
        }