Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            // Build the WRITE side (we use a bus for it) ----------
            var bus = new FakeBus();
            var bookingRepository = new BookingAndClientsRepository();

            var bookingHandler = CompositionRootHelper.BuildTheWriteModelHexagon(bookingRepository, bookingRepository, bus, bus);

            // TODO: register handlers for the query part coming from the bus?

            // Build the READ side ---------------------------------
            var hotelsAdapter = new HotelsAndRoomsAdapter($"{env.WebRootPath}/hotels/", bus);

            hotelsAdapter.LoadAllHotelsFiles();

            var readFacade = CompositionRootHelper.BuildTheReadModelHexagon(hotelsAdapter, hotelsAdapter, null, bus);

            // Registers all services to the MVC IoC framework
            services.AddSingleton <ISendCommands>(bus);
            services.AddSingleton <IQueryBookingOptions>(readFacade);
            services.AddSingleton <IProvideHotel>(readFacade);
            services.AddSingleton <IProvideReservations>(readFacade);


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Build the WRITE side (we use a bus for it) ----------
            var bus = new FakeBus();
            var bookingRepository = new BookingAndClientsRepository();

            var bookingHandler = CompositionRootHelper.BuildTheWriteModelHexagon(bookingRepository, bookingRepository, bus, bus);

            // TODO: register handlers for the query part coming from the bus?

            // Build the READ side ---------------------------------
            var hotelsAdapter = new HotelsAndRoomsAdapter($"{env.WebRootPath}/hotels/", bus);

            hotelsAdapter.LoadAllHotelsFiles();

            var readFacade = CompositionRootHelper.BuildTheReadModelHexagon(hotelsAdapter, hotelsAdapter, null, bus);

            // Registers all services to the MVC IoC framework
            services.AddSingleton <ISendCommands>(bus);
            services.AddSingleton <IQueryBookingOptions>(readFacade);
            services.AddSingleton <IProvideHotel>(readFacade);
            services.AddSingleton <IProvideReservations>(readFacade);

            // Add framework services.
            services.AddMvc();
        }
Beispiel #3
0
        public void Should_impact_both_write_and_read_models_when_sending_a_booking_command()
        {
            // Initialize Read-model side
            var bus                 = new FakeBus(synchronousPublication: true);
            var hotelsAdapter       = new HotelsAndRoomsAdapter(Constants.RelativePathForHotelIntegrationFiles, bus);
            var reservationsAdapter = new ReservationAdapter(bus);

            hotelsAdapter.LoadHotelFile("New York Sofitel-availabilities.json");

            var readFacade = CompositionRootHelper.BuildTheReadModelHexagon(hotelsAdapter, hotelsAdapter, reservationsAdapter, bus);

            // Search Rooms availabilities
            var checkInDate  = Constants.MyFavoriteSaturdayIn2017;
            var checkOutDate = checkInDate.AddDays(1);

            var searchQuery    = new SearchBookingOptions(checkInDate, checkOutDate, location: "New York", numberOfAdults: 2);
            var bookingOptions = readFacade.SearchBookingOptions(searchQuery);

            // We should get 1 booking option with 13 available rooms in it.
            Check.That(bookingOptions).HasSize(1);

            var bookingOption       = bookingOptions.First();
            var initialRoomsNumbers = 13;

            Check.That(bookingOption.AvailableRoomsWithPrices).HasSize(initialRoomsNumbers);

            // Now, let's book that room!
            var firstRoomOfThisBookingOption = bookingOption.AvailableRoomsWithPrices.First();
            var bookingCommand = new BookingCommand(clientId: "*****@*****.**", hotelName: "New York Sofitel", hotelId: bookingOption.Hotel.Identifier, roomNumber: firstRoomOfThisBookingOption.RoomIdentifier, checkInDate: checkInDate, checkOutDate: checkOutDate);

            // Initialize Write-model side
            var bookingRepository = new BookingAndClientsRepository();

            CompositionRootHelper.BuildTheWriteModelHexagon(bookingRepository, bookingRepository, bus, bus);

            // We send the BookARoom command
            bus.Send(bookingCommand);

            // We check that both the BookingRepository (Write model) and the available rooms (Read model) have been updated.
            Check.That(bookingRepository.GetBookingsFrom("*****@*****.**").Count()).IsEqualTo(1);

            // Fetch rooms availabilities now. One room should have disappeared from the search result
            bookingOptions = readFacade.SearchBookingOptions(searchQuery);
            Check.That(bookingOptions).HasSize(1);
            Check.That(bookingOption.AvailableRoomsWithPrices).As("available matching rooms").HasSize(initialRoomsNumbers - 1);
        }
Beispiel #4
0
        public void Should_retrieve_updated_list_of_reservations()
        {
            var bus     = new FakeBus();
            var adapter = new HotelsAndRoomsAdapter(Constants.RelativePathForHotelIntegrationFiles, bus);

            adapter.LoadHotelFile("New York Sofitel-availabilities.json");
            var reservationAdapter = new ReservationAdapter(bus);
            var readFacade         = CompositionRootHelper.BuildTheReadModelHexagon(adapter, adapter, reservationAdapter, bus);

            var clientId = "*****@*****.**";
            IEnumerable <Reservation> reservations = readFacade.GetReservationsFor(clientId);

            Check.That(reservations).IsEmpty();

            var bookingAndClientsRepository = new BookingAndClientsRepository();

            CompositionRootHelper.BuildTheWriteModelHexagon(bookingAndClientsRepository, bookingAndClientsRepository, bus, bus);

            var hotelId      = 1;
            var hotelName    = "New York Sofitel";
            var roomNumber   = "101";
            var checkInDate  = Constants.MyFavoriteSaturdayIn2017;
            var checkOutDate = checkInDate.AddDays(1);

            bus.Send(new BookingCommand(clientId, hotelName, hotelId, roomNumber, checkInDate, checkOutDate));

            reservations = readFacade.GetReservationsFor(clientId);
            Check.That(reservations).HasSize(1);
            var reservation = reservations.First();

            Check.That(reservation.ClientId).IsEqualTo(clientId);
            Check.That(reservation.HotelId).IsEqualTo(hotelId.ToString()); // TODO: make the hotelId a string and not an int.
            Check.That(reservation.RoomNumber).IsEqualTo(roomNumber);
            Check.That(reservation.CheckInDate).IsEqualTo(checkInDate);
            Check.That(reservation.CheckOutDate).IsEqualTo(checkOutDate);
        }