Example #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 ApiFamilyRequestModel();

            createModel.SetProperties("B", "B", "B", "B", "B");
            CreateResponse <ApiFamilyResponseModel> createResult = await client.FamilyCreateAsync(createModel);

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

            ApiFamilyResponseModel getResponse = await client.FamilyGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.FamilyDeleteAsync(2);

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

            ApiFamilyResponseModel verifyResponse = await client.FamilyGetAsync(2);

            verifyResponse.Should().BeNull();
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiFamilyRequestModel model)
 {
     this.NoteRules();
     this.PrimaryContactEmailRules();
     this.PrimaryContactFirstNameRules();
     this.PrimaryContactLastNameRules();
     this.PrimaryContactPhoneRules();
     return(await this.ValidateAsync(model, id));
 }
Example #3
0
        private async Task <ApiFamilyResponseModel> CreateRecord()
        {
            var model = new ApiFamilyRequestModel();

            model.SetProperties("B", "B", "B", "B", "B", 1);
            CreateResponse <ApiFamilyResponseModel> result = await this.Client.FamilyCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiFamilyRequestModel model)
 {
     this.NotesRules();
     this.PcEmailRules();
     this.PcFirstNameRules();
     this.PcLastNameRules();
     this.PcPhoneRules();
     this.StudioIdRules();
     return(await this.ValidateAsync(model, id));
 }
Example #5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiFamilyRequestModel model)
        {
            CreateResponse <ApiFamilyResponseModel> result = await this.FamilyService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Families/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Example #6
0
        public void MapModelToBO()
        {
            var mapper = new BOLFamilyMapper();
            ApiFamilyRequestModel model = new ApiFamilyRequestModel();

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

            response.Note.Should().Be("A");
            response.PrimaryContactEmail.Should().Be("A");
            response.PrimaryContactFirstName.Should().Be("A");
            response.PrimaryContactLastName.Should().Be("A");
            response.PrimaryContactPhone.Should().Be("A");
        }
Example #7
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiFamilyModelMapper();
            var model  = new ApiFamilyResponseModel();

            model.SetProperties(1, "A", "A", "A", "A", "A");
            ApiFamilyRequestModel response = mapper.MapResponseToRequest(model);

            response.Note.Should().Be("A");
            response.PrimaryContactEmail.Should().Be("A");
            response.PrimaryContactFirstName.Should().Be("A");
            response.PrimaryContactLastName.Should().Be("A");
            response.PrimaryContactPhone.Should().Be("A");
        }
        public virtual async Task <CreateResponse <ApiFamilyResponseModel> > Create(
            ApiFamilyRequestModel model)
        {
            CreateResponse <ApiFamilyResponseModel> response = new CreateResponse <ApiFamilyResponseModel>(await this.familyModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolFamilyMapper.MapModelToBO(default(int), model);
                var record = await this.familyRepository.Create(this.dalFamilyMapper.MapBOToEF(bo));

                response.SetRecord(this.bolFamilyMapper.MapBOToModel(this.dalFamilyMapper.MapEFToBO(record)));
            }

            return(response);
        }
Example #9
0
        public void MapModelToBO()
        {
            var mapper = new BOLFamilyMapper();
            ApiFamilyRequestModel model = new ApiFamilyRequestModel();

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

            response.Notes.Should().Be("A");
            response.PcEmail.Should().Be("A");
            response.PcFirstName.Should().Be("A");
            response.PcLastName.Should().Be("A");
            response.PcPhone.Should().Be("A");
            response.StudioId.Should().Be(1);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiFamilyModelMapper();
            var model  = new ApiFamilyResponseModel();

            model.SetProperties(1, "A", "A", "A", "A", "A", 1);
            ApiFamilyRequestModel response = mapper.MapResponseToRequest(model);

            response.Notes.Should().Be("A");
            response.PcEmail.Should().Be("A");
            response.PcFirstName.Should().Be("A");
            response.PcLastName.Should().Be("A");
            response.PcPhone.Should().Be("A");
            response.StudioId.Should().Be(1);
        }
Example #11
0
        private async Task <ApiFamilyRequestModel> PatchModel(int id, JsonPatchDocument <ApiFamilyRequestModel> patch)
        {
            var record = await this.FamilyService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiFamilyRequestModel request = this.FamilyModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public virtual BOFamily MapModelToBO(
            int id,
            ApiFamilyRequestModel model
            )
        {
            BOFamily boFamily = new BOFamily();

            boFamily.SetProperties(
                id,
                model.Note,
                model.PrimaryContactEmail,
                model.PrimaryContactFirstName,
                model.PrimaryContactLastName,
                model.PrimaryContactPhone);
            return(boFamily);
        }
Example #13
0
        public void CreatePatch()
        {
            var mapper = new ApiFamilyModelMapper();
            var model  = new ApiFamilyRequestModel();

            model.SetProperties("A", "A", "A", "A", "A");

            JsonPatchDocument <ApiFamilyRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiFamilyRequestModel();

            patch.ApplyTo(response);
            response.Note.Should().Be("A");
            response.PrimaryContactEmail.Should().Be("A");
            response.PrimaryContactFirstName.Should().Be("A");
            response.PrimaryContactLastName.Should().Be("A");
            response.PrimaryContactPhone.Should().Be("A");
        }
        public virtual BOFamily MapModelToBO(
            int id,
            ApiFamilyRequestModel model
            )
        {
            BOFamily boFamily = new BOFamily();

            boFamily.SetProperties(
                id,
                model.Notes,
                model.PcEmail,
                model.PcFirstName,
                model.PcLastName,
                model.PcPhone,
                model.StudioId);
            return(boFamily);
        }
Example #15
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IFamilyRepository>();
            var model = new ApiFamilyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Family>())).Returns(Task.FromResult(new Family()));
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFamilyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Family>()));
        }
Example #16
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IFamilyRepository>();
            var model = new ApiFamilyRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.bolFamilyMapper.MapModelToBO(id, model);
                await this.familyRepository.Update(this.dalFamilyMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiFamilyResponseModel>(this.bolFamilyMapper.MapBOToModel(this.dalFamilyMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiFamilyResponseModel>(validationResult));
            }
        }
Example #18
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiFamilyRequestModel model)
        {
            ApiFamilyRequestModel request = await this.PatchModel(id, this.FamilyModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #19
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiFamilyRequestModel> patch)
        {
            ApiFamilyResponseModel record = await this.FamilyService.Get(id);

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

                UpdateResponse <ApiFamilyResponseModel> result = await this.FamilyService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Example #20
0
        public virtual async Task <UpdateResponse <ApiFamilyResponseModel> > FamilyUpdateAsync(int id, ApiFamilyRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Families/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiFamilyResponseModel> >(httpResponse.Content.ContentToString()));
        }