Exemple #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 ApiStudioRequestModel();

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

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

            ApiStudioResponseModel getResponse = await client.StudioGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.StudioDeleteAsync(2);

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

            ApiStudioResponseModel verifyResponse = await client.StudioGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Exemple #2
0
        private async Task <ApiStudioResponseModel> CreateRecord()
        {
            var model = new ApiStudioRequestModel();

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

            result.Success.Should().BeTrue();
            return(result.Record);
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiStudioRequestModel model)
 {
     this.Address1Rules();
     this.Address2Rules();
     this.CityRules();
     this.NameRules();
     this.StateIdRules();
     this.WebsiteRules();
     this.ZipRules();
     return(await this.ValidateAsync(model, id));
 }
Exemple #4
0
 public async Task <ValidationResult> ValidateCreateAsync(ApiStudioRequestModel model)
 {
     this.Address1Rules();
     this.Address2Rules();
     this.CityRules();
     this.NameRules();
     this.ProvinceRules();
     this.WebsiteRules();
     this.ZipRules();
     return(await this.ValidateAsync(model));
 }
        public virtual async Task <IActionResult> Create([FromBody] ApiStudioRequestModel model)
        {
            CreateResponse <ApiStudioResponseModel> result = await this.StudioService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Studios/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Exemple #6
0
        public virtual async Task <CreateResponse <ApiStudioResponseModel> > Create(
            ApiStudioRequestModel model)
        {
            CreateResponse <ApiStudioResponseModel> response = new CreateResponse <ApiStudioResponseModel>(await this.StudioModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolStudioMapper.MapModelToBO(default(int), model);
                var record = await this.StudioRepository.Create(this.DalStudioMapper.MapBOToEF(bo));

                response.SetRecord(this.BolStudioMapper.MapBOToModel(this.DalStudioMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiStudioRequestModel> PatchModel(int id, JsonPatchDocument <ApiStudioRequestModel> patch)
        {
            var record = await this.StudioService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiStudioRequestModel request = this.StudioModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Exemple #8
0
        public void MapModelToBO()
        {
            var mapper = new BOLStudioMapper();
            ApiStudioRequestModel model = new ApiStudioRequestModel();

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

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.City.Should().Be("A");
            response.Name.Should().Be("A");
            response.StateId.Should().Be(1);
            response.Website.Should().Be("A");
            response.Zip.Should().Be("A");
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiStudioModelMapper();
            var model  = new ApiStudioResponseModel();

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

            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.City.Should().Be("A");
            response.Name.Should().Be("A");
            response.StateId.Should().Be(1);
            response.Website.Should().Be("A");
            response.Zip.Should().Be("A");
        }
		public async void Create()
		{
			var mock = new ServiceMockFacade<IStudioRepository>();
			var model = new ApiStudioRequestModel();
			mock.RepositoryMock.Setup(x => x.Create(It.IsAny<Studio>())).Returns(Task.FromResult(new Studio()));
			var service = new StudioService(mock.LoggerMock.Object,
			                                mock.RepositoryMock.Object,
			                                mock.ModelValidatorMockFactory.StudioModelValidatorMock.Object,
			                                mock.BOLMapperMockFactory.BOLStudioMapperMock,
			                                mock.DALMapperMockFactory.DALStudioMapperMock);

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

			response.Should().NotBeNull();
			mock.ModelValidatorMockFactory.StudioModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny<ApiStudioRequestModel>()));
			mock.RepositoryMock.Verify(x => x.Create(It.IsAny<Studio>()));
		}
		public async void Delete()
		{
			var mock = new ServiceMockFacade<IStudioRepository>();
			var model = new ApiStudioRequestModel();
			mock.RepositoryMock.Setup(x => x.Delete(It.IsAny<int>())).Returns(Task.CompletedTask);
			var service = new StudioService(mock.LoggerMock.Object,
			                                mock.RepositoryMock.Object,
			                                mock.ModelValidatorMockFactory.StudioModelValidatorMock.Object,
			                                mock.BOLMapperMockFactory.BOLStudioMapperMock,
			                                mock.DALMapperMockFactory.DALStudioMapperMock);

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

			response.Should().NotBeNull();
			mock.RepositoryMock.Verify(x => x.Delete(It.IsAny<int>()));
			mock.ModelValidatorMockFactory.StudioModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny<int>()));
		}
        public virtual BOStudio MapModelToBO(
            int id,
            ApiStudioRequestModel model
            )
        {
            BOStudio boStudio = new BOStudio();

            boStudio.SetProperties(
                id,
                model.Address1,
                model.Address2,
                model.City,
                model.Name,
                model.Province,
                model.Website,
                model.Zip);
            return(boStudio);
        }
        public void CreatePatch()
        {
            var mapper = new ApiStudioModelMapper();
            var model  = new ApiStudioRequestModel();

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

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

            patch.ApplyTo(response);
            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.City.Should().Be("A");
            response.Name.Should().Be("A");
            response.StateId.Should().Be(1);
            response.Website.Should().Be("A");
            response.Zip.Should().Be("A");
        }
Exemple #14
0
        public virtual async Task <UpdateResponse <ApiStudioResponseModel> > Update(
            int id,
            ApiStudioRequestModel model)
        {
            var validationResult = await this.StudioModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolStudioMapper.MapModelToBO(id, model);
                await this.StudioRepository.Update(this.DalStudioMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiStudioResponseModel>(this.BolStudioMapper.MapBOToModel(this.DalStudioMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiStudioResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiStudioRequestModel model)
        {
            ApiStudioRequestModel request = await this.PatchModel(id, this.StudioModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiStudioResponseModel> result = await this.StudioService.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 <ApiStudioRequestModel> patch)
        {
            ApiStudioResponseModel record = await this.StudioService.Get(id);

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

                UpdateResponse <ApiStudioResponseModel> result = await this.StudioService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <UpdateResponse <ApiStudioResponseModel> > StudioUpdateAsync(int id, ApiStudioRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Studios/{id}", item).ConfigureAwait(false);

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