Ejemplo n.º 1
0
        public void Checklist_Service_GetById_To_Get_Checklist()
        {
            //Arrange
            List <ChecklistBacklog> checklists = new List <ChecklistBacklog>();
            var checklist = new ChecklistBacklog();

            checklist.ChecklistId = 1;
            checklists.Add(checklist);
            var mockRepoCheck = new Mock <ICheckListRepository>();

            mockRepoCheck.Setup(x => x.Get(1)).Returns(checklists);
            ChecklistService obj = new ChecklistService(mockRepoCheck.Object);
            //Act
            var res = obj.Get(1);

            //Assert
            Assert.NotNull(res);
            Assert.Equal(checklists, res);
        }
Ejemplo n.º 2
0
        Task <OapChecklist> IRequestHandler <AddChecklistRequest, OapChecklist> .Handle(AddChecklistRequest request, CancellationToken cancellationToken)
        {
            var existingChecklist = ChecklistService.GetByName(request.Checklist.Name);

            if (existingChecklist != null)
            {
                return(Task.FromResult(existingChecklist));
            }


            int newChecklistId = 0;

            using (var ts = new TransactionScope())
            {
                newChecklistId = ChecklistService.Add(request.Checklist);

                ts.Complete();
            }
            return(Task.FromResult(ChecklistService.Get(newChecklistId)));
        }
        Task <bool> IRequestHandler <UpdateChecklistRequest, bool> .Handle(UpdateChecklistRequest request, CancellationToken cancellationToken)
        {
            var existingCheckList = ChecklistService.Get(request.Checklist.Id);

            if (existingCheckList == null)
            {
                throw new ApplicationException($"UpdateChecklistHandler: Checklist with Id {request.Checklist.Id} does not exist.");
            }

            //AutoMapper to Map the fields
            Mapper.Map(request.Checklist, existingCheckList);

            using (var ts = new TransactionScope())
            {
                var updatedChecklist = ChecklistService.Update(existingCheckList);

                ts.Complete();
            }
            return(Task.FromResult(true));
        }