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 ApiTestAllFieldTypeRequestModel(); 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 <ApiTestAllFieldTypeResponseModel> createResult = await client.TestAllFieldTypeCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiTestAllFieldTypeResponseModel getResponse = await client.TestAllFieldTypeGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.TestAllFieldTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTestAllFieldTypeResponseModel verifyResponse = await client.TestAllFieldTypeGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTestAllFieldTypeRequestModel 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)); }
private async Task <ApiTestAllFieldTypeResponseModel> CreateRecord(ApiClient client) { var model = new ApiTestAllFieldTypeRequestModel(); 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"), 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 <ApiTestAllFieldTypeResponseModel> result = await client.TestAllFieldTypeCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiTestAllFieldTypeRequestModel model) { CreateResponse <ApiTestAllFieldTypeResponseModel> result = await this.TestAllFieldTypeService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TestAllFieldTypes/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiTestAllFieldTypeRequestModel> PatchModel(int id, JsonPatchDocument <ApiTestAllFieldTypeRequestModel> patch) { var record = await this.TestAllFieldTypeService.Get(id); if (record == null) { return(null); } else { ApiTestAllFieldTypeRequestModel request = this.TestAllFieldTypeModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiTestAllFieldTypeResponseModel> > Create( ApiTestAllFieldTypeRequestModel model) { CreateResponse <ApiTestAllFieldTypeResponseModel> response = new CreateResponse <ApiTestAllFieldTypeResponseModel>(await this.TestAllFieldTypeModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolTestAllFieldTypeMapper.MapModelToBO(default(int), model); var record = await this.TestAllFieldTypeRepository.Create(this.DalTestAllFieldTypeMapper.MapBOToEF(bo)); response.SetRecord(this.BolTestAllFieldTypeMapper.MapBOToModel(this.DalTestAllFieldTypeMapper.MapEFToBO(record))); } return(response); }
public async void Create() { var mock = new ServiceMockFacade <ITestAllFieldTypeRepository>(); var model = new ApiTestAllFieldTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TestAllFieldType>())).Returns(Task.FromResult(new TestAllFieldType())); var service = new TestAllFieldTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTestAllFieldTypeMapperMock, mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock); CreateResponse <ApiTestAllFieldTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTestAllFieldTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TestAllFieldType>())); }
public async void Delete() { var mock = new ServiceMockFacade <ITestAllFieldTypeRepository>(); var model = new ApiTestAllFieldTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TestAllFieldTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTestAllFieldTypeMapperMock, mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiTestAllFieldTypeResponseModel> > Update( int id, ApiTestAllFieldTypeRequestModel model) { var validationResult = await this.TestAllFieldTypeModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolTestAllFieldTypeMapper.MapModelToBO(id, model); await this.TestAllFieldTypeRepository.Update(this.DalTestAllFieldTypeMapper.MapBOToEF(bo)); var record = await this.TestAllFieldTypeRepository.Get(id); return(new UpdateResponse <ApiTestAllFieldTypeResponseModel>(this.BolTestAllFieldTypeMapper.MapBOToModel(this.DalTestAllFieldTypeMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiTestAllFieldTypeResponseModel>(validationResult)); } }
public void CreatePatch() { var mapper = new ApiTestAllFieldTypeModelMapper(); var model = new ApiTestAllFieldTypeRequestModel(); 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"), 1, 1, 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 <ApiTestAllFieldTypeRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTestAllFieldTypeRequestModel(); 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(1); response.FieldFloat.Should().Be(1); 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] ApiTestAllFieldTypeRequestModel model) { ApiTestAllFieldTypeRequestModel request = await this.PatchModel(id, this.TestAllFieldTypeModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTestAllFieldTypeResponseModel> result = await this.TestAllFieldTypeService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual BOTestAllFieldType MapModelToBO( int id, ApiTestAllFieldTypeRequestModel model ) { BOTestAllFieldType boTestAllFieldType = new BOTestAllFieldType(); boTestAllFieldType.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(boTestAllFieldType); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTestAllFieldTypeRequestModel> patch) { ApiTestAllFieldTypeResponseModel record = await this.TestAllFieldTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTestAllFieldTypeRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiTestAllFieldTypeResponseModel> result = await this.TestAllFieldTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiTestAllFieldTypeResponseModel> > TestAllFieldTypeUpdateAsync(int id, ApiTestAllFieldTypeRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/TestAllFieldTypes/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiTestAllFieldTypeResponseModel> >(httpResponse.Content.ContentToString())); }