public void MachineArea_Delete_DoesSetWorkflowStateToRemoved() { OuterResource outerResource = new OuterResource() { Name = Guid.NewGuid().ToString() }; DbContext.OuterResources.Add(outerResource); DbContext.SaveChanges(); InnerResource innerResource = new InnerResource() { Name = Guid.NewGuid().ToString() }; DbContext.InnerResources.Add(innerResource); DbContext.SaveChanges(); Random rnd = new Random(); OuterInnerResource outerInnerResource = new OuterInnerResource(); outerInnerResource.OuterResourceId = outerResource.Id; outerInnerResource.InnerResourceId = innerResource.Id; DbContext.OuterInnerResources.Add(outerInnerResource); DbContext.SaveChanges(); //Act outerInnerResource.Delete(DbContext); OuterInnerResource dbOuterInnerResource = DbContext.OuterInnerResources.AsNoTracking().First(); List <OuterInnerResource> machineAreaList = DbContext.OuterInnerResources.AsNoTracking().ToList(); List <OuterInnerResourceVersion> machineAreaVersions = DbContext.OuterInnerResourceVersions.AsNoTracking().ToList(); //Assert Assert.NotNull(dbOuterInnerResource); Assert.NotNull(dbOuterInnerResource.Id); Assert.AreEqual(dbOuterInnerResource.InnerResourceId, innerResource.Id); Assert.AreEqual(dbOuterInnerResource.OuterResourceId, outerResource.Id); Assert.AreEqual(1, machineAreaList.Count()); Assert.AreEqual(1, machineAreaVersions.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(outerInnerResource.CreatedByUserId, dbOuterInnerResource.CreatedByUserId); Assert.AreEqual(outerInnerResource.UpdatedByUserId, dbOuterInnerResource.UpdatedByUserId); Assert.AreEqual(dbOuterInnerResource.WorkflowState, Constants.WorkflowStates.Removed); }
private async Task UpdateSitesDeployed( OuterInnerResource outerInnerResource, List <Site> sites, int eFormId) { WriteLogEntry("OuterInnerResourceUpdateHandler: UpdateSitesDeployed called"); var siteIds = new List <int>(); if (outerInnerResource.WorkflowState == Constants.WorkflowStates.Created) { if (sites.Any()) { foreach (var site in sites) { siteIds.Add(site.Id); var outerInnerResourceSites = await _dbContext.OuterInnerResourceSites.Where( x => x.MicrotingSdkSiteId == site.Id && x.OuterInnerResourceId == outerInnerResource.Id && x.WorkflowState == Constants.WorkflowStates.Created).ToListAsync(); if (!outerInnerResourceSites.Any()) { var outerInnerResourceSite = new OuterInnerResourceSite { OuterInnerResourceId = outerInnerResource.Id, MicrotingSdkSiteId = site.Id, MicrotingSdkeFormId = eFormId }; await outerInnerResourceSite.Create(_dbContext); await _bus.SendLocal(new OuterInnerResourcePosteForm(outerInnerResourceSite.Id, eFormId)); } else { if (outerInnerResourceSites.First().MicrotingSdkCaseId == null) { await _bus.SendLocal(new OuterInnerResourcePosteForm( outerInnerResourceSites.First().Id, eFormId)); } } } } } var sitesConfigured = _dbContext.OuterInnerResourceSites.Where(x => x.OuterInnerResourceId == outerInnerResource.Id && x.WorkflowState != Constants.WorkflowStates.Removed).ToList(); WriteLogEntry("OuterInnerResourceUpdateHandler: sitesConfigured looked up"); if (sitesConfigured.Any()) { foreach (var outerInnerResourceSite in sitesConfigured) { if (!siteIds.Contains(outerInnerResourceSite.MicrotingSdkSiteId) || outerInnerResource.WorkflowState == Constants.WorkflowStates.Removed) { if (outerInnerResourceSite.MicrotingSdkCaseId != null) { await outerInnerResourceSite.Delete(_dbContext); await _bus.SendLocal(new OuterInnerResourceDeleteFromServer(outerInnerResourceSite.Id)); } } } } }