public void ShouldReturnDestinationsForStockholm()
        {
            // Arrange
            var destinations = new List<string> { "New York", "Tokyo" };

            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(repository => repository.GetDestinationsForAirport(It.Is<string>(s => s == "Borlänge")))
                     .Returns(destinations);

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<DestinationsModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/destinations/Borlänge",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("application/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);

            var jsonResult = result.Body.DeserializeJson<List<string>>();

            jsonResult.Should().BeEquivalentTo(destinations);
        }
        public void ShouldReturnErrorWhenDateIsInvalid()
        {
            // Arrange
            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(
                repository => repository.GetOffers(It.IsAny<string>(), It.IsAny<DateTime>()))
                     .Returns(new[] { new Offer(), new Offer() });

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferSearchModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/offers/from/Borlänge/on/2013-01-01asd",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("text/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            result.Body.AsString().Should().Be("Departure date format is invalid");
        }
        public void ShouldReturnOffersForAirport()
        {
            // Arrange
            var offer = new Offer
                            {
                                City = "Stockholm",
                                BookingUrl = "http://fake.com",
                                Date = DateTime.Now,
                                Days = 7,
                                Departure = "Borlänge",
                                Destination = "Sverige",
                                HotelId = "10",
                                Price = 2000,
                                Remaining = 2,
                                RoomDesc = "Enkelrum"
                            };

            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(repository => repository.GetOffers(It.Is<string>(s => s == "Borlänge")))
                     .Returns(new[] { offer });

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferSearchModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/offers/from/Borlänge",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("text/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);

            var offers = result.Body.DeserializeJson<Offer[]>();

            offers.Length.Should().Be(1);

            var firstOffer = offers[0];
            firstOffer.City.Should().Be(offer.City);
            firstOffer.BookingUrl.Should().Be(offer.BookingUrl);
            firstOffer.Date.Should().Be(offer.Date);
            firstOffer.Days.Should().Be(offer.Days);
            firstOffer.Departure.Should().Be(offer.Departure);
            firstOffer.Destination.Should().Be(offer.Destination);
            firstOffer.HotelId.Should().Be(offer.HotelId);
            firstOffer.Price.Should().Be(offer.Price);
            firstOffer.Remaining.Should().Be(offer.Remaining);
            firstOffer.RoomDesc.Should().Be(offer.RoomDesc);
        }
        public void ShouldReturnHotel()
        {
            // Arrange
            var hotel = new Hotel
                            {
                                Name = "Taj Mahal",
                                ImageUrl = "http://www.fake.com/image.jpg",
                                Grade = 4.5m,
                                Html = "<blink>AWESOME</blink>",
                                Id = "1",
                                Url = "http://fake.com"
                            };

            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(repository => repository.GetHotel(It.Is<string>(s => s == "10")))
                     .Returns(hotel);

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferHotelModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/offer/hotel/10",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("application/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);

            var hotelModel =
                new
                {
                    html = string.Empty,
                    grade = 0.0m,
                    name = string.Empty,
                    url = string.Empty,
                    hasImage = false
                };

            var jsonObject = JsonConvert.DeserializeAnonymousType(result.Body.AsString(), hotelModel);

            jsonObject.name.Should().Be(hotel.Name);
            jsonObject.hasImage.Should().BeTrue();
            jsonObject.grade.Should().Be(hotel.Grade);
            jsonObject.html.Should().Be(hotel.Html);
            jsonObject.url.Should().Be(hotel.Url);
        }
        public void ShouldReturnAvailableAirports()
        {
            // Arrange
            var bootstrapper = new TestBootstrapper(with => with.Module<AirportsModule>());

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/airports",
                with =>
                    {
                        with.HttpRequest();
                        with.Accept("application/json");
                    });

            // Asser
            result.StatusCode.Should().Be(HttpStatusCode.OK);

            var jsonObject = new[] { new { Code = string.Empty, Name = string.Empty } };

            jsonObject = JsonConvert.DeserializeAnonymousType(result.Body.AsString(), jsonObject);
            jsonObject.Should().Contain(arg => arg.Name == "Borlänge" && arg.Code == "Borlänge");
        }
        public void ShouldReturnOffersForAirportWithADate()
        {
            // Arrange
            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(
                repository => repository.GetOffers(It.IsAny<string>(), It.IsAny<DateTime>()))
                     .Returns(new[] { new Offer(), new Offer() });

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferSearchModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/offers/from/Borlänge/on/2013-01-01",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("text/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.OK);

            var offers = result.Body.DeserializeJson<Offer[]>();

            offers.Length.Should().Be(2);
        }
        public void ShouldReturnNotFoundForInvalidId()
        {
            // Arrange
            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(repository => repository.GetHotel(It.Is<string>(s => s == "100")))
                     .Returns((Hotel)null);

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferHotelModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/offer/hotel/100",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("application/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
        public void ShouldReturnNotFoundWhenImageSourceIsNotFound()
        {
            // Arrange
            var hotel = new Hotel { ImageUrl = "http://www.fake.com/image.jpg" };

            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(repository => repository.GetHotel(It.IsAny<string>()))
                     .Returns(hotel);

            var response = new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.NotFound };
            var httpClient = new HttpClient(new FakeHandler { Response = response });

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferHotelModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
                with.Dependency<HttpClient>(httpClient);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/offer/hotel/1/image/width/100/height/100",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("application/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
        public void ShouldReturnNotFoundWhenHotelDoesNotExist()
        {
            // Arrange
            var offerRepo = new Mock<ITravelOffersRepository>();
            offerRepo.Setup(repository => repository.GetHotel(It.IsAny<string>()))
                     .Returns(default(Hotel));

            var bootstrapper = new TestBootstrapper(with =>
            {
                with.Module<OfferHotelModule>();
                with.Dependency<ITravelOffersRepository>(offerRepo.Object);
            });

            var browser = new Browser(bootstrapper);

            // Act
            var result = browser.Get(
                "/hotel/1/image/width/100/height/100",
                with =>
                {
                    with.HttpRequest();
                    with.Accept("application/json");
                });

            // Assert
            result.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }