コード例 #1
0
        public async Task UpdateAsync_given_study_updates_study()
        {
            // Arrange
            var context = new Mock <IContext>();
            var entity  = new Study {
                Id = 11
            };

            context.Setup(c => c.Studies.FindAsync(11)).ReturnsAsync(entity);

            using (var repository = new StudyRepository(context.Object))
            {
                var study = new StudyDTO
                {
                    Id          = 11,
                    Title       = "StudyTitle",
                    Description = "StudyDescription"
                };

                // Act
                await repository.UpdateAsync(study);
            }

            // Assert
            Assert.Equal("StudyTitle", entity.Title);
            Assert.Equal("StudyDescription", entity.Description);
        }
コード例 #2
0
        public async Task UpdateAsync_given_study_returns_true()
        {
            // Arrange
            var context = new Mock <IContext>();
            var entity  = new Study {
                Id = 11
            };

            context.Setup(c => c.Studies.FindAsync(11)).ReturnsAsync(entity);

            using (var repository = new StudyRepository(context.Object))
            {
                var study = new StudyDTO
                {
                    Id          = 11,
                    Title       = "StudyTitle",
                    Description = "StudyDescription"
                };

                // Act
                var result = await repository.UpdateAsync(study);

                // Assert
                Assert.True(result);
            }
        }
コード例 #3
0
ファイル: StudyService.cs プロジェクト: etriks/ehs-server
        public StudyDTO Addstudy(StudyDTO studyDto)
        {
            if (studyDto.ProjectAcc != null)
            {
                var project = _projectRepository.FindSingle(p => p.Accession == studyDto.ProjectAcc,
                                                            new List <string>()
                {
                    "Studies"
                });

                if (project != null)
                {
                    var num  = project.Studies.Count;
                    var abbr = studyDto.ProjectAcc.Substring(2, 3);
                    studyDto.Accession = "S-" + abbr + "-" + (num + 1).ToString("00");
                    studyDto.ProjectId = project.Id;
                }
            }


            var study = new Study()
            {
                Name = studyDto.Name, Description = studyDto.Title, Accession = studyDto.Accession, ProjectId = studyDto.ProjectId
            };

            study = _studyRepository.Insert(study);
            if (!_studyServiceUnit.Save().Equals("CREATED"))
            {
                return(null);
            }
            studyDto.Id        = study.Id;
            studyDto.Accession = study.Accession;
            return(studyDto);
        }
コード例 #4
0
        public async Task UpdateAsync_given_study_calls_SaveChangesAsync()
        {
            // Arrange
            var context = new Mock <IContext>();
            var entity  = new Study {
                Id = 11
            };

            context.Setup(c => c.Studies.FindAsync(11)).ReturnsAsync(entity);

            using (var repository = new StudyRepository(context.Object))
            {
                var study = new StudyDTO
                {
                    Id          = 11,
                    Title       = "StudyTitle",
                    Description = "StudyDescription"
                };

                // Act
                await repository.UpdateAsync(study);
            }

            // Assert
            context.Verify(c => c.SaveChangesAsync(default(CancellationToken)));
        }
コード例 #5
0
        public IActionResult Study([FromBody] StudyModel model)
        {
            StudyDTO dto = Mapping.Mapper.Map <StudyModel, StudyDTO>(model);

            _curriculumService.AddOrUpdateSectionBlock <StudyDTO>(dto, model.FormMode, SectionNames.Study);

            return(Ok(new { id = model.StudyId }));
        }
コード例 #6
0
 public StudyControllerTests()
 {
     _studyLogicMock = new Mock <IStudyLogic>();
     _studyDTO       = new StudyDTO()
     {
         Id = 1, Name = "Test", Description = "Test"
     };
 }
コード例 #7
0
ファイル: StudyLogicTests.cs プロジェクト: Jodavs/ReviewIt
 public StudyLogicTests()
 {
     _mock     = new Mock <IRepository <StudyDTO> >();
     _studyDTO = new StudyDTO()
     {
         Id = 1
     };
 }
