public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTestAllFieldTypesNullableRequestModel model) { this.FieldBigIntRules(); this.FieldBinaryRules(); this.FieldBitRules(); this.FieldCharRules(); this.FieldDateRules(); this.FieldDateTimeRules(); this.FieldDateTime2Rules(); this.FieldDateTimeOffsetRules(); this.FieldDecimalRules(); this.FieldFloatRules(); this.FieldImageRules(); this.FieldMoneyRules(); this.FieldNCharRules(); this.FieldNTextRules(); this.FieldNumericRules(); this.FieldNVarcharRules(); this.FieldRealRules(); this.FieldSmallDateTimeRules(); this.FieldSmallIntRules(); this.FieldSmallMoneyRules(); this.FieldTextRules(); this.FieldTimeRules(); this.FieldTimestampRules(); this.FieldTinyIntRules(); this.FieldUniqueIdentifierRules(); this.FieldVarBinaryRules(); this.FieldVarcharRules(); this.FieldXMLRules(); return(await this.ValidateAsync(model, id)); }
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 ApiTestAllFieldTypesNullableRequestModel(); createModel.SetProperties(2, BitConverter.GetBytes(2), true, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), 2, 2, BitConverter.GetBytes(2), 2m, "B", "B", 2m, "B", 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B", TimeSpan.Parse("1"), BitConverter.GetBytes(2), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), BitConverter.GetBytes(2), "B", "B"); CreateResponse <ApiTestAllFieldTypesNullableResponseModel> createResult = await client.TestAllFieldTypesNullableCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTestAllFieldTypesNullableResponseModel getResponse = await client.TestAllFieldTypesNullableGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TestAllFieldTypesNullableDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTestAllFieldTypesNullableResponseModel verifyResponse = await client.TestAllFieldTypesNullableGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task<ApiTestAllFieldTypesNullableResponseModel> CreateRecord() { var model = new ApiTestAllFieldTypesNullableRequestModel(); model.SetProperties(2, BitConverter.GetBytes(2), true, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), 2m, 2m, BitConverter.GetBytes(2), 2m, "B", "B", 2m, "B", 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B", TimeSpan.Parse("1"), BitConverter.GetBytes(2), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), BitConverter.GetBytes(2), "B", "B"); CreateResponse<ApiTestAllFieldTypesNullableResponseModel> result = await this.Client.TestAllFieldTypesNullableCreateAsync(model); result.Success.Should().BeTrue(); return result.Record; }
public virtual async Task <IActionResult> Create([FromBody] ApiTestAllFieldTypesNullableRequestModel model) { CreateResponse <ApiTestAllFieldTypesNullableResponseModel> result = await this.TestAllFieldTypesNullableService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TestAllFieldTypesNullables/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiTestAllFieldTypesNullableRequestModel> PatchModel(int id, JsonPatchDocument <ApiTestAllFieldTypesNullableRequestModel> patch) { var record = await this.TestAllFieldTypesNullableService.Get(id); if (record == null) { return(null); } else { ApiTestAllFieldTypesNullableRequestModel request = this.TestAllFieldTypesNullableModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiTestAllFieldTypesNullableResponseModel> > Create( ApiTestAllFieldTypesNullableRequestModel model) { CreateResponse <ApiTestAllFieldTypesNullableResponseModel> response = new CreateResponse <ApiTestAllFieldTypesNullableResponseModel>(await this.testAllFieldTypesNullableModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolTestAllFieldTypesNullableMapper.MapModelToBO(default(int), model); var record = await this.testAllFieldTypesNullableRepository.Create(this.dalTestAllFieldTypesNullableMapper.MapBOToEF(bo)); response.SetRecord(this.bolTestAllFieldTypesNullableMapper.MapBOToModel(this.dalTestAllFieldTypesNullableMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <ITestAllFieldTypesNullableRepository>(); var model = new ApiTestAllFieldTypesNullableRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TestAllFieldTypesNullable>())).Returns(Task.FromResult(new TestAllFieldTypesNullable())); var service = new TestAllFieldTypesNullableService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TestAllFieldTypesNullableModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTestAllFieldTypesNullableMapperMock, mock.DALMapperMockFactory.DALTestAllFieldTypesNullableMapperMock); CreateResponse <ApiTestAllFieldTypesNullableResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TestAllFieldTypesNullableModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTestAllFieldTypesNullableRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TestAllFieldTypesNullable>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITestAllFieldTypesNullableRepository>(); var model = new ApiTestAllFieldTypesNullableRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TestAllFieldTypesNullableService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TestAllFieldTypesNullableModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTestAllFieldTypesNullableMapperMock, mock.DALMapperMockFactory.DALTestAllFieldTypesNullableMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TestAllFieldTypesNullableModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiTestAllFieldTypesNullableResponseModel> > Update( int id, ApiTestAllFieldTypesNullableRequestModel model) { var validationResult = await this.testAllFieldTypesNullableModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolTestAllFieldTypesNullableMapper.MapModelToBO(id, model); await this.testAllFieldTypesNullableRepository.Update(this.dalTestAllFieldTypesNullableMapper.MapBOToEF(bo)); var record = await this.testAllFieldTypesNullableRepository.Get(id); return(new UpdateResponse <ApiTestAllFieldTypesNullableResponseModel>(this.bolTestAllFieldTypesNullableMapper.MapBOToModel(this.dalTestAllFieldTypesNullableMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTestAllFieldTypesNullableResponseModel>(validationResult)); } }
public void CreatePatch() { var mapper = new ApiTestAllFieldTypesNullableModelMapper(); var model = new ApiTestAllFieldTypesNullableRequestModel(); model.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1m, 1m, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A"); JsonPatchDocument <ApiTestAllFieldTypesNullableRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTestAllFieldTypesNullableRequestModel(); patch.ApplyTo(response); response.FieldBigInt.Should().Be(1); response.FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldBit.Should().Be(true); response.FieldChar.Should().Be("A"); response.FieldDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldDateTime2.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.FieldDecimal.Should().Be(1m); response.FieldFloat.Should().Be(1m); response.FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldMoney.Should().Be(1m); response.FieldNChar.Should().Be("A"); response.FieldNText.Should().Be("A"); response.FieldNumeric.Should().Be(1m); response.FieldNVarchar.Should().Be("A"); response.FieldReal.Should().Be(1m); response.FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldSmallInt.Should().Be(1); response.FieldSmallMoney.Should().Be(1m); response.FieldText.Should().Be("A"); response.FieldTime.Should().Be(TimeSpan.Parse("0")); response.FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldTinyInt.Should().Be(1); response.FieldUniqueIdentifier.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldVarchar.Should().Be("A"); response.FieldXML.Should().Be("A"); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTestAllFieldTypesNullableRequestModel model) { ApiTestAllFieldTypesNullableRequestModel request = await this.PatchModel(id, this.TestAllFieldTypesNullableModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTestAllFieldTypesNullableResponseModel> result = await this.TestAllFieldTypesNullableService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual BOTestAllFieldTypesNullable MapModelToBO( int id, ApiTestAllFieldTypesNullableRequestModel model ) { BOTestAllFieldTypesNullable boTestAllFieldTypesNullable = new BOTestAllFieldTypesNullable(); boTestAllFieldTypesNullable.SetProperties( id, model.FieldBigInt, model.FieldBinary, model.FieldBit, model.FieldChar, model.FieldDate, model.FieldDateTime, model.FieldDateTime2, model.FieldDateTimeOffset, model.FieldDecimal, model.FieldFloat, model.FieldImage, model.FieldMoney, model.FieldNChar, model.FieldNText, model.FieldNumeric, model.FieldNVarchar, model.FieldReal, model.FieldSmallDateTime, model.FieldSmallInt, model.FieldSmallMoney, model.FieldText, model.FieldTime, model.FieldTimestamp, model.FieldTinyInt, model.FieldUniqueIdentifier, model.FieldVarBinary, model.FieldVarchar, model.FieldXML); return(boTestAllFieldTypesNullable); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTestAllFieldTypesNullableRequestModel> patch) { ApiTestAllFieldTypesNullableResponseModel record = await this.TestAllFieldTypesNullableService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTestAllFieldTypesNullableRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTestAllFieldTypesNullableResponseModel> result = await this.TestAllFieldTypesNullableService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiTestAllFieldTypesNullableResponseModel> > TestAllFieldTypesNullableUpdateAsync(int id, ApiTestAllFieldTypesNullableRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/TestAllFieldTypesNullables/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiTestAllFieldTypesNullableResponseModel> >(httpResponse.Content.ContentToString())); }