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 ApiBucketRequestModel(); createModel.SetProperties(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); CreateResponse <ApiBucketResponseModel> createResult = await client.BucketCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiBucketResponseModel getResponse = await client.BucketGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.BucketDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiBucketResponseModel verifyResponse = await client.BucketGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiBucketResponseModel MapBOToModel( BOBucket boBucket) { var model = new ApiBucketResponseModel(); model.SetProperties(boBucket.Id, boBucket.ExternalId, boBucket.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiBucketModelMapper(); var model = new ApiBucketResponseModel(); model.SetProperties(1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); ApiBucketRequestModel response = mapper.MapResponseToRequest(model); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLBucketMapper(); BOBucket bo = new BOBucket(); bo.SetProperties(1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); ApiBucketResponseModel response = mapper.MapBOToModel(bo); response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Id.Should().Be(1); response.Name.Should().Be("A"); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiBucketResponseModel response = await client.BucketGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiBucketResponseModel response = await this.BucketService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByName(string name) { ApiBucketResponseModel response = await this.BucketService.ByName(name); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByExternalId(Guid externalId) { ApiBucketResponseModel response = await this.BucketService.ByExternalId(externalId); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IBucketRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Bucket>(null)); var service = new BucketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBucketMapperMock, mock.DALMapperMockFactory.DALBucketMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ApiBucketResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ByExternalId_Not_Exists() { var mock = new ServiceMockFacade <IBucketRepository>(); mock.RepositoryMock.Setup(x => x.ByExternalId(It.IsAny <Guid>())).Returns(Task.FromResult <Bucket>(null)); var service = new BucketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBucketMapperMock, mock.DALMapperMockFactory.DALBucketMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ApiBucketResponseModel response = await service.ByExternalId(default(Guid)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.ByExternalId(It.IsAny <Guid>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiBucketResponseModel model = await client.BucketGetAsync(1); ApiBucketModelMapper mapper = new ApiBucketModelMapper(); UpdateResponse <ApiBucketResponseModel> updateResponse = await client.BucketUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void ByName_Exists() { var mock = new ServiceMockFacade <IBucketRepository>(); var record = new Bucket(); mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record)); var service = new BucketService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BucketModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBucketMapperMock, mock.DALMapperMockFactory.DALBucketMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); ApiBucketResponseModel response = await service.ByName(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>())); }
public async void Create_Errors() { BucketControllerMockFacade mock = new BucketControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiBucketResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiBucketResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBucketRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBucketResponseModel> >(mockResponse.Object)); BucketController controller = new BucketController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiBucketRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBucketRequestModel>())); }
public async void All_Exists() { BucketControllerMockFacade mock = new BucketControllerMockFacade(); var record = new ApiBucketResponseModel(); var records = new List <ApiBucketResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); BucketController controller = new BucketController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiBucketResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiBucketRequestModel> patch) { ApiBucketResponseModel record = await this.BucketService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBucketRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiBucketResponseModel> result = await this.BucketService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiBucketResponseModel response = await this.Client.BucketGetAsync(1); response.Should().NotBeNull(); }