コード例 #8
0
ファイル: StudyService.cs プロジェクト: etriks/ehs-server
        //public void addDatasetVariables(List<VariableDefinition> variableDefinitions)
        //{
        //    for (int i = 0; i < variableDefinitions.Count; i++)
        //    {
        //        _variableDefinitionRepository.Insert(variableDefinitions[i]);
        //    }
        //    _studyServiceUnit.Save();
        //}

        public string Updatestudy(StudyDTO studyDto, int studyId)
        {
            var studyToUpdate = _studyRepository.Get(studyId);

            studyToUpdate.Name        = studyDto.Name;
            studyToUpdate.Description = studyDto.Title;
            _studyRepository.Update(studyToUpdate);
            return(_studyServiceUnit.Save());
        }
コード例 #9
0
ファイル: StudyController.cs プロジェクト: etriks/ehs-server
        public IActionResult Addstudy([FromBody] StudyDTO studyDTO)
        {
            var addedstudy = _studyService.Addstudy(studyDTO);

            if (addedstudy != null)
            {
                return(new CreatedAtActionResult("GET", "GetstudyById", new { studyId = addedstudy.Id }, studyDTO));
            }

            return(new BadRequestResult());
        }
コード例 #10
0
ファイル: StudyController.cs プロジェクト: Jodavs/ReviewIt
        public async Task <IActionResult> CreateStudy([FromBody] StudyDTO study)
        {
            if (!ModelState.IsValid || study.Id != 0)
            {
                return(BadRequest(ModelState));
            }

            var create = await _studyLogic.Create(study);

            return(Ok(create));
        }
コード例 #11
0
        public StudyLogicIntegrationTests()
        {
            var efContext = new EFContext();

            _repo     = new StudyRepository(efContext);
            _studyDTO = new StudyDTO()
            {
                Id = 1
            };
            efContext.PurgeData();
        }
コード例 #12
0
ファイル: StudyController.cs プロジェクト: etriks/ehs-server
 public IActionResult Updatestudy(int studyId, [FromBody] StudyDTO studyDTO)
 {
     try
     {
         _studyService.Updatestudy(studyDTO, studyId);
         return(new CreatedAtActionResult("GET", "GetstudyById", new { studyId = studyDTO.Id }, studyDTO));
     }
     catch (Exception e)
     {
         return(new BadRequestObjectResult(e.Message));
     }
 }
コード例 #13
0
 public static Study ConvertToEntity(this StudyDTO dto)
 {
     return(new Study {
         Id = dto.Id,
         Name = dto.Name,
         Phases = dto.Phases?.Select(d => d.ConvertToEntity()).ToList(),
         Description = dto.Description,
         ActivePhase = dto.ActivePhase?.ConvertToEntity(),
         Participants = dto.Users?.Select(d => d.ConvertToEntity()).ToList(),
         Publications = dto.Publications?.Select(d => d.ConvertToEntity()).ToList()
     });
 }
コード例 #14
0
        public async Task Post_when_not_ModelState_IsValid_returns_BadRequest()
        {
            var controller = new StudiesController(null);

            controller.ModelState.AddModelError("", "");

            var study = new StudyDTO();

            var result = await controller.Post(study);

            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #15
0
        public async Task Put_when_repository_Update_returns_false_returns_NotFound()
        {
            var study = new StudyDTO {
                Id = 42, Name = "Name"
            };
            var repository = new Mock <IStudyRepository>();
            var controller = new StudiesController(repository.Object);

            var result = await controller.Put(42, study);

            Assert.IsType <NotFoundResult>(result);
        }
コード例 #16
0
        public async Task Post_when_valid_returns_Created()
        {
            var repository = new Mock <IStudyRepository>();
            var controller = new StudiesController(repository.Object);

            var study = new StudyDTO {
                Name = "Name"
            };

            var result = await controller.Post(study);

            Assert.IsAssignableFrom <CreatedAtActionResult>(result);
        }
コード例 #17
0
        public async Task <IActionResult> Post([FromBody] StudyDTO study)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = await _repository.CreateAsync(study);

            study.Id = id;

            return(CreatedAtAction("Get", new { id }, study));
        }
