public async Task ActivityWithNestedUpdated_StructureUnchanged() { var tree = FixtureData.CreateTestActivityTreeWithOnlyActivityDo(); var updatedTree = FixtureData.CreateTestActivityTreeWithOnlyActivityDo(); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = new PlanDO { PlanState = PlanState.Executing, Name = "name", ChildNodes = { tree } }; uow.PlanRepository.Add(plan); uow.SaveChanges(); Visit(updatedTree, x => x.Label = string.Format("We were here {0}", x.Id)); } await _activity.SaveOrUpdateActivity(updatedTree); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var result = uow.PlanRepository.GetById <ActivityDO>(tree.Id); Compare(updatedTree, result, (r, a) => { if (r.Label != a.Label) { throw new Exception("Update failed"); } }); } }
public async Task ActivityWithNestedUpdated_RemoveElements() { var tree = FixtureData.CreateTestActivityTreeWithOnlyActivityDo(); var updatedTree = FixtureData.CreateTestActivityTreeWithOnlyActivityDo(); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = new PlanDO { PlanState = PlanState.Executing, Name = "name", ChildNodes = { tree } }; uow.PlanRepository.Add(plan); uow.SaveChanges(); int removeCounter = 0; Visit(updatedTree, a => { if (removeCounter % 3 == 0 && a.ParentPlanNode != null) { a.ParentPlanNode.ChildNodes.Remove(a); } removeCounter++; }); } await _activity.SaveOrUpdateActivity(updatedTree); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var result = uow.PlanRepository.GetById <ActivityDO>(tree.Id); Compare(updatedTree, result, (r, a) => { if (r.Id != a.Id) { throw new Exception("Update failed"); } }); } }
public async Task ActivityWithNestedUpdated_AddElements() { var tree = FixtureData.CreateTestActivityTreeWithOnlyActivityDo(); var updatedTree = FixtureData.CreateTestActivityTreeWithOnlyActivityDo(); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = new PlanDO { Name = "name", PlanState = PlanState.Executing, ChildNodes = { tree } }; uow.PlanRepository.Add(plan); uow.SaveChanges(); int addCounter = 0; Visit(updatedTree, a => { if (addCounter % 3 == 0 && a.ParentPlanNode != null) { var newAction = new ActivityDO { Id = FixtureData.GetTestGuidById(addCounter + 666), ParentPlanNode = a, ActivityTemplateId = FixtureData.GetTestGuidById(1) }; a.ParentPlanNode.ChildNodes.Add(newAction); } addCounter++; }); for (int i = 0; i < 4; i++) { Visit(updatedTree, a => { // if (a.Id > 666) if (FixtureData.GetTestIdByGuid(a.Id) > 666) { var newAction = new ActivityDO { Id = FixtureData.GetTestGuidById(addCounter + 666), ParentPlanNode = a, ActivityTemplateId = FixtureData.GetTestGuidById(1) }; a.ParentPlanNode.ChildNodes.Add(newAction); } addCounter++; }); } updatedTree.ParentPlanNodeId = plan.Id; } await _activity.SaveOrUpdateActivity(updatedTree); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var result = uow.PlanRepository.GetById <ActivityDO>(tree.Id); Compare(updatedTree, result, (r, a) => { if (r.Id != a.Id) { throw new Exception("Update failed"); } }); } }