public void CreatePatch() { var mapper = new ApiUsersModelMapper(); var model = new ApiUsersRequestModel(); model.SetProperties("A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, "A"); JsonPatchDocument <ApiUsersRequestModel> patch = mapper.CreatePatch(model); var response = new ApiUsersRequestModel(); patch.ApplyTo(response); response.AboutMe.Should().Be("A"); response.AccountId.Should().Be(1); response.Age.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DisplayName.Should().Be("A"); response.DownVotes.Should().Be(1); response.EmailHash.Should().Be("A"); response.LastAccessDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Location.Should().Be("A"); response.Reputation.Should().Be(1); response.UpVotes.Should().Be(1); response.Views.Should().Be(1); response.WebsiteUrl.Should().Be("A"); }
private async Task <ApiUsersResponseModel> CreateRecord() { var model = new ApiUsersRequestModel(); model.SetProperties("B", 2, 2, DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2, 2, 2, "B"); CreateResponse <ApiUsersResponseModel> result = await this.Client.UsersCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiUsersRequestModel model) { CreateResponse <ApiUsersResponseModel> result = await this.UsersService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Users/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiUsersRequestModel> PatchModel(int id, JsonPatchDocument <ApiUsersRequestModel> patch) { var record = await this.UsersService.Get(id); if (record == null) { return(null); } else { ApiUsersRequestModel request = this.UsersModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiUsersResponseModel> > Create( ApiUsersRequestModel model) { CreateResponse <ApiUsersResponseModel> response = new CreateResponse <ApiUsersResponseModel>(await this.usersModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolUsersMapper.MapModelToBO(default(int), model); var record = await this.usersRepository.Create(this.dalUsersMapper.MapBOToEF(bo)); response.SetRecord(this.bolUsersMapper.MapBOToModel(this.dalUsersMapper.MapEFToBO(record))); } return(response); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiUsersRequestModel model) { this.AboutMeRules(); this.AccountIdRules(); this.AgeRules(); this.CreationDateRules(); this.DisplayNameRules(); this.DownVotesRules(); this.EmailHashRules(); this.LastAccessDateRules(); this.LocationRules(); this.ReputationRules(); this.UpVotesRules(); this.ViewsRules(); this.WebsiteUrlRules(); return(await this.ValidateAsync(model, id)); }
public async void Create() { var mock = new ServiceMockFacade <IUsersRepository>(); var model = new ApiUsersRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Users>())).Returns(Task.FromResult(new Users())); var service = new UsersService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.UsersModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLUsersMapperMock, mock.DALMapperMockFactory.DALUsersMapperMock); CreateResponse <ApiUsersResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.UsersModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiUsersRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Users>())); }
public async void Delete() { var mock = new ServiceMockFacade <IUsersRepository>(); var model = new ApiUsersRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new UsersService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.UsersModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLUsersMapperMock, mock.DALMapperMockFactory.DALUsersMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.UsersModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiUsersResponseModel> > Update( int id, ApiUsersRequestModel model) { var validationResult = await this.usersModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolUsersMapper.MapModelToBO(id, model); await this.usersRepository.Update(this.dalUsersMapper.MapBOToEF(bo)); var record = await this.usersRepository.Get(id); return(new UpdateResponse <ApiUsersResponseModel>(this.bolUsersMapper.MapBOToModel(this.dalUsersMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiUsersResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiUsersRequestModel model) { ApiUsersRequestModel request = await this.PatchModel(id, this.UsersModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiUsersResponseModel> result = await this.UsersService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public void MapResponseToRequest() { var mapper = new ApiUsersModelMapper(); var model = new ApiUsersResponseModel(); model.SetProperties(1, "A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, "A"); ApiUsersRequestModel response = mapper.MapResponseToRequest(model); response.AboutMe.Should().Be("A"); response.AccountId.Should().Be(1); response.Age.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DisplayName.Should().Be("A"); response.DownVotes.Should().Be(1); response.EmailHash.Should().Be("A"); response.LastAccessDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Location.Should().Be("A"); response.Reputation.Should().Be(1); response.UpVotes.Should().Be(1); response.Views.Should().Be(1); response.WebsiteUrl.Should().Be("A"); }
public virtual BOUsers MapModelToBO( int id, ApiUsersRequestModel model ) { BOUsers boUsers = new BOUsers(); boUsers.SetProperties( id, model.AboutMe, model.AccountId, model.Age, model.CreationDate, model.DisplayName, model.DownVotes, model.EmailHash, model.LastAccessDate, model.Location, model.Reputation, model.UpVotes, model.Views, model.WebsiteUrl); return(boUsers); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiUsersRequestModel> patch) { ApiUsersResponseModel record = await this.UsersService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiUsersRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiUsersResponseModel> result = await this.UsersService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiUsersResponseModel> > UsersUpdateAsync(int id, ApiUsersRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Users/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiUsersResponseModel> >(httpResponse.Content.ContentToString())); }