コード例 #18
0
        public async Task Post_calls_repository_Create()
        {
            var repository = new Mock <IStudyRepository>();
            var controller = new StudiesController(repository.Object);

            var study = new StudyDTO {
                Name = "Name"
            };

            await controller.Post(study);

            repository.Verify(r => r.CreateAsync(study), Times.Once);
        }
コード例 #19
0
        public void Gets_all_phases_for_study_valid_input()
        {
            var study = new StudyDTO
            {
                Id                     = 0,
                Name                   = "test",
                Description            = "for testing",
                ActivePhase            = null,
                ExclusionCriteria      = null,
                ClassificationCriteria = null,
                Users                  = null,
                Publications           = null,
                Phases                 = null
            };


            var listOfPhases = new List <PhaseDTO>
            {
                new PhaseDTO
                {
                    Id            = 0, Purpose = "something", Participants = null, TaskDelegations = null,
                    DisplayFields = null, InputFields = null, OverlapPercentage = 50,
                    IsAutomatic   = true, ConflictManager = null, StudyId = study.Id
                },
                new PhaseDTO
                {
                    Id            = 1, Purpose = "something1", Participants = null, TaskDelegations = null,
                    DisplayFields = null, InputFields = null, OverlapPercentage = 50,
                    IsAutomatic   = true, ConflictManager = null, StudyId = study.Id
                },
                new PhaseDTO
                {
                    Id            = 5, Purpose = "something", Participants = null, TaskDelegations = null,
                    DisplayFields = null, InputFields = null, OverlapPercentage = 50,
                    IsAutomatic   = true, ConflictManager = null, StudyId = study.Id
                }
            };

            study.Phases = listOfPhases.ToList();

            _phaseDtoRepository.Setup(a => a.ReadAsync()).Returns(Task.FromResult(listOfPhases.AsQueryable()));


            var result = _phaseLogic.GetAllForStudy(study.Id).Result;

            var phase1 = listOfPhases.ElementAt(0);
            var res1   = result.ElementAt(0);

            Assert.Equal(listOfPhases.Count(), result.Count());
            Assert.Equal(phase1.Id, res1.Id);
        }
コード例 #20
0
        public async Task Get_42_returns_repository_FindAsync_42()
        {
            var repository = new Mock <IStudyRepository>();
            var study      = new StudyDTO {
                Id = 42
            };

            repository.Setup(r => r.FindAsync(42)).ReturnsAsync(study);
            var controller = new StudiesController(repository.Object);

            var result = await controller.Get(42) as OkObjectResult;

            Assert.Same(study, result.Value);
        }
コード例 #21
0
        public async Task Put_when_repository_Update_returns_true_returns_NoContent()
        {
            var study = new StudyDTO {
                Id = 42, Name = "Name"
            };
            var repository = new Mock <IStudyRepository>();

            repository.Setup(r => r.UpdateAsync(study)).ReturnsAsync(true);
            var controller = new StudiesController(repository.Object);

            var result = await controller.Put(42, study);

            Assert.IsType <NoContentResult>(result);
        }
コード例 #22
0
        public async Task Put_when_not_ModelState_IsValid_does_not_call_repository()
        {
            var study = new StudyDTO {
                Id = 42, Name = "Name"
            };
            var repository = new Mock <IStudyRepository>();
            var controller = new StudiesController(repository.Object);

            controller.ModelState.AddModelError("", "");

            await controller.Put(42, study);

            repository.Verify(r => r.UpdateAsync(study), Times.Never);
        }
