Exemplo n.º 1
0
        public async Task AddAsync_WithIncorrectProperty_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var paymentModel = new Payment
            {
                DateOfPayment       = DateTime.Now,
                Amount              = 300,
                PaymentTypeId       = null,
                ReservationPayments = new List <ReservationPayment>
                {
                    new ReservationPayment {
                        ReservationId = context.Reservations.First().Id
                    }
                },
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await paymentsService.AddPaymentAsync(paymentModel);
            });
        }
Exemplo n.º 2
0
        public async Task GetAllPayments_ShouldReturnCorrectResult()
        {
            var errorMessage = "PaymentsService GetAllPayments() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            // Act
            var actualResult   = paymentsService.GetAllPayments().ToList();
            var expectedResult = new Payment[]
            {
                new Payment
                {
                    Id            = paymentRepository.All().First().Id,
                    DateOfPayment = paymentRepository.All().First().DateOfPayment,
                    Amount        = paymentRepository.All().First().Amount,
                    PaymentTypeId = paymentRepository.All().First().PaymentTypeId,
                },
            };

            Assert.True(expectedResult[0].Id == actualResult[0].Id, errorMessage + " " + "Id is not returned properly.");
            Assert.True(expectedResult[0].DateOfPayment == actualResult[0].DateOfPayment, errorMessage + " " + "Date of payment is not returned properly.");
            Assert.True(expectedResult[0].Amount == actualResult[0].Amount, errorMessage + " " + "Amount is not returned properly.");
            Assert.True(expectedResult[0].PaymentTypeId == actualResult[0].PaymentTypeId, errorMessage + " " + "payment type id is not returned properly.");
        }
Exemplo n.º 3
0
        public async Task GetAllPayments_ShouldReturnCorrectCount()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            // Act
            var actualResult   = paymentsService.GetAllPayments().ToList();
            var expectedResult = new Payment[]
            {
                new Payment
                {
                    Id            = paymentRepository.All().First().Id,
                    DateOfPayment = paymentRepository.All().First().DateOfPayment,
                    Amount        = paymentRepository.All().First().Amount,
                    PaymentTypeId = paymentRepository.All().First().PaymentTypeId,
                },
            };

            Assert.Equal(expectedResult.Length, actualResult.Count());
        }
Exemplo n.º 4
0
        public async Task GetPaymentByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMessage = "PaymentsService GetPaymentByIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var paymentId = paymentRepository.All().First().Id;

            // Act
            var actualResult = await paymentsService.GetPaymentByIdAsync(paymentId);

            var expectedResult = await paymentRepository
                                 .All()
                                 .SingleOrDefaultAsync(x => x.Id == paymentId);

            // Assert
            Assert.True(expectedResult.DateOfPayment == actualResult.DateOfPayment, errorMessage + " " + "Date of payment is not returned properly.");
            Assert.True(expectedResult.Amount == actualResult.Amount, errorMessage + " " + "Amount is not returned properly.");
            Assert.True(expectedResult.PaymentTypeId == actualResult.PaymentTypeId, errorMessage + " " + "payment type id is not returned properly.");
        }
Exemplo n.º 5
0
        public async Task CreateAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "PaymentsService AddPaymentAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var paymentModel = new Payment
            {
                DateOfPayment       = DateTime.Now,
                Amount              = 300,
                PaymentTypeId       = context.PaymentTypes.First().Id,
                ReservationPayments = new List <ReservationPayment>
                {
                    new ReservationPayment {
                        ReservationId = context.Reservations.First().Id
                    }
                },
            };

            // Act
            var result = await paymentsService.AddPaymentAsync(paymentModel);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
Exemplo n.º 6
0
        public async Task EditAsync_WithNonExistentId_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context           = HotelDbContextInMemoryFactory.InitializeContext();
            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);
            var seeder            = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var nonExistentId = Guid.NewGuid().ToString();

            var model = new EditPaymentViewModel
            {
                Id                  = nonExistentId,
                DateOfPayment       = DateTime.Now.Date,
                Amount              = 300,
                PaymentTypeId       = context.PaymentTypes.First().Id,
                ReservationPayments = new List <ReservationPayment>
                {
                    new ReservationPayment {
                        ReservationId = context.Reservations.First().Id
                    }
                },
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await paymentsService.EditAsync(model);
            });
        }
Exemplo n.º 7
0
        public async Task GetAllPaymentsForReservation_ShouldReturnCorrectCount()
        {
            // Arrange
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var reservation = context.Reservations.First();

            // Act
            var actualResult   = paymentsService.GetAllPaymentsForReservation(reservation.Id).ToList();
            var expectedResult = 1;

            Assert.Equal(expectedResult, actualResult.Count());
        }
Exemplo n.º 8
0
        public async Task GetAllPaymentsForReservation_ShouldReturnCorrectResult()
        {
            var errorMessage = "PaymentsService GetAllPaymentsForReservation() method does not work properly.";

            // Arrange
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var reservation = context.Reservations.First();

            // Act
            var actualResult   = paymentsService.GetAllPaymentsForReservation(reservation.Id).ToList();
            var expectedResult = new string[] { paymentRepository.All().First().ReservationPayments.First().PaymentId };

            Assert.True(expectedResult[0] == actualResult[0], errorMessage + " " + "Id is not returned properly.");
        }
Exemplo n.º 9
0
        public async Task GetAllPaymentsCountAsync_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "PaymentsService GetAllPaymentsCountAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            // Act
            var actualResult = await paymentsService.GetAllPaymentsCountAsync();

            var expectedResult = paymentRepository.All().Count();

            // Assert
            Assert.True(actualResult == expectedResult, errorMessagePrefix + " " + "RoomTypesService GetAllRoomTypesCountAsync() method does not work properly.");
        }
Exemplo n.º 10
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            var errorMessage = "PaymentsService EditAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var payment = context.Payments.First();

            var model = new EditPaymentViewModel
            {
                Id                  = payment.Id,
                DateOfPayment       = DateTime.Now.Date,
                Amount              = 300,
                PaymentTypeId       = context.PaymentTypes.First().Id,
                ReservationPayments = new List <ReservationPayment>
                {
                    new ReservationPayment {
                        ReservationId = context.Reservations.First().Id
                    }
                },
            };

            // Act
            await paymentsService.EditAsync(model);

            var actualResult   = paymentRepository.All().First();
            var expectedResult = model;

            // Assert
            Assert.True(expectedResult.DateOfPayment == actualResult.DateOfPayment, errorMessage + " " + "Date of payment is not returned properly.");
            Assert.True(expectedResult.Amount == actualResult.Amount, errorMessage + " " + "Amount is not returned properly.");
            Assert.True(expectedResult.PaymentTypeId == actualResult.PaymentTypeId, errorMessage + " " + "payment type id is not returned properly.");
        }