public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ILocationService, ILocationRepository>(); var model = new ApiLocationServerRequestModel(); var validatorMock = new Mock <IApiLocationServerRequestModelValidator>(); 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 LocationService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALLocationMapperMock, mock.DALMapperMockFactory.DALTweetMapperMock, mock.DALMapperMockFactory.DALUserMapperMock); 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 <LocationDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
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; ILocationService service = testServer.Host.Services.GetService(typeof(ILocationService)) as ILocationService; var model = new ApiLocationServerRequestModel(); model.SetProperties(2, 2, "B"); CreateResponse <ApiLocationServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.LocationDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiLocationServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public virtual async Task <IActionResult> Create([FromBody] ApiLocationServerRequestModel model) { CreateResponse <ApiLocationServerResponseModel> result = await this.LocationService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Locations/{result.Record.LocationId}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapServerResponseToRequest() { var mapper = new ApiLocationServerModelMapper(); var model = new ApiLocationServerResponseModel(); model.SetProperties(1, 1, 1, "A"); ApiLocationServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.GpsLat.Should().Be(1); response.GpsLong.Should().Be(1); response.LocationName.Should().Be("A"); }
private async Task <ApiLocationServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiLocationServerRequestModel> patch) { var record = await this.LocationService.Get(id); if (record == null) { return(null); } else { ApiLocationServerRequestModel request = this.LocationModelMapper.MapServerResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void CreatePatch() { var mapper = new ApiLocationServerModelMapper(); var model = new ApiLocationServerRequestModel(); model.SetProperties(1, 1, "A"); JsonPatchDocument <ApiLocationServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiLocationServerRequestModel(); patch.ApplyTo(response); response.GpsLat.Should().Be(1); response.GpsLong.Should().Be(1); response.LocationName.Should().Be("A"); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiLocationServerRequestModel model) { ApiLocationServerRequestModel request = await this.PatchModel(id, this.LocationModelMapper.CreatePatch(model)) as ApiLocationServerRequestModel; if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiLocationServerResponseModel> result = await this.LocationService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ILocationService, ILocationRepository>(); var model = new ApiLocationServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new LocationService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object, mock.DALMapperMockFactory.DALLocationMapperMock, mock.DALMapperMockFactory.DALTweetMapperMock, mock.DALMapperMockFactory.DALUserMapperMock); 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.LocationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LocationDeletedNotification>(), It.IsAny <CancellationToken>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiLocationServerRequestModel> patch) { ApiLocationServerResponseModel record = await this.LocationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiLocationServerRequestModel model = await this.PatchModel(id, patch) as ApiLocationServerRequestModel; UpdateResponse <ApiLocationServerResponseModel> result = await this.LocationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }