Beispiel #1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiTeacherSkillRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiTeacherSkillResponseModel> createResult = await client.TeacherSkillCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiTeacherSkillResponseModel getResponse = await client.TeacherSkillGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TeacherSkillDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiTeacherSkillResponseModel verifyResponse = await client.TeacherSkillGetAsync(2);

            verifyResponse.Should().BeNull();
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiTeacherSkillModelMapper();
            var model = new ApiTeacherSkillResponseModel();
            model.SetProperties(1, "A");
            ApiTeacherSkillRequestModel response = mapper.MapResponseToRequest(model);

            response.Name.Should().Be("A");
        }
Beispiel #3
0
        private async Task <ApiTeacherSkillResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiTeacherSkillRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiTeacherSkillResponseModel> result = await client.TeacherSkillCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Beispiel #4
0
        public void MapModelToBO()
        {
            var mapper = new BOLTeacherSkillMapper();
            ApiTeacherSkillRequestModel model = new ApiTeacherSkillRequestModel();

            model.SetProperties("A");
            BOTeacherSkill response = mapper.MapModelToBO(1, model);

            response.Name.Should().Be("A");
        }
        public void CreatePatch()
        {
            var mapper = new ApiTeacherSkillModelMapper();
            var model = new ApiTeacherSkillRequestModel();
            model.SetProperties("A");

            JsonPatchDocument<ApiTeacherSkillRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiTeacherSkillRequestModel();
            patch.ApplyTo(response);
            response.Name.Should().Be("A");
        }
        public virtual BOTeacherSkill MapModelToBO(
            int id,
            ApiTeacherSkillRequestModel model
            )
        {
            BOTeacherSkill boTeacherSkill = new BOTeacherSkill();

            boTeacherSkill.SetProperties(
                id,
                model.Name);
            return(boTeacherSkill);
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiTeacherSkillRequestModel model)
        {
            CreateResponse <ApiTeacherSkillResponseModel> result = await this.TeacherSkillService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TeacherSkills/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        private async Task <ApiTeacherSkillRequestModel> PatchModel(int id, JsonPatchDocument <ApiTeacherSkillRequestModel> patch)
        {
            var record = await this.TeacherSkillService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTeacherSkillRequestModel request = this.TeacherSkillModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual async Task <CreateResponse <ApiTeacherSkillResponseModel> > Create(
            ApiTeacherSkillRequestModel model)
        {
            CreateResponse <ApiTeacherSkillResponseModel> response = new CreateResponse <ApiTeacherSkillResponseModel>(await this.teacherSkillModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolTeacherSkillMapper.MapModelToBO(default(int), model);
                var record = await this.teacherSkillRepository.Create(this.dalTeacherSkillMapper.MapBOToEF(bo));

                response.SetRecord(this.bolTeacherSkillMapper.MapBOToModel(this.dalTeacherSkillMapper.MapEFToBO(record)));
            }

            return(response);
        }
Beispiel #10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITeacherSkillRepository>();
            var model = new ApiTeacherSkillRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TeacherSkill>())).Returns(Task.FromResult(new TeacherSkill()));
            var service = new TeacherSkillService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLTeacherSkillMapperMock,
                                                  mock.DALMapperMockFactory.DALTeacherSkillMapperMock,
                                                  mock.BOLMapperMockFactory.BOLRateMapperMock,
                                                  mock.DALMapperMockFactory.DALRateMapperMock);

            CreateResponse <ApiTeacherSkillResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTeacherSkillRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TeacherSkill>()));
        }
Beispiel #11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITeacherSkillRepository>();
            var model = new ApiTeacherSkillRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new TeacherSkillService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLTeacherSkillMapperMock,
                                                  mock.DALMapperMockFactory.DALTeacherSkillMapperMock,
                                                  mock.BOLMapperMockFactory.BOLRateMapperMock,
                                                  mock.DALMapperMockFactory.DALRateMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TeacherSkillModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <UpdateResponse <ApiTeacherSkillResponseModel> > Update(
            int id,
            ApiTeacherSkillRequestModel model)
        {
            var validationResult = await this.teacherSkillModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolTeacherSkillMapper.MapModelToBO(id, model);
                await this.teacherSkillRepository.Update(this.dalTeacherSkillMapper.MapBOToEF(bo));

                var record = await this.teacherSkillRepository.Get(id);

                return(new UpdateResponse <ApiTeacherSkillResponseModel>(this.bolTeacherSkillMapper.MapBOToModel(this.dalTeacherSkillMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTeacherSkillResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTeacherSkillRequestModel model)
        {
            ApiTeacherSkillRequestModel request = await this.PatchModel(id, this.TeacherSkillModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiTeacherSkillResponseModel> result = await this.TeacherSkillService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTeacherSkillRequestModel> patch)
        {
            ApiTeacherSkillResponseModel record = await this.TeacherSkillService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiTeacherSkillRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiTeacherSkillResponseModel> result = await this.TeacherSkillService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #15
0
        public virtual async Task <UpdateResponse <ApiTeacherSkillResponseModel> > TeacherSkillUpdateAsync(int id, ApiTeacherSkillRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/TeacherSkills/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiTeacherSkillResponseModel> >(httpResponse.Content.ContentToString()));
        }
Beispiel #16
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTeacherSkillRequestModel model)
 {
     this.NameRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #17
0
 public async Task <ValidationResult> ValidateCreateAsync(ApiTeacherSkillRequestModel model)
 {
     this.NameRules();
     this.StudioIdRules();
     return(await this.ValidateAsync(model));
 }