public Task <OperationDetails> New(Visitor visitor) { var task = Task <OperationDetails> .Factory.StartNew(() => { try { var dispatch = new XMLDispatch { Id = visitor.Id, Status = Status.New, Operation = Operation.Add, DateInSystem = DateTime.Now }; _database.XMLDispatchManager.Create(dispatch); return(new OperationDetails(true, "Запись готова для передачи")); } catch (Exception ex) { return(new OperationDetails(false, ex.Message)); } } ); return(task); }
public async Task Add_Update_Remove_XMLDispatch_UnitOfWork() { //create XMLDispatch dispatch = new XMLDispatch { Id = 55, Operation = Operation.Add, Status = Status.New }; var findDispatch = uow.XMLDispatchManager.GetById(dispatch.Id); if (findDispatch != null) { dispatch = findDispatch; } else { dispatch = uow.XMLDispatchManager.Create(dispatch); } findDispatch = uow.XMLDispatchManager.GetAll().Where(d => d.Id == dispatch.Id).FirstOrDefault(); Assert.AreEqual(Operation.Add, findDispatch.Operation); Assert.AreEqual(Status.New, findDispatch.Status); findDispatch = uow.XMLDispatchManager.GetById(dispatch.Id); Assert.AreEqual(Operation.Add, findDispatch.Operation); Assert.AreEqual(Status.New, findDispatch.Status); findDispatch = await uow.XMLDispatchManager.GetByIdAsync(dispatch.Id); Assert.AreEqual(Operation.Add, findDispatch.Operation); Assert.AreEqual(Status.New, findDispatch.Status); //// //edit var newDispatch = dispatch; newDispatch.Operation = Operation.Done; newDispatch.Status = Status.Send; uow.XMLDispatchManager.Update(newDispatch); findDispatch = uow.XMLDispatchManager.GetAll().Where(d => d.Id == newDispatch.Id).FirstOrDefault(); Assert.AreEqual(Operation.Done, findDispatch.Operation); Assert.AreEqual(Status.Send, findDispatch.Status); //// uow.XMLDispatchManager.Delete(newDispatch.Id); findDispatch = uow.XMLDispatchManager.GetAll().Where(d => d.Id == newDispatch.Id).FirstOrDefault(); Assert.IsNull(findDispatch); }
public async Task Delete_Group_Of_Many_Visitors() { var group = await CreateGroup(createGroup, visitor1, visitor2); Assert.IsNotNull(group); var result = await DeleteGroup(group.Id); Assert.IsNotNull(result); foreach (var item in group.Visitors) { XMLDispatch dispatch = database.XMLDispatchManager.GetById(item.Id); Assert.IsNull(dispatch); } }
public async Task Edit_Group_Add_One_Visitor_Of_Many_Visitors() { var group = await CreateGroup(createGroup, visitor1, visitor2); Assert.IsNotNull(group); group = await EditGroup(editGroupNew, visitorNew, visitorNew2, visitorNew3); Assert.IsNotNull(group); foreach (var item in group.Visitors) { XMLDispatch dispatch = database.XMLDispatchManager.GetById(item.Id); Assert.AreEqual(Status.New, dispatch.Status); Assert.AreEqual(Operation.Add, dispatch.Operation); } }
public async Task Edit_Group_Delete_All_Visitors_Of_Many_Visitors() { var group = await CreateGroup(createGroup, visitor1, visitor2); var oldVisitor1 = group.Visitors.FirstOrDefault(v => v.Surname == visitor1.Surname); var oldVisitor2 = group.Visitors.FirstOrDefault(v => v.Surname == visitor2.Surname); Assert.IsNotNull(group); group = await EditGroup(editGroupNew); Assert.IsNotNull(group); XMLDispatch dispatch1 = database.XMLDispatchManager.GetById(oldVisitor1.Id); XMLDispatch dispatch2 = database.XMLDispatchManager.GetById(oldVisitor2.Id); Assert.IsNull(dispatch1); Assert.IsNull(dispatch2); }
public async Task Delete_Group_Of_Many_Recd_Visitors() { var group = await CreateGroup(createGroup, visitor1, visitor2); Assert.IsNotNull(group); await RecdVisitor(group.Visitors); var result = await DeleteGroup(group.Id); Assert.IsNotNull(result); foreach (var item in group.Visitors) { XMLDispatch dispatch = database.XMLDispatchManager.GetById(item.Id); Assert.AreEqual(Status.Recd, dispatch.Status); Assert.AreEqual(Operation.Remove, dispatch.Operation); } }
public async Task Edit_Group_Update_Visitors_One_Visitor_Send_Of_Many_Visitors() { var group = await CreateGroup(createGroup, visitor1, visitor2); await SendVisitor(group.Visitors.FirstOrDefault()); Assert.IsNotNull(group); group = await EditGroup(editGroupNew, visitorNew, visitorNew2); Assert.IsNotNull(group); var resultVisitor1 = group.Visitors.LastOrDefault(); XMLDispatch dispatch = database.XMLDispatchManager.GetById(resultVisitor1.Id); Assert.AreEqual(Status.New, dispatch.Status); Assert.AreEqual(Operation.Add, dispatch.Operation); }
public async Task Delete_Group_One_Visitor_Send_Of_Many_Visitors() { var group = await CreateGroup(createGroup, visitor1, visitor2); Assert.IsNotNull(group); await SendVisitor(group.Visitors.FirstOrDefault()); var result = await DeleteGroup(group.Id); Assert.IsNotNull(result); var resultVisitor1 = group.Visitors.FirstOrDefault(); var resultVisitor2 = group.Visitors.LastOrDefault(); XMLDispatch dispatch1 = database.XMLDispatchManager.GetById(resultVisitor1.Id); XMLDispatch dispatch2 = database.XMLDispatchManager.GetById(resultVisitor2.Id); Assert.AreEqual(Status.Send, dispatch1.Status); Assert.AreEqual(Operation.Remove, dispatch1.Operation); Assert.IsNull(dispatch2); }