public virtual ApiKeyAllocationResponseModel MapBOToModel( BOKeyAllocation boKeyAllocation) { var model = new ApiKeyAllocationResponseModel(); model.SetProperties(boKeyAllocation.CollectionName, boKeyAllocation.Allocated); return(model); }
public void MapResponseToRequest() { var mapper = new ApiKeyAllocationModelMapper(); var model = new ApiKeyAllocationResponseModel(); model.SetProperties("A", 1); ApiKeyAllocationRequestModel response = mapper.MapResponseToRequest(model); response.Allocated.Should().Be(1); }
public void MapBOToModel() { var mapper = new BOLKeyAllocationMapper(); BOKeyAllocation bo = new BOKeyAllocation(); bo.SetProperties("A", 1); ApiKeyAllocationResponseModel response = mapper.MapBOToModel(bo); response.Allocated.Should().Be(1); response.CollectionName.Should().Be("A"); }
public async virtual Task <IActionResult> Get(string id) { ApiKeyAllocationResponseModel response = await this.KeyAllocationService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IKeyAllocationRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <KeyAllocation>(null)); var service = new KeyAllocationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.KeyAllocationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLKeyAllocationMapperMock, mock.DALMapperMockFactory.DALKeyAllocationMapperMock); ApiKeyAllocationResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public async void Create_Errors() { KeyAllocationControllerMockFacade mock = new KeyAllocationControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiKeyAllocationResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiKeyAllocationResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiKeyAllocationRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiKeyAllocationResponseModel> >(mockResponse.Object)); KeyAllocationController controller = new KeyAllocationController(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 ApiKeyAllocationRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiKeyAllocationRequestModel>())); }
public async void All_Exists() { KeyAllocationControllerMockFacade mock = new KeyAllocationControllerMockFacade(); var record = new ApiKeyAllocationResponseModel(); var records = new List <ApiKeyAllocationResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); KeyAllocationController controller = new KeyAllocationController(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 <ApiKeyAllocationResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiKeyAllocationRequestModel> patch) { ApiKeyAllocationResponseModel record = await this.KeyAllocationService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiKeyAllocationRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiKeyAllocationResponseModel> result = await this.KeyAllocationService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiKeyAllocationResponseModel response = await this.Client.KeyAllocationGetAsync("A"); response.Should().NotBeNull(); }