コード例 #23
0
        public async Task Put_given_id_not_eq_to_studyId_returns_BadRequest()
        {
            // Arrange
            var repository = new Mock <IStudyRepository>();
            var controller = new StudyController(repository.Object, log.Object);

            var customer = new StudyDTO {
                Id = 11
            };

            // Act
            var result = await controller.Put(0, customer);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #24
0
        public async Task Put_given_valid_study_calls_UpdateAsync()
        {
            // Arrange
            var repository = new Mock <IStudyRepository>();
            var controller = new StudyController(repository.Object, log.Object);

            var study = new StudyDTO {
                Id = 11
            };

            // Act
            await controller.Put(11, study);

            // Arrange
            repository.Verify(r => r.UpdateAsync(study));
        }
コード例 #25
0
ファイル: StudyController.cs プロジェクト: Jodavs/ReviewIt
        public async Task <IActionResult> UpdateStudy([FromBody] StudyDTO study, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var update = await _studyLogic.Update(study, id);

            if (update)
            {
                return(NoContent());
            }

            return(NotFound());
        }
コード例 #26
0
        public async Task <bool> UpdateAsync(StudyDTO study)
        {
            var entity = await _context.Studies.FindAsync(study.Id);

            if (entity == null)
            {
                return(false);
            }

            entity.Title       = study.Title;
            entity.Description = study.Description;

            await _context.SaveChangesAsync();

            return(true);
        }
コード例 #27
0
        public async Task Post_when_valid_returns_study_with_new_id()
        {
            var study = new StudyDTO {
                Name = "Name"
            };
            var repository = new Mock <IStudyRepository>();

            repository.Setup(r => r.CreateAsync(study)).ReturnsAsync(42);
            var controller = new StudiesController(repository.Object);

            var result = await controller.Post(study) as CreatedAtActionResult;

            var created = result.Value as StudyDTO;

            Assert.Equal(42, created.Id);
        }
コード例 #28
0
        public async Task <IActionResult> Put(int id, [FromBody] StudyDTO study)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ok = await _repository.UpdateAsync(study);

            if (ok)
            {
                return(NoContent());
            }

            return(NotFound());
        }
コード例 #29
0
        public async Task Post_when_valid_returns_Get_action()
        {
            var study = new StudyDTO {
                Name = "Name"
            };
            var repository = new Mock <IStudyRepository>();

            repository.Setup(r => r.CreateAsync(study)).ReturnsAsync(42);
            var controller = new StudiesController(repository.Object);

            var result = await controller.Post(study) as CreatedAtActionResult;

            Assert.Equal("Get", result.ActionName);
            Assert.Null(result.ControllerName); // null means current controller
            Assert.Equal(42, result.RouteValues["id"]);
        }
コード例 #30
0
        public async void Gets_all_phases_for_study_valid_input_integration()
        {
            var study = new StudyDTO {
                Id                     = 0,
                Name                   = "test",
                Description            = "for testing",
                ActivePhase            = null,
                ExclusionCriteria      = null,
                ClassificationCriteria = null,
                Users                  = null,
                Publications           = null,
                Phases                 = null
            };


            var listOfPhases = new Collection <PhaseDTO>
            {
                new PhaseDTO
                {
                    Id            = 0, Purpose = "something", Participants = null, TaskDelegations = null,
                    DisplayFields = null, InputFields = null, OverlapPercentage = 50,
                    IsAutomatic   = true, ConflictManager = null
                },
                new PhaseDTO
                {
                    Id            = 1, Purpose = "something1", Participants = null, TaskDelegations = null,
                    DisplayFields = null, InputFields = null, OverlapPercentage = 50,
                    IsAutomatic   = true, ConflictManager = null
                },
                new PhaseDTO
                {
                    Id            = 5, Purpose = "something", Participants = null, TaskDelegations = null,
                    DisplayFields = null, InputFields = null, OverlapPercentage = 50,
                    IsAutomatic   = true, ConflictManager = null
                }
            };

            study.Phases = listOfPhases;

            var result = await _phaseLogic.GetAllForStudy(study.Id);

            var phase1 = listOfPhases.ElementAt(0);
            var res1   = result.ElementAt(0);

            Assert.Equal(listOfPhases.Count(), result.Count());
            Assert.Equal(phase1.Id, res1.Id);
        }