public async Task <Guid> AddAsync(SummaryDocument doc) { var existing = await TryGetSummaryEntityForInspectionAsync(doc.InspectionId); if (existing != null) { throw ItemAlreadyExistsException.MatchingEntityExists("RusHydroPsaSummary", existing.Id); } if (doc.Id == Guid.Empty) { doc.Id = Guid.NewGuid(); } var shiftAbsIndex = WorkingShiftAbsoluteIndex.GetAbsoluteIndex(doc.CompletionTime.LocalDateTime); var deptReportId = DepartmentShiftReportIdBuilder.BuildReportId(doc.DepartmentId, shiftAbsIndex); var summary = new Summary { Id = doc.Id, DepartmentShiftReportId = deptReportId, ShiftAbsoluteIndex = shiftAbsIndex, BranchOfficeId = doc.BranchOfficeId, CompletionTime = doc.CompletionTime, DepartmentId = doc.DepartmentId, EmployeeId = doc.Employee.Id, InspectionId = doc.InspectionId, SummaryDocument = doc, TenantId = _tenantIdProvider.GetTenantId(), UpdateDate = doc.UpdateDate }; _psaSummaryRepository.Add(summary); await _psaSummaryRepository.SaveChangesAsync(); return(summary.Id); }
public void WriteReport_AlreadyExists_OverwriteDisallowed() { ItemAlreadyExistsException ex = Assert.Throws <ItemAlreadyExistsException>( delegate { writer.WriteReport(reportItem_AlreadyExists); }); Assert.That(ex.Message, Is.EqualTo(string.Format("An item at '{0}' already exists.", reportItem_AlreadyExists.Path))); }
public void WriteDataSource_AlreadyExists_OverwriteDisallow() { ItemAlreadyExistsException ex = Assert.Throws <ItemAlreadyExistsException>( delegate { writer.WriteDataSource(alreadyExistsDataSourceItem); }); Assert.That(ex.Message, Is.EqualTo(string.Format("An item at '{0}' already exists.", alreadyExistsDataSourceItem.Path))); }
public void testAlreadyExistentValue() { ItemAlreadyExistsException exception = Assert.Throws <ItemAlreadyExistsException>(delegate() { Bag <object> bag = new Bag <object>(); bag.Add("Existent Item", "ItemValue 1"); bag.Add("Existent Item", "ItemValue 2"); }); Assert.AreEqual("Item \"Existent Item\" already exists in \"unnamed\" bag", exception.Message); }
public void WriteFolder_AlreadyExists() { ItemAlreadyExistsException ex = Assert.Throws <ItemAlreadyExistsException>( delegate { writer.WriteFolder(alreadyExistsFolderItem); }); Assert.That(ex.Message, Is.EqualTo(string.Format("An item at '{0}' already exists.", alreadyExistsFolderItem.Path))); }
public void Store_AddItemWithSameNameTwice_ByOpener_ShouldFail() { LoginSessionSuccess(REGISTERED_SESSION_ID, FIRST_OPENER_USERNAME); Item item = AddOneItemTo_FIRST_STORE_LegalUserForOp(REGISTERED_SESSION_ID); string jsonAnswer = AddItemError(REGISTERED_SESSION_ID, FIRST_STORE_ID, "newitem", 33, JsonConvert.SerializeObject(stringCategories1), 20.55); ItemAlreadyExistsException e = JsonConvert.DeserializeObject <ItemAlreadyExistsException>(jsonAnswer); Assert.AreEqual("Item with name newitem already exists", e.Message); }
protected override async Task CheckNewItemIsUnique(Inspection value) { var existing = await Repository.GetSingleOrDefaultAsync( i => i.StartTime == value.StartTime && i.EmployeeId == value.EmployeeId ); if (existing != null) { throw ItemAlreadyExistsException.MatchingEntityExists(nameof(Inspection), existing.Id); } }
public async override Task <Guid> AddAsync(Test test) { var existing = await Repository.GetSingleOrDefaultAsync( i => i.StartTime == test.StartTime && i.EmployeeId == test.EmployeeId ); if (existing != null) { throw ItemAlreadyExistsException.MatchingEntityExists(nameof(Test), existing.Id); } return(await base.AddAsync(test)); }
public void WriteDataSources_OneOrMoreAlreadyExists_OverwriteDisallowed() { List <DataSourceItem> items = new List <DataSourceItem>(); items.AddRange(dataSourceItems); items.Add(alreadyExistsDataSourceItem); ItemAlreadyExistsException ex = Assert.Throws <ItemAlreadyExistsException>( delegate { writer.WriteDataSources(items.ToArray()); }); Assert.That(ex.Message, Is.EqualTo(string.Format("An item at '{0}' already exists.", alreadyExistsDataSourceItem.Path))); }
public void WriteFolders_OneOrMoreAlreadyExists() { List <FolderItem> items = new List <FolderItem>(); items.AddRange(folderItems); items.Add(alreadyExistsFolderItem); ItemAlreadyExistsException ex = Assert.Throws <ItemAlreadyExistsException>( delegate { writer.WriteFolders(items.ToArray()); }); Assert.That(ex.Message, Is.EqualTo(string.Format("An item at '{0}' already exists.", alreadyExistsFolderItem.Path))); }
public void Store_AddItemWithSameNameTwice_ByOwner_NotOpener_ShouldFail() { AddFirstOwnerToStoreByOpener(); Guid sessionID = Guid.NewGuid(); LoginSessionSuccess(sessionID, FIRST_OWNER_USERNAME); Item item = AddOneItemTo_FIRST_STORE_LegalUserForOp(sessionID); string jsonAnswer = AddItemError(sessionID, FIRST_STORE_ID, "newitem", 33, JsonConvert.SerializeObject(stringCategories1), 20.55); ItemAlreadyExistsException e = JsonConvert.DeserializeObject <ItemAlreadyExistsException>(jsonAnswer); Assert.AreEqual("Item with name newitem already exists", e.Message); }
public void WriteReports_OneOrMoreAlreadyExists_OverwriteDisallowed() { List <ReportItem> items = new List <ReportItem>() { reportItem_AlreadyExists }; items.AddRange(reportItems); ItemAlreadyExistsException ex = Assert.Throws <ItemAlreadyExistsException>( delegate { writer.WriteReports(items.ToArray()); }); Assert.That(ex.Message, Is.EqualTo(string.Format("An item at '{0}' already exists.", reportItem_AlreadyExists.Path))); }