示例#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 ApiCustomerRequestModel();

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

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

            ApiCustomerResponseModel getResponse = await client.CustomerGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.CustomerDeleteAsync(2);

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

            ApiCustomerResponseModel verifyResponse = await client.CustomerGetAsync(2);

            verifyResponse.Should().BeNull();
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiCustomerRequestModel model)
 {
     this.EmailRules();
     this.FirstNameRules();
     this.LastNameRules();
     this.PhoneRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiCustomerResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiCustomerRequestModel();

            model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 1, 1);
            CreateResponse <ApiCustomerResponseModel> result = await client.CustomerCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
示例#4
0
        private async Task <ApiCustomerResponseModel> CreateRecord()
        {
            var model = new ApiCustomerRequestModel();

            model.SetProperties("B", "B", "B", "B");
            CreateResponse <ApiCustomerResponseModel> result = await this.Client.CustomerCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
示例#5
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiCustomerRequestModel model)
 {
     this.AccountNumberRules();
     this.ModifiedDateRules();
     this.PersonIDRules();
     this.RowguidRules();
     this.StoreIDRules();
     this.TerritoryIDRules();
     return(await this.ValidateAsync(model, id));
 }
        public virtual async Task <IActionResult> Create([FromBody] ApiCustomerRequestModel model)
        {
            CreateResponse <ApiCustomerResponseModel> result = await this.CustomerService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Customers/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
示例#7
0
        public void MapModelToBO()
        {
            var mapper = new BOLCustomerMapper();
            ApiCustomerRequestModel model = new ApiCustomerRequestModel();

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

            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiCustomerModelMapper();
            var model  = new ApiCustomerResponseModel();

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

            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
		public virtual BOCustomer MapModelToBO(
			int id,
			ApiCustomerRequestModel model
			)
		{
			BOCustomer boCustomer = new BOCustomer();
			boCustomer.SetProperties(
				id,
				model.Email,
				model.FirstName,
				model.LastName,
				model.Phone);
			return boCustomer;
		}
示例#10
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiCustomerModelMapper();
            var model  = new ApiCustomerResponseModel();

            model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1);
            ApiCustomerRequestModel response = mapper.MapResponseToRequest(model);

            response.AccountNumber.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PersonID.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.StoreID.Should().Be(1);
            response.TerritoryID.Should().Be(1);
        }
        public virtual async Task <CreateResponse <ApiCustomerResponseModel> > Create(
            ApiCustomerRequestModel model)
        {
            CreateResponse <ApiCustomerResponseModel> response = new CreateResponse <ApiCustomerResponseModel>(await this.CustomerModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolCustomerMapper.MapModelToBO(default(int), model);
                var record = await this.CustomerRepository.Create(this.DalCustomerMapper.MapBOToEF(bo));

                response.SetRecord(this.BolCustomerMapper.MapBOToModel(this.DalCustomerMapper.MapEFToBO(record)));
            }

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

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiCustomerRequestModel request = this.CustomerModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiCustomerModelMapper();
            var model  = new ApiCustomerRequestModel();

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

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

            patch.ApplyTo(response);
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
示例#14
0
        public virtual BOCustomer MapModelToBO(
            int customerID,
            ApiCustomerRequestModel model
            )
        {
            BOCustomer boCustomer = new BOCustomer();

            boCustomer.SetProperties(
                customerID,
                model.AccountNumber,
                model.ModifiedDate,
                model.PersonID,
                model.Rowguid,
                model.StoreID,
                model.TerritoryID);
            return(boCustomer);
        }
示例#15
0
        public void CreatePatch()
        {
            var mapper = new ApiCustomerModelMapper();
            var model  = new ApiCustomerRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, 1);

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

            patch.ApplyTo(response);
            response.AccountNumber.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PersonID.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.StoreID.Should().Be(1);
            response.TerritoryID.Should().Be(1);
        }
示例#16
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ICustomerRepository>();
            var model = new ApiCustomerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Customer>())).Returns(Task.FromResult(new Customer()));
            var service = new CustomerService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.CustomerModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLCustomerMapperMock,
                                              mock.DALMapperMockFactory.DALCustomerMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.CustomerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCustomerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Customer>()));
        }
示例#17
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ICustomerRepository>();
            var model = new ApiCustomerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new CustomerService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.CustomerModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLCustomerMapperMock,
                                              mock.DALMapperMockFactory.DALCustomerMapperMock);

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

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

            if (validationResult.IsValid)
            {
                var bo = this.BolCustomerMapper.MapModelToBO(id, model);
                await this.CustomerRepository.Update(this.DalCustomerMapper.MapBOToEF(bo));

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

                return(new UpdateResponse <ApiCustomerResponseModel>(this.BolCustomerMapper.MapBOToModel(this.DalCustomerMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiCustomerResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiCustomerRequestModel model)
        {
            ApiCustomerRequestModel request = await this.PatchModel(id, this.CustomerModelMapper.CreatePatch(model));

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

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

                UpdateResponse <ApiCustomerResponseModel> result = await this.CustomerService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
示例#21
0
        public virtual async Task <UpdateResponse <ApiCustomerResponseModel> > CustomerUpdateAsync(int id, ApiCustomerRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Customers/{id}", item).ConfigureAwait(false);

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