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 ApiAdminRequestModel(); createModel.SetProperties("B", "B", "B", "B", "B", "B"); CreateResponse <ApiAdminResponseModel> createResult = await client.AdminCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiAdminResponseModel getResponse = await client.AdminGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.AdminDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiAdminResponseModel verifyResponse = await client.AdminGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiAdminResponseModel> CreateRecord(ApiClient client) { var model = new ApiAdminRequestModel(); model.SetProperties("B", "B", "B", "B", "B", "B"); CreateResponse <ApiAdminResponseModel> result = await client.AdminCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public async Task <ValidationResult> ValidateCreateAsync(ApiAdminRequestModel model) { this.BirthdayRules(); this.EmailRules(); this.FirstNameRules(); this.LastNameRules(); this.PhoneRules(); this.StudioIdRules(); return(await this.ValidateAsync(model)); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiAdminRequestModel model) { this.EmailRules(); this.FirstNameRules(); this.LastNameRules(); this.PasswordRules(); this.PhoneRules(); this.UsernameRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiAdminResponseModel> CreateRecord() { var model = new ApiAdminRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", 1); CreateResponse <ApiAdminResponseModel> result = await this.Client.AdminCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiAdminRequestModel model) { CreateResponse <ApiAdminResponseModel> result = await this.AdminService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Admins/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapResponseToRequest() { var mapper = new ApiAdminModelMapper(); var model = new ApiAdminResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); ApiAdminRequestModel response = mapper.MapResponseToRequest(model); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.StudioId.Should().Be(1); }
public void MapResponseToRequest() { var mapper = new ApiAdminModelMapper(); var model = new ApiAdminResponseModel(); model.SetProperties(1, "A", "A", "A", "A", "A", "A"); ApiAdminRequestModel response = mapper.MapResponseToRequest(model); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Password.Should().Be("A"); response.Phone.Should().Be("A"); response.Username.Should().Be("A"); }
private async Task <ApiAdminRequestModel> PatchModel(int id, JsonPatchDocument <ApiAdminRequestModel> patch) { var record = await this.AdminService.Get(id); if (record == null) { return(null); } else { ApiAdminRequestModel request = this.AdminModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void MapModelToBO() { var mapper = new BOLAdminMapper(); ApiAdminRequestModel model = new ApiAdminRequestModel(); model.SetProperties("A", "A", "A", "A", "A", "A"); BOAdmin response = mapper.MapModelToBO(1, model); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Password.Should().Be("A"); response.Phone.Should().Be("A"); response.Username.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiAdminResponseModel> > Create( ApiAdminRequestModel model) { CreateResponse <ApiAdminResponseModel> response = new CreateResponse <ApiAdminResponseModel>(await this.adminModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolAdminMapper.MapModelToBO(default(int), model); var record = await this.adminRepository.Create(this.dalAdminMapper.MapBOToEF(bo)); response.SetRecord(this.bolAdminMapper.MapBOToModel(this.dalAdminMapper.MapEFToBO(record))); } return(response); }
public void MapModelToBO() { var mapper = new BOLAdminMapper(); ApiAdminRequestModel model = new ApiAdminRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); BOAdmin response = mapper.MapModelToBO(1, model); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.UserId.Should().Be(1); }
public virtual BOAdmin MapModelToBO( int id, ApiAdminRequestModel model ) { BOAdmin boAdmin = new BOAdmin(); boAdmin.SetProperties( id, model.Email, model.FirstName, model.LastName, model.Password, model.Phone, model.Username); return(boAdmin); }
public virtual BOAdmin MapModelToBO( int id, ApiAdminRequestModel model ) { BOAdmin boAdmin = new BOAdmin(); boAdmin.SetProperties( id, model.Birthday, model.Email, model.FirstName, model.LastName, model.Phone, model.StudioId); return(boAdmin); }
public async void Delete() { var mock = new ServiceMockFacade <IAdminRepository>(); var model = new ApiAdminRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new AdminService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.AdminModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLAdminMapperMock, mock.DALMapperMockFactory.DALAdminMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.AdminModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Create() { var mock = new ServiceMockFacade <IAdminRepository>(); var model = new ApiAdminRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Admin>())).Returns(Task.FromResult(new Admin())); var service = new AdminService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.AdminModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLAdminMapperMock, mock.DALMapperMockFactory.DALAdminMapperMock); CreateResponse <ApiAdminResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.AdminModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiAdminRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Admin>())); }
public void CreatePatch() { var mapper = new ApiAdminModelMapper(); var model = new ApiAdminRequestModel(); model.SetProperties("A", "A", "A", "A", "A", "A"); JsonPatchDocument <ApiAdminRequestModel> patch = mapper.CreatePatch(model); var response = new ApiAdminRequestModel(); patch.ApplyTo(response); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Password.Should().Be("A"); response.Phone.Should().Be("A"); response.Username.Should().Be("A"); }
public void CreatePatch() { var mapper = new ApiAdminModelMapper(); var model = new ApiAdminRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); JsonPatchDocument <ApiAdminRequestModel> patch = mapper.CreatePatch(model); var response = new ApiAdminRequestModel(); patch.ApplyTo(response); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.FirstName.Should().Be("A"); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.StudioId.Should().Be(1); }
public virtual async Task <UpdateResponse <ApiAdminResponseModel> > Update( int id, ApiAdminRequestModel model) { var validationResult = await this.adminModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolAdminMapper.MapModelToBO(id, model); await this.adminRepository.Update(this.dalAdminMapper.MapBOToEF(bo)); var record = await this.adminRepository.Get(id); return(new UpdateResponse <ApiAdminResponseModel>(this.bolAdminMapper.MapBOToModel(this.dalAdminMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiAdminResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiAdminRequestModel model) { ApiAdminRequestModel request = await this.PatchModel(id, this.AdminModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiAdminResponseModel> result = await this.AdminService.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 <ApiAdminRequestModel> patch) { ApiAdminResponseModel record = await this.AdminService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiAdminRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiAdminResponseModel> result = await this.AdminService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiAdminResponseModel> > AdminUpdateAsync(int id, ApiAdminRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Admins/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiAdminResponseModel> >(httpResponse.Content.ContentToString())); }