Esempio n. 1
0
        public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "PaymentTypesService EditAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var paymentTypeRepository = new EfDeletableEntityRepository <PaymentType>(context);
            var paymentTypesService   = this.GetPaymentTypesService(paymentTypeRepository);
            var seeder = new PaymentTypesServiceTestsSeeder();
            await seeder.SeedPaymentTypeAsync(context);

            var paymentType = context.PaymentTypes.First();

            var model = new EditPaymentTypeViewModel
            {
                Id   = paymentType.Id,
                Name = "Test-1-Edited",
            };

            // Act
            var result = await paymentTypesService.EditAsync(model);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
Esempio n. 2
0
        public async Task GetViewModelByIdAsync_WithExistentId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "PaymentTypesService GetViewModelByIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var paymentTypeRepository = new EfDeletableEntityRepository <PaymentType>(context);
            var paymentTypesService   = this.GetPaymentTypesService(paymentTypeRepository);
            var seeder = new PaymentTypesServiceTestsSeeder();
            await seeder.SeedPaymentTypesAsync(context);

            var paymentTypeId = paymentTypeRepository.All().First().Id;

            // Act
            var actualResult = await paymentTypesService.GetViewModelByIdAsync <EditPaymentTypeViewModel>(paymentTypeId);

            var expectedResult = new EditPaymentTypeViewModel
            {
                Id   = paymentTypeId,
                Name = paymentTypeRepository.All().First().Name,
            };

            // Assert
            Assert.True(expectedResult.Id == actualResult.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly.");
        }
Esempio n. 3
0
        public async Task EditAsync_WithIncorrectProperty_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var paymentTypeRepository = new EfDeletableEntityRepository <PaymentType>(context);
            var paymentTypesService   = this.GetPaymentTypesService(paymentTypeRepository);
            var seeder = new PaymentTypesServiceTestsSeeder();
            await seeder.SeedPaymentTypeAsync(context);

            var paymentType = context.PaymentTypes.First();

            var model = new EditPaymentTypeViewModel
            {
                Id   = paymentType.Id,
                Name = null,
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await paymentTypesService.EditAsync(model);
            });
        }
        public async Task <bool> EditAsync(EditPaymentTypeViewModel paymentTypeEditViewModel)
        {
            var paymentType = this.paymentTypesRepository.All().FirstOrDefault(r => r.Id == paymentTypeEditViewModel.Id);

            if (paymentType == null)
            {
                throw new ArgumentNullException(string.Format(string.Format(ServicesDataConstants.InvalidPaymentTypeIdErrorMessage, paymentTypeEditViewModel.Id)));
            }

            if (paymentTypeEditViewModel.Name == null)
            {
                throw new ArgumentNullException(string.Format(ServicesDataConstants.InvalidPropertyNameErrorMessage));
            }

            paymentType.Name = paymentTypeEditViewModel.Name;

            this.paymentTypesRepository.Update(paymentType);

            var result = await this.paymentTypesRepository.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 5
0
        public async Task <ActionResult> EditPaymentType(EditPaymentTypeViewModel viewModel)
        {
            var project = await ProjectRepository.GetProjectAsync(viewModel.ProjectId);

            var paymentType = project.PaymentTypes.SingleOrDefault(pt => pt.PaymentTypeId == viewModel.PaymentTypeId);

            if (paymentType == null)
            {
                return(HttpNotFound());
            }

            try
            {
                await FinanceService.EditCustomPaymentType(viewModel.ProjectId, viewModel.PaymentTypeId, viewModel.Name, viewModel.IsDefault);

                return(RedirectToAction("Setup", new { viewModel.ProjectId }));
            }
            catch (Exception exc)
            {
                ModelState.AddException(exc);
                return(View(viewModel));
            }
        }
Esempio n. 6
0
        public async Task <ActionResult> EditPaymentType(EditPaymentTypeViewModel viewModel)
        {
            var project = await ProjectRepository.GetProjectAsync(viewModel.ProjectId);

            var paymentType = project.PaymentTypes.SingleOrDefault(pt => pt.PaymentTypeId == viewModel.PaymentTypeId);
            var errorResult = AsMaster(paymentType, acl => acl.CanManageMoney);

            if (errorResult != null)
            {
                return(errorResult);
            }

            try
            {
                await FinanceService.EditCustomPaymentType(viewModel.ProjectId, CurrentUserId, viewModel.PaymentTypeId, viewModel.Name, viewModel.IsDefault);

                return(RedirectToAction("Setup", new { viewModel.ProjectId }));
            }
            catch (Exception exc)
            {
                ModelState.AddException(exc);
                return(View(viewModel));
            }
        }
Esempio n. 7
0
        public async Task EditAsync_WithNonExistentId_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var paymentTypeRepository = new EfDeletableEntityRepository <PaymentType>(context);
            var paymentTypesService   = this.GetPaymentTypesService(paymentTypeRepository);

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

            var model = new EditPaymentTypeViewModel
            {
                Id   = nonExistentId,
                Name = "Test-1-Edited",
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await paymentTypesService.EditAsync(model);
            });
        }