public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; ITestAllFieldTypeService service = testServer.Host.Services.GetService(typeof(ITestAllFieldTypeService)) as ITestAllFieldTypeService; var model = new ApiTestAllFieldTypeServerRequestModel(); 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, 2, BitConverter.GetBytes(2), 2m, "B", "B", 2m, "B", 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B", TimeSpan.Parse("02:00:00"), BitConverter.GetBytes(2), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), BitConverter.GetBytes(2), "B", "B"); CreateResponse <ApiTestAllFieldTypeServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.TestAllFieldTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiTestAllFieldTypeServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public virtual async Task <IActionResult> Create([FromBody] ApiTestAllFieldTypeServerRequestModel model) { CreateResponse <ApiTestAllFieldTypeServerResponseModel> 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 <ApiTestAllFieldTypeServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiTestAllFieldTypeServerRequestModel> patch) { var record = await this.TestAllFieldTypeService.Get(id); if (record == null) { return(null); } else { ApiTestAllFieldTypeServerRequestModel request = this.TestAllFieldTypeModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ITestAllFieldTypeService, ITestAllFieldTypeRepository>(); var model = new ApiTestAllFieldTypeServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new TestAllFieldTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Object, mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TestAllFieldTypeDeletedNotification>(), It.IsAny <CancellationToken>())); }
public void CreatePatch() { var mapper = new ApiTestAllFieldTypeServerModelMapper(); var model = new ApiTestAllFieldTypeServerRequestModel(); 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, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("01:00:00"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A"); JsonPatchDocument <ApiTestAllFieldTypeServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiTestAllFieldTypeServerRequestModel(); 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(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("01:00:00")); 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] ApiTestAllFieldTypeServerRequestModel model) { ApiTestAllFieldTypeServerRequestModel request = await this.PatchModel(id, this.TestAllFieldTypeModelMapper.CreatePatch(model)) as ApiTestAllFieldTypeServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiTestAllFieldTypeServerResponseModel> result = await this.TestAllFieldTypeService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ITestAllFieldTypeService, ITestAllFieldTypeRepository>(); var model = new ApiTestAllFieldTypeServerRequestModel(); var validatorMock = new Mock <IApiTestAllFieldTypeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new TestAllFieldTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TestAllFieldTypeDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTestAllFieldTypeServerRequestModel> patch) { ApiTestAllFieldTypeServerResponseModel record = await this.TestAllFieldTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiTestAllFieldTypeServerRequestModel model = await this.PatchModel(id, patch) as ApiTestAllFieldTypeServerRequestModel; UpdateResponse <ApiTestAllFieldTypeServerResponseModel> result = await this.TestAllFieldTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }