public void Area_Create_DoesCreate() { //Arrange OuterResource outerResource = new OuterResource(); outerResource.Name = Guid.NewGuid().ToString(); //Act outerResource.Create(DbContext); OuterResource dbOuterResource = DbContext.OuterResources.AsNoTracking().First(); List <OuterResource> areaList = DbContext.OuterResources.AsNoTracking().ToList(); //Assert Assert.NotNull(dbOuterResource); Assert.NotNull(dbOuterResource.Id); Assert.AreEqual(1, areaList.Count()); Assert.AreEqual(outerResource.CreatedAt.ToString(), dbOuterResource.CreatedAt.ToString()); Assert.AreEqual(outerResource.Version, dbOuterResource.Version); Assert.AreEqual(outerResource.UpdatedAt.ToString(), dbOuterResource.UpdatedAt.ToString()); Assert.AreEqual(dbOuterResource.WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(outerResource.CreatedByUserId, dbOuterResource.CreatedByUserId); Assert.AreEqual(outerResource.UpdatedByUserId, dbOuterResource.UpdatedByUserId); Assert.AreEqual(outerResource.Name, dbOuterResource.Name); }
public void MachineAreaTimeRegistration_Create_DoesCreate() { //Arrange OuterResource outerResource = new OuterResource() { Name = Guid.NewGuid().ToString() }; outerResource.Create(DbContext); InnerResource innerResource = new InnerResource() { Name = Guid.NewGuid().ToString() }; innerResource.Create(DbContext); Random rnd = new Random(); ResourceTimeRegistration matr = new ResourceTimeRegistration(); matr.DoneAt = DateTime.Now; matr.TimeInHours = 10; matr.TimeInMinutes = 60; matr.TimeInSeconds = 100; matr.SDKCaseId = rnd.Next(1, 100); matr.SDKSiteId = rnd.Next(1, 100); matr.SDKFieldValueId = rnd.Next(1, 100); matr.OuterResourceId = outerResource.Id; matr.InnerResourceId = innerResource.Id; //Act matr.Create(DbContext); ResourceTimeRegistration dbMatr = DbContext.ResourceTimeRegistrations.AsNoTracking().First(); List <ResourceTimeRegistration> matrList = DbContext.ResourceTimeRegistrations.AsNoTracking().ToList(); //Assert Assert.NotNull(dbMatr); Assert.AreEqual(matr.DoneAt.ToString(), dbMatr.DoneAt.ToString()); Assert.AreEqual(matr.TimeInHours, dbMatr.TimeInHours); Assert.AreEqual(matr.TimeInMinutes, dbMatr.TimeInMinutes); Assert.AreEqual(matr.TimeInSeconds, dbMatr.TimeInSeconds); Assert.AreEqual(matr.SDKCaseId, dbMatr.SDKCaseId); Assert.AreEqual(matr.SDKSiteId, dbMatr.SDKSiteId); Assert.AreEqual(matr.SDKFieldValueId, dbMatr.SDKFieldValueId); Assert.AreEqual(matr.OuterResourceId, dbMatr.OuterResourceId); Assert.AreEqual(matr.InnerResourceId, dbMatr.InnerResourceId); Assert.AreEqual(1, matrList.Count()); }
public async Task <OperationResult> Create(OuterResourceModel model) { try { var outerResource = new OuterResource() { Name = model.Name, ExternalId = model.ExternalId }; await outerResource.Create(_dbContext); model.Id = outerResource.Id; if (model.RelatedInnerResourcesIds != null) { foreach (var innerResourceId in model.RelatedInnerResourcesIds) { var macth = await _dbContext.OuterInnerResources.SingleOrDefaultAsync(x => x.OuterResourceId == model.Id && x.InnerResourceId == innerResourceId); if (macth == null) { var outerInnerResource = new Microting.eFormOuterInnerResourceBase.Infrastructure.Data.Entities. OuterInnerResource { InnerResourceId = innerResourceId, OuterResourceId = model.Id }; await outerInnerResource.Create(_dbContext); } } await _bus.SendLocal(new OuterInnerResourceCreate(null, model)); } return(new OperationResult(true, _localizationService.GetString("OuterResourceCreatedSuccessfully", model.Name))); } catch (Exception e) { Trace.TraceError(e.Message); _logger.LogError(e.Message); return(new OperationResult(false, _localizationService.GetString("ErrorCreatingOuterResource"))); } }
public void MachineArea_Create_DoesCreate() { OuterResource outerResource = new OuterResource() { Name = Guid.NewGuid().ToString() }; outerResource.Create(DbContext); InnerResource innerResource = new InnerResource() { Name = Guid.NewGuid().ToString() }; innerResource.Create(DbContext); Random rnd = new Random(); OuterInnerResource outerInnerResource = new OuterInnerResource(); outerInnerResource.OuterResourceId = outerResource.Id; outerInnerResource.InnerResourceId = innerResource.Id; //Act outerInnerResource.Create(DbContext); OuterInnerResource dbOuterInnerResource = DbContext.OuterInnerResources.AsNoTracking().First(); List <OuterInnerResource> machineAreaList = DbContext.OuterInnerResources.AsNoTracking().ToList(); //Assert Assert.NotNull(dbOuterInnerResource); Assert.NotNull(dbOuterInnerResource.Id); Assert.AreEqual(outerInnerResource.OuterResourceId, outerResource.Id); Assert.AreEqual(outerInnerResource.InnerResourceId, innerResource.Id); Assert.AreEqual(1, machineAreaList.Count()); Assert.AreEqual(outerInnerResource.CreatedAt.ToString(), dbOuterInnerResource.CreatedAt.ToString()); Assert.AreEqual(outerInnerResource.Version, dbOuterInnerResource.Version); Assert.AreEqual(outerInnerResource.UpdatedAt.ToString(), dbOuterInnerResource.UpdatedAt.ToString()); Assert.AreEqual(dbOuterInnerResource.WorkflowState, Constants.WorkflowStates.Created); Assert.AreEqual(outerInnerResource.CreatedByUserId, dbOuterInnerResource.CreatedByUserId); Assert.AreEqual(outerInnerResource.UpdatedByUserId, dbOuterInnerResource.UpdatedByUserId); }
public async Task OuterResource_Save_DoesSave() { // Arrange OuterResource newOuterResource = new OuterResource() { Name = Guid.NewGuid().ToString() }; // Act await newOuterResource.Create(DbContext); OuterResource area = DbContext.OuterResources.AsNoTracking().First(); List <OuterResource> areaList = DbContext.OuterResources.AsNoTracking().ToList(); List <OuterResourceVersion> versionList = DbContext.OuterResourceVersions.AsNoTracking().ToList(); // Assert Assert.NotNull(area); Assert.AreEqual(1, areaList.Count()); Assert.AreEqual(1, versionList.Count()); Assert.AreEqual(newOuterResource.Name, area.Name); }
public async Task EmployeesReportByDay_Generate_DoesGenerate() { OuterResource newArea = new OuterResource() { Name = "My OuterResource 1", Version = 1 }; OuterResource newArea1 = new OuterResource() { Name = "My OuterResource 2", Version = 1 }; OuterResource newArea2 = new OuterResource() { Name = "My OuterResource 3", Version = 1 }; InnerResource newMachine = new InnerResource() { Name = "My InnerResource 1", Version = 1 }; InnerResource newMachine1 = new InnerResource() { Name = "My InnerResource 2", Version = 1 }; InnerResource newMachine2 = new InnerResource() { Name = "My InnerResource 3", Version = 1 }; await newArea.Create(DbContext); await newArea1.Create(DbContext); await newArea2.Create(DbContext); await newMachine.Create(DbContext); await newMachine1.Create(DbContext); await newMachine2.Create(DbContext); // Different days ResourceTimeRegistration newTimeRegistrationDay = new ResourceTimeRegistration() { OuterResourceId = newArea.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 13) }; ResourceTimeRegistration newTimeRegistrationDay1 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 14) }; ResourceTimeRegistration newTimeRegistrationDay2 = new ResourceTimeRegistration() { OuterResourceId = newArea2.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine2.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 15) }; ResourceTimeRegistration newTimeRegistrationDay3 = new ResourceTimeRegistration() { OuterResourceId = newArea.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 13) }; ResourceTimeRegistration newTimeRegistrationDay4 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 14) }; ResourceTimeRegistration newTimeRegistrationDay5 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine2.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 15) }; ResourceTimeRegistration newTimeRegistrationDay6 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 15) }; await DbContext.ResourceTimeRegistrations.AddRangeAsync(newTimeRegistrationDay, newTimeRegistrationDay1, newTimeRegistrationDay2, newTimeRegistrationDay3, newTimeRegistrationDay4, newTimeRegistrationDay5, newTimeRegistrationDay6); await DbContext.SaveChangesAsync(); GenerateReportModel model = new GenerateReportModel() { DateFrom = new DateTime(2019, 5, 13), DateTo = new DateTime(2019, 5, 16), Relationship = ReportRelationshipType.Employee, Type = ReportType.Day }; List <SiteDto> sitesList = new List <SiteDto>() { new SiteDto(1, "Test Site 1", "", "", 1, 1, 1, 1), new SiteDto(2, "Test Site 2", "", "", 1, 1, 1, 1) }; DateTime modelDateFrom = new DateTime( model.DateFrom.Year, model.DateFrom.Month, model.DateFrom.Day, 0, 0, 0); DateTime modelDateTo = new DateTime( model.DateTo.Year, model.DateTo.Month, model.DateTo.Day, 23, 59, 59); List <ResourceTimeRegistration> jobsList = await DbContext.ResourceTimeRegistrations .Include(x => x.InnerResource) .Include(x => x.OuterResource) .Where(x => x.DoneAt >= modelDateFrom && x.DoneAt <= modelDateTo) .ToListAsync(); ReportModel reportModel = ReportsHelper.GetReportData(model, jobsList, sitesList, (int)ReportTimeType.Minutes); Assert.AreEqual(reportModel.SubReports.Count, 1); Assert.AreEqual(reportModel.SubReports[0].TotalTime, 4200); Assert.AreEqual(reportModel.SubReports[0].Entities.Count, sitesList.Count); Assert.AreEqual(reportModel.SubReports[0].Entities[0].EntityName, sitesList[0].SiteName); Assert.AreEqual(reportModel.SubReports[0].Entities[1].EntityName, sitesList[1].SiteName); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TotalTime, 1800); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TotalTime, 2400); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[0], 600); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[1], 600); }
public async Task EmployeesReportByMonth_Generate_DoesGenerate() { OuterResource newArea = new OuterResource() { Name = "My OuterResource 1", Version = 1 }; OuterResource newArea1 = new OuterResource() { Name = "My OuterResource 2", Version = 1 }; OuterResource newArea2 = new OuterResource() { Name = "My OuterResource 3", Version = 1 }; InnerResource newMachine = new InnerResource() { Name = "My InnerResource 1", Version = 1 }; InnerResource newMachine1 = new InnerResource() { Name = "My InnerResource 2", Version = 1 }; InnerResource newMachine2 = new InnerResource() { Name = "My InnerResource 3", Version = 1 }; await newArea.Create(DbContext); await newArea1.Create(DbContext); await newArea2.Create(DbContext); await newMachine.Create(DbContext); await newMachine1.Create(DbContext); await newMachine2.Create(DbContext); // Different Month ResourceTimeRegistration newTimeRegistrationMonth = new ResourceTimeRegistration() { OuterResourceId = newArea.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 06, 13) }; ResourceTimeRegistration newTimeRegistrationMonth1 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 07, 14) }; ResourceTimeRegistration newTimeRegistrationMonth2 = new ResourceTimeRegistration() { OuterResourceId = newArea2.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine2.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 07, 15) }; ResourceTimeRegistration newTimeRegistrationMonth3 = new ResourceTimeRegistration() { OuterResourceId = newArea.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 08, 13) }; ResourceTimeRegistration newTimeRegistrationMonth4 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 08, 14) }; ResourceTimeRegistration newTimeRegistrationMonth5 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine2.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 09, 15) }; ResourceTimeRegistration newTimeRegistrationMonth6 = new ResourceTimeRegistration() { OuterResourceId = newArea1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 09, 15) }; await DbContext.ResourceTimeRegistrations.AddRangeAsync(newTimeRegistrationMonth, newTimeRegistrationMonth1, newTimeRegistrationMonth2, newTimeRegistrationMonth3, newTimeRegistrationMonth4, newTimeRegistrationMonth5, newTimeRegistrationMonth6); await DbContext.SaveChangesAsync(); GenerateReportModel model = new GenerateReportModel() { DateFrom = new DateTime(2019, 5, 13), DateTo = new DateTime(2019, 9, 13), Relationship = ReportRelationshipType.Employee, Type = ReportType.Month }; List <SiteDto> sitesList = new List <SiteDto>() { // new SiteDto(1, "Test Site 1", "", "", 1, 1, 1, 1), new SiteDto() { CustomerNo = 1, Email = "bla", FirstName = "Test", LastName = "Site 1", OtpCode = 1, SiteId = 1, SiteName = "Test Site 1", UnitId = 1, WorkerUid = 1 }, // new SiteDto(2, "Test Site 2", "", "", 1, 1, 1, 1) new SiteDto() { CustomerNo = 1, Email = "bla", FirstName = "Test", LastName = "Site 2", OtpCode = 1, SiteId = 2, SiteName = "Test Site 2", UnitId = 1, WorkerUid = 1 } }; DateTime modelDateFrom = new DateTime( model.DateFrom.Year, model.DateFrom.Month, model.DateFrom.Day, 0, 0, 0); DateTime modelDateTo = new DateTime( model.DateTo.Year, model.DateTo.Month, model.DateTo.Day, 23, 59, 59); List <ResourceTimeRegistration> jobsList = await DbContext.ResourceTimeRegistrations .Include(x => x.InnerResource) .Include(x => x.OuterResource) .Where(x => x.DoneAt >= modelDateFrom && x.DoneAt <= modelDateTo) .ToListAsync(); ReportModel reportModel = ReportsHelper.GetReportData(model, jobsList, sitesList, (int)ReportTimeType.Minutes); Assert.AreEqual(reportModel.SubReports.Count, 1); Assert.AreEqual(reportModel.SubReports[0].TotalTime, 3000); Assert.AreEqual(reportModel.SubReports[0].Entities.Count, sitesList.Count); Assert.AreEqual(reportModel.SubReports[0].Entities[0].EntityName, sitesList[0].SiteName); Assert.AreEqual(reportModel.SubReports[0].Entities[1].EntityName, sitesList[1].SiteName); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TotalTime, 1800); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TotalTime, 1200); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[0], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[1], 600); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[2], 1200); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[3], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[4], 0); }
public async Task OuterResourcesReportByWeek_Generate_DoesGenerate() { OuterResource newOuterResource = new OuterResource() { Name = "My OuterResource 1", Version = 1 }; OuterResource newOuterResource1 = new OuterResource() { Name = "My OuterResource 2", Version = 1 }; OuterResource newOuterResource2 = new OuterResource() { Name = "My OuterResource 3", Version = 1 }; InnerResource newMachine = new InnerResource() { Name = "My InnerResource 1", Version = 1 }; InnerResource newMachine1 = new InnerResource() { Name = "My InnerResource 2", Version = 1 }; InnerResource newMachine2 = new InnerResource() { Name = "My InnerResource 3", Version = 1 }; await newOuterResource.Create(DbContext); await newOuterResource1.Create(DbContext); await newOuterResource2.Create(DbContext); await newMachine.Create(DbContext); await newMachine1.Create(DbContext); await newMachine2.Create(DbContext); // Different Weeks ResourceTimeRegistration newTimeRegistrationWeek = new ResourceTimeRegistration() { OuterResourceId = newOuterResource.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 20) }; ResourceTimeRegistration newTimeRegistrationWeek1 = new ResourceTimeRegistration() { OuterResourceId = newOuterResource1.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 20) }; ResourceTimeRegistration newTimeRegistrationWeek2 = new ResourceTimeRegistration() { OuterResourceId = newOuterResource2.Id, Version = 1, SDKSiteId = 1, InnerResourceId = newMachine2.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 05, 27) }; ResourceTimeRegistration newTimeRegistrationWeek3 = new ResourceTimeRegistration() { OuterResourceId = newOuterResource.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 06, 27) }; ResourceTimeRegistration newTimeRegistrationWeek4 = new ResourceTimeRegistration() { OuterResourceId = newOuterResource1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 06, 05) }; ResourceTimeRegistration newTimeRegistrationWeek5 = new ResourceTimeRegistration() { OuterResourceId = newOuterResource1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine2.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 06, 05) }; ResourceTimeRegistration newTimeRegistrationWeek6 = new ResourceTimeRegistration() { OuterResourceId = newOuterResource1.Id, Version = 1, SDKSiteId = 2, InnerResourceId = newMachine1.Id, TimeInSeconds = 36000, DoneAt = new DateTime(2019, 06, 06) }; await DbContext.ResourceTimeRegistrations.AddRangeAsync(newTimeRegistrationWeek, newTimeRegistrationWeek1, newTimeRegistrationWeek2, newTimeRegistrationWeek3, newTimeRegistrationWeek4, newTimeRegistrationWeek5, newTimeRegistrationWeek6); await DbContext.SaveChangesAsync(); GenerateReportModel model = new GenerateReportModel() { DateFrom = new DateTime(2019, 5, 13), DateTo = new DateTime(2019, 6, 07), Relationship = ReportRelationshipType.OuterResource, Type = ReportType.Week }; List <SiteDto> sitesList = new List <SiteDto>() { new SiteDto(1, "Test Site 1", "", "", 1, 1, 1, 1), new SiteDto(2, "Test Site 2", "", "", 1, 1, 1, 1) }; DateTime modelDateFrom = new DateTime( model.DateFrom.Year, model.DateFrom.Month, model.DateFrom.Day, 0, 0, 0); DateTime modelDateTo = new DateTime( model.DateTo.Year, model.DateTo.Month, model.DateTo.Day, 23, 59, 59); List <ResourceTimeRegistration> jobsList = await DbContext.ResourceTimeRegistrations .Include(x => x.InnerResource) .Include(x => x.OuterResource) .Where(x => x.DoneAt >= modelDateFrom && x.DoneAt <= modelDateTo) .ToListAsync(); ReportModel reportModel = ReportsHelper.GetReportData(model, jobsList, sitesList, (int)ReportTimeType.Minutes); Assert.AreEqual(reportModel.SubReports.Count, 1); Assert.AreEqual(reportModel.SubReports[0].TotalTime, 3600); Assert.AreEqual(reportModel.SubReports[0].Entities.Count, 3); Assert.AreEqual(reportModel.SubReports[0].Entities[0].EntityName, newOuterResource.Name); Assert.AreEqual(reportModel.SubReports[0].Entities[1].EntityName, newOuterResource1.Name); Assert.AreEqual(reportModel.SubReports[0].Entities[2].EntityName, newOuterResource2.Name); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TotalTime, 600); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TotalTime, 2400); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[0], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[1], 600); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[2], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[0].TimePerTimeUnit[3], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TimePerTimeUnit[0], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TimePerTimeUnit[1], 600); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TimePerTimeUnit[2], 0); Assert.AreEqual(reportModel.SubReports[0].Entities[1].TimePerTimeUnit[3], 1800); }