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 ApiBadgeRequestModel(); createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2); CreateResponse <ApiBadgeResponseModel> createResult = await client.BadgeCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiBadgeResponseModel getResponse = await client.BadgeGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.BadgeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiBadgeResponseModel verifyResponse = await client.BadgeGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiBadgeRequestModel model) { this.DateRules(); this.NameRules(); this.UserIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiBadgeResponseModel> CreateRecord(ApiClient client) { var model = new ApiBadgeRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 2); CreateResponse <ApiBadgeResponseModel> result = await client.BadgeCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapResponseToRequest() { var mapper = new ApiBadgeModelMapper(); var model = new ApiBadgeResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1); ApiBadgeRequestModel response = mapper.MapResponseToRequest(model); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.UserId.Should().Be(1); }
public void MapModelToBO() { var mapper = new BOLBadgeMapper(); ApiBadgeRequestModel model = new ApiBadgeRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1); BOBadge response = mapper.MapModelToBO(1, model); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.UserId.Should().Be(1); }
public virtual async Task <IActionResult> Create([FromBody] ApiBadgeRequestModel model) { CreateResponse <ApiBadgeResponseModel> result = await this.BadgeService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Badges/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public virtual BOBadge MapModelToBO( int id, ApiBadgeRequestModel model ) { BOBadge boBadge = new BOBadge(); boBadge.SetProperties( id, model.Date, model.Name, model.UserId); return(boBadge); }
public void CreatePatch() { var mapper = new ApiBadgeModelMapper(); var model = new ApiBadgeRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1); JsonPatchDocument <ApiBadgeRequestModel> patch = mapper.CreatePatch(model); var response = new ApiBadgeRequestModel(); patch.ApplyTo(response); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Name.Should().Be("A"); response.UserId.Should().Be(1); }
private async Task <ApiBadgeRequestModel> PatchModel(int id, JsonPatchDocument <ApiBadgeRequestModel> patch) { var record = await this.BadgeService.Get(id); if (record == null) { return(null); } else { ApiBadgeRequestModel request = this.BadgeModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiBadgeResponseModel> > Create( ApiBadgeRequestModel model) { CreateResponse <ApiBadgeResponseModel> response = new CreateResponse <ApiBadgeResponseModel>(await this.BadgeModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolBadgeMapper.MapModelToBO(default(int), model); var record = await this.BadgeRepository.Create(this.DalBadgeMapper.MapBOToEF(bo)); response.SetRecord(this.BolBadgeMapper.MapBOToModel(this.DalBadgeMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <IBadgeRepository>(); var model = new ApiBadgeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Badge>())).Returns(Task.FromResult(new Badge())); var service = new BadgeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBadgeMapperMock, mock.DALMapperMockFactory.DALBadgeMapperMock); CreateResponse <ApiBadgeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiBadgeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Badge>())); }
public async void Delete() { var mock = new ServiceMockFacade <IBadgeRepository>(); var model = new ApiBadgeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new BadgeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBadgeMapperMock, mock.DALMapperMockFactory.DALBadgeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiBadgeResponseModel> > Update( int id, ApiBadgeRequestModel model) { var validationResult = await this.BadgeModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolBadgeMapper.MapModelToBO(id, model); await this.BadgeRepository.Update(this.DalBadgeMapper.MapBOToEF(bo)); var record = await this.BadgeRepository.Get(id); return(new UpdateResponse <ApiBadgeResponseModel>(this.BolBadgeMapper.MapBOToModel(this.DalBadgeMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiBadgeResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiBadgeRequestModel model) { ApiBadgeRequestModel request = await this.PatchModel(id, this.BadgeModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiBadgeResponseModel> result = await this.BadgeService.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 <ApiBadgeRequestModel> patch) { ApiBadgeResponseModel record = await this.BadgeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBadgeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBadgeResponseModel> result = await this.BadgeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiBadgeResponseModel> > BadgeUpdateAsync(int id, ApiBadgeRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Badges/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiBadgeResponseModel> >(httpResponse.Content.ContentToString())); }