public void EditReading_ReadingObject_EditReadingObject() { // Arrange var previousReading = new Reading(); var reading = new Reading(); reading.Id = 1; // reading.Month = Month.April; reading.PresentReading = 1000; reading.PreviousReading = 500; reading.DayOffset = 2; reading.ReadingTakenDate = DateTime.Today; reading.TenantId = 5; var previousMonth = reading.ReadingTakenDate.Month - 2; var expectedUnitPrice = 300; _billUnitOfWorkMock.Setup(x => x.BillRepository).Returns(_billRepositoryMock.Object); _billUnitOfWorkMock.Setup(x => x.ReadingRepository).Returns(_readingRepositoryMock.Object); _readingRepositoryMock.Setup(x => x.GetById(reading.Id)).Returns(reading).Verifiable(); // _billRepositoryMock.Setup(x => x.GetUnitPrice((Month)previousMonth)).Returns(expectedUnitPrice).Verifiable(); _billUnitOfWorkMock.Setup(x => x.Save()).Verifiable(); // Act _readingService.EditReading(reading); //Assert _billRepositoryMock.VerifyAll(); _readingRepositoryMock.VerifyAll(); _billUnitOfWorkMock.VerifyAll(); }
public void EditReading() { try { _readingService.EditReading(new Reading { Id = this.Id, TenantId = this.TenantId, // Month=this.Month, DayOffset = this.DayOffset, PreviousReading = this.PreviousReading, PresentReading = this.PresentReading, ReadingTakenDate = this.ReadingTakenDate }); Notification = new NotificationModel("Success!", "Reading successfuly updated", NotificationModel.NotificationType.Success); } catch (InvalidOperationException iex) { Notification = new NotificationModel( "Failed!", "Failed to update Reading", NotificationModel.NotificationType.Fail); _logger.LogError(iex.Message); } catch (Exception ex) { Notification = new NotificationModel( "Failed!", "Failed to update reading, please try again", NotificationModel.NotificationType.Fail); _logger.LogError(ex.Message); } }