コード例 #1
0
        public async Task AddReservationAsync_WithCorrectData_ShouldSuccessfullyCreate()
        {
            MapperInitializer.InitializeMapper();
            var errorMessagePrefix    = "ReservationsService  AddReservationAsync() method does not work properly.";
            var context               = HotelDbContextInMemoryFactory.InitializeContext();
            var reservationRepository = new EfDeletableEntityRepository <Reservation>(context);
            var reservationsService   = this.GetReservationService(reservationRepository, context);
            var seeder = new ReservationsServiceTestsSeeder();
            await seeder.SeedDataForAddAsyncMethodAsync(context);

            var reservation = new Reservation
            {
                UserId              = context.Users.First().Id,
                StartDate           = new DateTime(2020, 4, 4),
                EndDate             = new DateTime(2020, 4, 8),
                Adults              = 2,
                Kids                = 1,
                ReservationStatusId = context.ReservationStatuses.First().Id,
                PaymentTypeId       = context.PaymentTypes.First().Id,
                TotalAmount         = 1000,
                PricePerDay         = 250,
                TotalDays           = 4,
                AdvancedPayment     = 300,
                ReservationRooms    = new List <ReservationRoom> {
                    new ReservationRoom {
                        RoomId = context.Rooms.First().Id
                    }
                },
            };

            // Act
            await reservationsService.AddReservationAsync(reservation);

            var actualResult   = reservationRepository.All().First();
            var expectedResult = reservation;

            // Assert
            Assert.True(expectedResult.UserId == actualResult.UserId, errorMessagePrefix + " " + "User is not returned properly.");
            Assert.True(expectedResult.StartDate == actualResult.StartDate, errorMessagePrefix + " " + "Start date is not returned properly.");
            Assert.True(expectedResult.EndDate == actualResult.EndDate, errorMessagePrefix + " " + "End date is not returned properly.");
            Assert.True(expectedResult.Adults == actualResult.Adults, errorMessagePrefix + " " + "Adults is not returned properly.");
            Assert.True(expectedResult.Kids == actualResult.Kids, errorMessagePrefix + " " + "Kids is not returned properly.");
            Assert.True(expectedResult.TotalAmount == actualResult.TotalAmount, errorMessagePrefix + " " + "Total amount is not returned properly.");
            Assert.True(expectedResult.ReservationStatusId == actualResult.ReservationStatusId, errorMessagePrefix + " " + "Reservation status Id is not returned properly.");
            Assert.True(expectedResult.PricePerDay == actualResult.PricePerDay, errorMessagePrefix + " " + "Price per day is not returned properly.");
            Assert.True(expectedResult.AdvancedPayment == actualResult.AdvancedPayment, errorMessagePrefix + " " + "Advanced payment is not returned properly.");
            Assert.True(expectedResult.TotalDays == actualResult.TotalDays, errorMessagePrefix + " " + "Total days is not returned properly.");
            Assert.True(expectedResult.ReservationRooms.First().RoomId == actualResult.ReservationRooms.First().RoomId, errorMessagePrefix + " " + "First room id in ReservationRooms status is not returned properly.");
            Assert.True(expectedResult.PaymentTypeId == actualResult.PaymentTypeId, errorMessagePrefix + " " + "Payment type Id is not returned properly.");
        }
コード例 #2
0
        public async Task AddReservationAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "ReservationsService  AddReservationAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var reservationRepository = new EfDeletableEntityRepository <Reservation>(context);
            var reservationsService   = this.GetReservationService(reservationRepository, context);
            var seeder = new ReservationsServiceTestsSeeder();
            await seeder.SeedDataForAddAsyncMethodAsync(context);

            var reservation = new Reservation
            {
                UserId              = context.Users.First().Id,
                StartDate           = new DateTime(2020, 4, 4),
                EndDate             = new DateTime(2020, 4, 8),
                Adults              = 2,
                Kids                = 1,
                ReservationStatusId = context.ReservationStatuses.First().Id,
                PaymentTypeId       = context.PaymentTypes.First().Id,
                TotalAmount         = 1000,
                PricePerDay         = 250,
                TotalDays           = 4,
                AdvancedPayment     = 300,
                ReservationRooms    = new List <ReservationRoom> {
                    new ReservationRoom {
                        RoomId = context.Rooms.First().Id
                    }
                },
            };

            // Act
            var result = await reservationsService.AddReservationAsync(reservation);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
コード例 #3
0
        public async Task AddReservationAsync_WithIncorrectProperty_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var reservationRepository = new EfDeletableEntityRepository <Reservation>(context);
            var reservationsService   = this.GetReservationService(reservationRepository, context);
            var seeder = new ReservationsServiceTestsSeeder();
            await seeder.SeedDataForAddAsyncMethodAsync(context);

            var reservation = new Reservation
            {
                UserId              = null,
                StartDate           = new DateTime(2020, 4, 4),
                EndDate             = new DateTime(2020, 4, 8),
                Adults              = 2,
                Kids                = 1,
                ReservationStatusId = null,
                PaymentTypeId       = null,
                TotalAmount         = 1000,
                PricePerDay         = 250,
                TotalDays           = 4,
                AdvancedPayment     = 300,
                ReservationRooms    = new List <ReservationRoom> {
                    new ReservationRoom {
                        RoomId = context.Rooms.First().Id
                    }
                },
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await reservationsService.AddReservationAsync(reservation);
            });
        }