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 ApiLinkStatusRequestModel(); createModel.SetProperties("B"); CreateResponse <ApiLinkStatusResponseModel> createResult = await client.LinkStatusCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiLinkStatusResponseModel getResponse = await client.LinkStatusGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.LinkStatusDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiLinkStatusResponseModel verifyResponse = await client.LinkStatusGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiLinkStatusResponseModel MapBOToModel( BOLinkStatus boLinkStatus) { var model = new ApiLinkStatusResponseModel(); model.SetProperties(boLinkStatus.Id, boLinkStatus.Name); return(model); }
public void MapResponseToRequest() { var mapper = new ApiLinkStatusModelMapper(); var model = new ApiLinkStatusResponseModel(); model.SetProperties(1, "A"); ApiLinkStatusRequestModel response = mapper.MapResponseToRequest(model); response.Name.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLLinkStatusMapper(); BOLinkStatus bo = new BOLinkStatus(); bo.SetProperties(1, "A"); ApiLinkStatusResponseModel response = mapper.MapBOToModel(bo); 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()); ApiLinkStatusResponseModel response = await client.LinkStatusGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiLinkStatusResponseModel response = await this.LinkStatusService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async virtual Task <IActionResult> ByName(string name) { ApiLinkStatusResponseModel response = await this.LinkStatusService.ByName(name); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiLinkStatusResponseModel model = await client.LinkStatusGetAsync(1); ApiLinkStatusModelMapper mapper = new ApiLinkStatusModelMapper(); UpdateResponse <ApiLinkStatusResponseModel> updateResponse = await client.LinkStatusUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Get_null_record() { var mock = new ServiceMockFacade <ILinkStatusRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <LinkStatus>(null)); var service = new LinkStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLinkStatusMapperMock, mock.DALMapperMockFactory.DALLinkStatusMapperMock, mock.BOLMapperMockFactory.BOLLinkMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock); ApiLinkStatusResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void ByName_Not_Exists() { var mock = new ServiceMockFacade <ILinkStatusRepository>(); mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult <LinkStatus>(null)); var service = new LinkStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLLinkStatusMapperMock, mock.DALMapperMockFactory.DALLinkStatusMapperMock, mock.BOLMapperMockFactory.BOLLinkMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock); ApiLinkStatusResponseModel response = await service.ByName(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>())); }
public async void Create_Errors() { LinkStatusControllerMockFacade mock = new LinkStatusControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiLinkStatusResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiLinkStatusResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLinkStatusRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLinkStatusResponseModel> >(mockResponse.Object)); LinkStatusController controller = new LinkStatusController(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 ApiLinkStatusRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLinkStatusRequestModel>())); }
public async void All_Exists() { LinkStatusControllerMockFacade mock = new LinkStatusControllerMockFacade(); var record = new ApiLinkStatusResponseModel(); var records = new List <ApiLinkStatusResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); LinkStatusController controller = new LinkStatusController(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 <ApiLinkStatusResponseModel>; 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 <ApiLinkStatusRequestModel> patch) { ApiLinkStatusResponseModel record = await this.LinkStatusService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiLinkStatusRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiLinkStatusResponseModel> result = await this.LinkStatusService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiLinkStatusResponseModel response = await this.Client.LinkStatusGetAsync(1); response.Should().NotBeNull(); }