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 ApiDeviceActionRequestModel(); createModel.SetProperties(1, "B", "B"); CreateResponse <ApiDeviceActionResponseModel> createResult = await client.DeviceActionCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiDeviceActionResponseModel getResponse = await client.DeviceActionGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.DeviceActionDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiDeviceActionResponseModel verifyResponse = await client.DeviceActionGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiDeviceActionResponseModel MapBOToModel( BODeviceAction boDeviceAction) { var model = new ApiDeviceActionResponseModel(); model.SetProperties(boDeviceAction.Id, boDeviceAction.DeviceId, boDeviceAction.Name, boDeviceAction.@Value); return(model); }
public void MapResponseToRequest() { var mapper = new ApiDeviceActionModelMapper(); var model = new ApiDeviceActionResponseModel(); model.SetProperties(1, 1, "A", "A"); ApiDeviceActionRequestModel response = mapper.MapResponseToRequest(model); response.DeviceId.Should().Be(1); response.Name.Should().Be("A"); [email protected]().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()); ApiDeviceActionResponseModel response = await client.DeviceActionGetAsync(1); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(int id) { ApiDeviceActionResponseModel response = await this.DeviceActionService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapBOToModel() { var mapper = new BOLDeviceActionMapper(); BODeviceAction bo = new BODeviceAction(); bo.SetProperties(1, 1, "A", "A"); ApiDeviceActionResponseModel response = mapper.MapBOToModel(bo); response.DeviceId.Should().Be(1); response.Id.Should().Be(1); response.Name.Should().Be("A"); [email protected]().Be("A"); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IDeviceActionRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <DeviceAction>(null)); var service = new DeviceActionService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DeviceActionModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLDeviceActionMapperMock, mock.DALMapperMockFactory.DALDeviceActionMapperMock); ApiDeviceActionResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiDeviceActionResponseModel model = await client.DeviceActionGetAsync(1); ApiDeviceActionModelMapper mapper = new ApiDeviceActionModelMapper(); UpdateResponse <ApiDeviceActionResponseModel> updateResponse = await client.DeviceActionUpdateAsync(model.Id, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { DeviceActionControllerMockFacade mock = new DeviceActionControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiDeviceActionResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiDeviceActionResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiDeviceActionRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiDeviceActionResponseModel> >(mockResponse.Object)); DeviceActionController controller = new DeviceActionController(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 ApiDeviceActionRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDeviceActionRequestModel>())); }
public async void All_Exists() { DeviceActionControllerMockFacade mock = new DeviceActionControllerMockFacade(); var record = new ApiDeviceActionResponseModel(); var records = new List <ApiDeviceActionResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); DeviceActionController controller = new DeviceActionController(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 <ApiDeviceActionResponseModel>; 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 <ApiDeviceActionRequestModel> patch) { ApiDeviceActionResponseModel record = await this.DeviceActionService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiDeviceActionRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiDeviceActionResponseModel> result = await this.DeviceActionService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiDeviceActionResponseModel response = await this.Client.DeviceActionGetAsync(1); response.Should().NotBeNull(); }