public void Update_FromDate() { // Arrange var helper = new TestHelper(); var user = PrincipalHelper.CreateForPermission(Permissions.ReportsSpl); var init = helper.InitializeDatabase(user); init.CreateDefaultWorkflowsWithStatus(); init.SaveChanges(); var project = init.CreateProject(1); var oldReport = init.CreateProjectReport(1, agency: project.Agency); var projectReport = init.CreateProjectReport(2, agency: project.Agency); var snapshot = init.CreateProjectSnapshot(1, agency: project.Agency); init.SetStatus(project, "SPL", "AP-SPL"); oldReport.IsFinal = true; oldReport.To = DateTime.UtcNow; snapshot.SnapshotOn = oldReport.To.Value; var metadata = new DisposalProjectSnapshotMetadata() { NetProceeds = 100 }; snapshot.Metadata = JsonSerializer.Serialize(metadata); snapshot.Project = project; projectReport.To = DateTime.UtcNow.AddDays(1); init.SaveChanges(); var options = ControllerHelper.CreateDefaultPimsOptions(); var service = helper.CreateService <ProjectReportService>(user, options); // Act var reportToUpdate = EntityHelper.CreateProjectReport(projectReport.Id, toDate: DateTime.UtcNow.AddDays(2)); reportToUpdate.From = oldReport.To; var result = service.Update(reportToUpdate); var snapshots = service.GetSnapshots(result.Id); // Assert Assert.NotNull(result); Assert.True(result.Id > 0); Assert.NotEmpty(snapshots); JsonSerializer.Deserialize <DisposalProjectSnapshotMetadata>(snapshots.First().Metadata).BaselineIntegrity.Should().Be(-100); }
public void Add_ProjectReport_FromDate() { // Arrange var helper = new TestHelper(); var user = PrincipalHelper.CreateForPermission(Permissions.ReportsSpl); DateTime fromDate = DateTime.UtcNow; var init = helper.InitializeDatabase(user); init.CreateDefaultWorkflowsWithStatus(); init.SaveChanges(); var project = init.CreateProject(1); var snapshot = init.CreateProjectSnapshot(1, agency: project.Agency); init.SetStatus(project, "SPL", "AP-SPL"); snapshot.SnapshotOn = fromDate; snapshot.Project = project; var metadata = new DisposalProjectSnapshotMetadata() { NetProceeds = 100 }; snapshot.Metadata = JsonSerializer.Serialize(metadata); init.SaveChanges(); var projectReport = EntityHelper.CreateProjectReport(1, fromDate: fromDate, agency: project.Agency); var options = ControllerHelper.CreateDefaultPimsOptions(); var service = helper.CreateService <ProjectReportService>(user, options); // Act var result = service.Add(projectReport); var snapshots = service.GetSnapshots(result.Id); // Assert Assert.NotNull(result); Assert.Equal(fromDate, result.From); Assert.True(result.Id > 0); JsonSerializer.Deserialize <DisposalProjectSnapshotMetadata>(snapshots.First().Metadata).BaselineIntegrity.Should().Be(-100); }