public virtual ApiApiKeyResponseModel MapBOToModel( BOApiKey boApiKey) { var model = new ApiApiKeyResponseModel(); model.SetProperties(boApiKey.Id, boApiKey.ApiKeyHashed, boApiKey.Created, boApiKey.JSON, boApiKey.UserId); return(model); }
public void MapResponseToRequest() { var mapper = new ApiApiKeyModelMapper(); var model = new ApiApiKeyResponseModel(); model.SetProperties("A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A"); ApiApiKeyRequestModel response = mapper.MapResponseToRequest(model); response.ApiKeyHashed.Should().Be("A"); response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.JSON.Should().Be("A"); response.UserId.Should().Be("A"); }
public async virtual Task <IActionResult> Get(string id) { ApiApiKeyResponseModel response = await this.ApiKeyService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapBOToModel() { var mapper = new BOLApiKeyMapper(); BOApiKey bo = new BOApiKey(); bo.SetProperties("A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A"); ApiApiKeyResponseModel response = mapper.MapBOToModel(bo); response.ApiKeyHashed.Should().Be("A"); response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be("A"); response.JSON.Should().Be("A"); response.UserId.Should().Be("A"); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IApiKeyRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ApiKey>(null)); var service = new ApiKeyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLApiKeyMapperMock, mock.DALMapperMockFactory.DALApiKeyMapperMock); ApiApiKeyResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public async void ByApiKeyHashed_Exists() { var mock = new ServiceMockFacade <IApiKeyRepository>(); var record = new ApiKey(); mock.RepositoryMock.Setup(x => x.ByApiKeyHashed(It.IsAny <string>())).Returns(Task.FromResult(record)); var service = new ApiKeyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ApiKeyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLApiKeyMapperMock, mock.DALMapperMockFactory.DALApiKeyMapperMock); ApiApiKeyResponseModel response = await service.ByApiKeyHashed(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.ByApiKeyHashed(It.IsAny <string>())); }
public async void Create_Errors() { ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiApiKeyResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiApiKeyResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiApiKeyRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiApiKeyResponseModel> >(mockResponse.Object)); ApiKeyController controller = new ApiKeyController(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 ApiApiKeyRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiApiKeyRequestModel>())); }
public async void All_Exists() { ApiKeyControllerMockFacade mock = new ApiKeyControllerMockFacade(); var record = new ApiApiKeyResponseModel(); var records = new List <ApiApiKeyResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ApiKeyController controller = new ApiKeyController(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 <ApiApiKeyResponseModel>; 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 <ApiApiKeyRequestModel> patch) { ApiApiKeyResponseModel record = await this.ApiKeyService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiApiKeyRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiApiKeyResponseModel> result = await this.ApiKeyService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiApiKeyResponseModel response = await this.Client.ApiKeyGetAsync("A"); response.Should().NotBeNull(); }