Example #1
0
        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);
        }
Example #2
0
        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)));
        }
Example #3
0
        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)));
        }
Example #4
0
    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)));
        }
Example #6
0
        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));
        }
Example #9
0
        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)));
        }
Example #11
0
        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);
        }
Example #12
0
        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)));
        }