public ActionResult Edit(EditPaymentViewModel model) { var businessManager = businessManagerContainer.Get <PaymentBusinessManager>(); var id = businessManager.Update(model.Id, model); return(RedirectToAction("Details", new { id })); }
public async Task <bool> EditAsync(EditPaymentViewModel paymentEditViewModel) { var payment = this.paymentRepository.All().FirstOrDefault(p => p.Id == paymentEditViewModel.Id); if (payment == null) { throw new ArgumentNullException(string.Format(string.Format(ServicesDataConstants.InvalidPaymentIdErrorMessage, paymentEditViewModel.Id))); } if (paymentEditViewModel.DateOfPayment == null || paymentEditViewModel.PaymentTypeId == null || paymentEditViewModel.ReservationPayments.Count == 0) { throw new ArgumentNullException(string.Format(ServicesDataConstants.InvalidPropertyErrorMessage)); } payment.DateOfPayment = paymentEditViewModel.DateOfPayment; payment.PaymentTypeId = paymentEditViewModel.PaymentTypeId; payment.Amount = paymentEditViewModel.Amount; this.paymentRepository.Update(payment); var result = await this.paymentRepository.SaveChangesAsync(); return(result > 0); }
public async Task AmountCorrectlyFormattedOnSave(string cultureString, string amountString, decimal expectedAmount) { // Arrange var cultureInfo = new CultureInfo(cultureString); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; var editPaymentVm = new EditPaymentViewModel(mediatorMock.Object, mapper, dialogServiceMock.Object, settingsFacadeMock.Object, backupServiceMock.Object, navigationServiceMock.Object); await editPaymentVm.InitializeCommand.ExecuteAsync(); editPaymentVm.SelectedPayment.ChargedAccount = new AccountViewModel { Name = "asdf" }; // Act editPaymentVm.AmountString = amountString; await editPaymentVm.SaveCommand.ExecuteAsync(); // Assert editPaymentVm.SelectedPayment.Amount.ShouldEqual(expectedAmount); }
public async Task Initialize_RecurringPayment_EndDateCorrect() { // Arrange const int paymentId = 99; var endDate = DateTime.Today.AddDays(-7); crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = false, EndDate = endDate } }); var editPaymentVm = new EditPaymentViewModel(null, crudServiceMock.Object, null, null, null, null); // Act editPaymentVm.PaymentId = paymentId; await editPaymentVm.InitializeCommand.ExecuteAsync(); // Assert editPaymentVm.SelectedPayment.RecurringPayment.IsEndless.ShouldBeFalse(); editPaymentVm.SelectedPayment.RecurringPayment.EndDate.ShouldEqual(endDate); }
public async Task GetViewModelByIdAsync_WithExistentId_ShouldReturnCorrectResult() { var errorMessage = "PaymentsService GetViewModelByIdAsync() 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.GetViewModelByIdAsync <EditPaymentViewModel>(paymentId); var expectedResult = new EditPaymentViewModel { Id = paymentId, DateOfPayment = paymentRepository.All().First().DateOfPayment, Amount = paymentRepository.All().First().Amount, PaymentTypeId = paymentRepository.All().First().PaymentTypeId, }; // Assert Assert.True(expectedResult.Id == actualResult.Id, errorMessage + " " + "Id is not returned properly."); 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."); }
public async Task GetAllPaymentsViewModels_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 <EditPaymentViewModel>().ToList(); var expectedResult = new EditPaymentViewModel[] { new EditPaymentViewModel { 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()); }
public async Task EditAsync_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 payment = context.Payments.First(); var model = new EditPaymentViewModel { Id = payment.Id, DateOfPayment = DateTime.Now.Date, Amount = 300, PaymentTypeId = null, ReservationPayments = null, }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await paymentsService.EditAsync(model); }); }
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); }); }
public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult() { 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 var result = await paymentsService.EditAsync(model); // Assert Assert.True(result, errorMessage + " " + "Returns false."); }
public async Task Initialize_EndlessRecurringPayment_EndDateNotNull() { // Arrange const int paymentId = 99; crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editPaymentVm = new EditPaymentViewModel(null, crudServiceMock.Object, null, null, null, null); // Act editPaymentVm.PaymentId = paymentId; await editPaymentVm.InitializeCommand.ExecuteAsync(); // Assert editPaymentVm.SelectedPayment.RecurringPayment.IsEndless.ShouldBeTrue(); editPaymentVm.SelectedPayment.RecurringPayment.EndDate.HasValue.ShouldBeTrue(); }
public void Prepare_RecurringPayment_EndDateCorrect() { // Arrange const int paymentId = 99; var endDate = DateTime.Today.AddDays(-7); crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = false, EndDate = endDate } }); var editAccountVm = new EditPaymentViewModel(null, crudServiceMock.Object, null, null, new Mock <IMvxMessenger>().Object, null, null, null); // Act editAccountVm.Prepare(new ModifyPaymentParameter(paymentId)); // Assert editAccountVm.SelectedPayment.RecurringPayment.IsEndless.ShouldBeFalse(); editAccountVm.SelectedPayment.RecurringPayment.EndDate.ShouldEqual(endDate); }
public ActionResult EditPayments() { var modelo = new EditPaymentViewModel(); modelo.RegionList = LocationService.GetAllRegions().ToSelectList(r => r.Region1, r => r.RegionId.ToString(), null, "Seleccionar"); modelo.ClinicList = LocationService.GetAllClinics().ToSelectList(c => string.Format("{0} [{1}]", c.Clinic1, c.RegionId), c => c.ClinicId.ToString(), null, "Seleccionar"); modelo.CityList = LocationService.GetAllCities().ToSelectList(c => string.Format("{0} [{1}]", c.City1, c.StateId), c => c.CityId.ToString(), null, "Seleccionar"); modelo.CourtList = GetAllCourts().ToList(); modelo.PaymentStatus = PaymentService.GetAllPaymentStatuses().ToSelectList(p => p.Status1, p => p.StatusId.ToString(), null, "Seleccionar"); return(View(modelo)); }
public async Task AmountStringSetOnInit() { // Arrange mediatorMock.Setup(x => x.Send(It.IsAny<GetPaymentByIdQuery>(), default)) .ReturnsAsync(new Payment(DateTime.Now, 12.10M, PaymentType.Expense, new Account("sad"))); var editPaymentVm = new EditPaymentViewModel(mediatorMock.Object, mapper, dialogServiceMock.Object, navigationServiceMock.Object); // Act await editPaymentVm.InitializeCommand.ExecuteAsync(); // Assert editPaymentVm.AmountString.ShouldEqual("12.10"); }
public async Task ShowNoMessageIfAmountIsPositiveOnSave(string amountString) { // Arrange var editPaymentVm = new EditPaymentViewModel(mediatorMock.Object, mapper, dialogServiceMock.Object, navigationServiceMock.Object); await editPaymentVm.InitializeCommand.ExecuteAsync(); editPaymentVm.AmountString = amountString; // Act await editPaymentVm.SaveCommand.ExecuteAsync(); // Assert dialogServiceMock.Verify(x => x.ShowMessageAsync(Strings.AmountMayNotBeNegativeTitle, Strings.AmountMayNotBeNegativeMessage), Times.Never); }
public async Task SavePayment_ResultSucceededWithBackup_CorrectMethodCalls() { // Arrange const int paymentId = 99; paymentServiceMock.Setup(x => x.UpdatePayment(It.IsAny <PaymentViewModel>())) .Returns(Task.CompletedTask); settingsFacadeMock.SetupGet(x => x.IsBackupAutouploadEnabled).Returns(true); crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editPaymentVm = new EditPaymentViewModel(paymentServiceMock.Object, crudServiceMock.Object, dialogServiceMock.Object, settingsFacadeMock.Object, backupServiceMock.Object, navigationServiceMock.Object); editPaymentVm.PaymentId = paymentId; await editPaymentVm.InitializeCommand.ExecuteAsync(); editPaymentVm.SelectedPayment.ChargedAccount = new AccountViewModel(); // Act await editPaymentVm.SaveCommand.ExecuteAsync(); // Assert paymentServiceMock.Verify(x => x.UpdatePayment(It.IsAny <PaymentViewModel>()), Times.Once); dialogServiceMock.Verify(x => x.ShowMessage(It.IsAny <string>(), It.IsAny <string>()), Times.Never); navigationServiceMock.Verify(x => x.GoBack(), Times.Once); settingsFacadeMock.VerifySet(x => x.LastExecutionTimeStampSyncBackup = It.IsAny <DateTime>(), Times.Once); backupServiceMock.Verify(x => x.EnqueueBackupTask(0), Times.Once); }
public void SavePayment_ResultFailed_CorrectMethodCalls() { // Arrange const int paymentId = 99; paymentServiceMock.Setup(x => x.UpdatePayment(It.IsAny <PaymentViewModel>())) .ReturnsAsync(OperationResult.Failed("")); crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editPaymentVm = new EditPaymentViewModel(paymentServiceMock.Object, crudServiceMock.Object, dialogServiceMock.Object, settingsFacadeMock.Object, new Mock <IMvxMessenger>().Object, backupServiceMock.Object, new Mock <IMvxLogProvider>().Object, navigationServiceMock.Object); editPaymentVm.Prepare(new ModifyPaymentParameter(paymentId)); editPaymentVm.SelectedPayment.ChargedAccount = new AccountViewModel(); // Act editPaymentVm.SaveCommand.Execute(); // Assert paymentServiceMock.Verify(x => x.UpdatePayment(It.IsAny <PaymentViewModel>()), Times.Once); dialogServiceMock.Verify(x => x.ShowMessage(It.IsAny <string>(), It.IsAny <string>()), Times.Once); navigationServiceMock.Verify(x => x.Close(It.IsAny <MvxViewModel>(), CancellationToken.None), Times.Never); settingsFacadeMock.VerifySet(x => x.LastExecutionTimeStampSyncBackup = It.IsAny <DateTime>(), Times.Once); backupServiceMock.Verify(x => x.EnqueueBackupTask(0), Times.Once); }
public async Task SavePayment_ResultFailedWithBackup_CorrectMethodCalls() { // Arrange const int paymentId = 99; paymentServiceMock.Setup(x => x.UpdatePayment(It.IsAny <PaymentViewModel>())) .Callback(() => throw new Exception()); settingsFacadeMock.SetupGet(x => x.IsBackupAutouploadEnabled).Returns(true); crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editPaymentVm = new EditPaymentViewModel(paymentServiceMock.Object, crudServiceMock.Object, dialogServiceMock.Object, settingsFacadeMock.Object, backupServiceMock.Object, navigationServiceMock.Object); editPaymentVm.PaymentId = paymentId; await editPaymentVm.InitializeCommand.ExecuteAsync(); editPaymentVm.SelectedPayment.ChargedAccount = new AccountViewModel(); // Act await Assert.ThrowsAsync <Exception>(async() => await editPaymentVm.SaveCommand.ExecuteAsync()); // Assert paymentServiceMock.Verify(x => x.UpdatePayment(It.IsAny <PaymentViewModel>()), Times.Once); navigationServiceMock.Verify(x => x.GoBack(), Times.Never); }
public void SavePayment_NoAccount_DialogShown() { // Arrange const int paymentId = 99; crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editPaymentVm = new EditPaymentViewModel(paymentServiceMock.Object, crudServiceMock.Object, dialogServiceMock.Object, settingsFacadeMock.Object, new Mock <IMvxMessenger>().Object, backupServiceMock.Object, new Mock <IMvxLogProvider>().Object, navigationServiceMock.Object); editPaymentVm.Prepare(new ModifyPaymentParameter(paymentId)); // Act editPaymentVm.SaveCommand.Execute(); // Assert paymentServiceMock.Verify(x => x.UpdatePayment(It.IsAny <PaymentViewModel>()), Times.Never); dialogServiceMock.Verify(x => x.ShowMessage(Strings.MandatoryFieldEmptyTitle, Strings.AccountRequiredMessage), Times.Once); navigationServiceMock.Verify(x => x.Close(It.IsAny <MvxViewModel>(), CancellationToken.None), Times.Never); settingsFacadeMock.VerifySet(x => x.LastExecutionTimeStampSyncBackup = It.IsAny <DateTime>(), Times.Never); backupServiceMock.Verify(x => x.EnqueueBackupTask(0), Times.Never); }
public void Prepare_EndlessRecurringPayment_EndDateNotNull() { // Arrange const int paymentId = 99; crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editAccountVm = new EditPaymentViewModel(null, crudServiceMock.Object, null, null, new Mock <IMvxMessenger>().Object, null, null, null); // Act editAccountVm.Prepare(new ModifyPaymentParameter(paymentId)); // Assert editAccountVm.SelectedPayment.RecurringPayment.IsEndless.ShouldBeTrue(); editAccountVm.SelectedPayment.RecurringPayment.EndDate.HasValue.ShouldBeTrue(); }
public async Task ShowMessageIfAmountIsNegativeOnSave() { // Arrange var editPaymentVm = new EditPaymentViewModel(mediatorMock.Object, mapper, dialogServiceMock.Object, settingsFacadeMock.Object, backupServiceMock.Object, navigationServiceMock.Object); await editPaymentVm.InitializeCommand.ExecuteAsync(); editPaymentVm.AmountString = "-2"; // Act await editPaymentVm.SaveCommand.ExecuteAsync(); // Assert dialogServiceMock.Verify(x => x.ShowMessageAsync(Strings.AmountMayNotBeNegativeTitle, Strings.AmountMayNotBeNegativeMessage), Times.Once); navigationServiceMock.Verify(x => x.GoBack(), Times.Never); settingsFacadeMock.VerifySet(x => x.LastExecutionTimeStampSyncBackup = It.IsAny <DateTime>(), Times.Never); backupServiceMock.Verify(x => x.UploadBackupAsync(BackupMode.Manual), Times.Never); }
public async Task SavePayment_NoAccount_DialogShown() { // Arrange const int paymentId = 99; crudServiceMock.Setup(x => x.ReadSingleAsync <PaymentViewModel>(It.IsAny <int>())) .ReturnsAsync(new PaymentViewModel { IsRecurring = true, RecurringPayment = new RecurringPaymentViewModel { IsEndless = true, EndDate = null } }); var editPaymentVm = new EditPaymentViewModel(paymentServiceMock.Object, crudServiceMock.Object, dialogServiceMock.Object, settingsFacadeMock.Object, backupServiceMock.Object, navigationServiceMock.Object); editPaymentVm.PaymentId = paymentId; await editPaymentVm.InitializeCommand.ExecuteAsync(); // Act await editPaymentVm.SaveCommand.ExecuteAsync(); // Assert paymentServiceMock.Verify(x => x.UpdatePayment(It.IsAny <PaymentViewModel>()), Times.Never); dialogServiceMock.Verify(x => x.ShowMessage(Strings.MandatoryFieldEmptyTitle, Strings.AccountRequiredMessage), Times.Once); navigationServiceMock.Verify(x => x.GoBack(), Times.Never); settingsFacadeMock.VerifySet(x => x.LastExecutionTimeStampSyncBackup = It.IsAny <DateTime>(), Times.Never); backupServiceMock.Verify(x => x.EnqueueBackupTask(0), Times.Never); }