public virtual ApiArtifactResponseModel MapBOToModel( BOArtifact boArtifact) { var model = new ApiArtifactResponseModel(); model.SetProperties(boArtifact.Id, boArtifact.Created, boArtifact.EnvironmentId, boArtifact.Filename, boArtifact.JSON, boArtifact.ProjectId, boArtifact.RelatedDocumentIds, boArtifact.TenantId); return(model); }
public async virtual Task <IActionResult> Get(string id) { ApiArtifactResponseModel response = await this.ArtifactService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapResponseToRequest() { var mapper = new ApiArtifactModelMapper(); var model = new ApiArtifactResponseModel(); model.SetProperties("A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", "A"); ApiArtifactRequestModel response = mapper.MapResponseToRequest(model); response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.EnvironmentId.Should().Be("A"); response.Filename.Should().Be("A"); response.JSON.Should().Be("A"); response.ProjectId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.TenantId.Should().Be("A"); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IArtifactRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Artifact>(null)); var service = new ArtifactService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ArtifactModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLArtifactMapperMock, mock.DALMapperMockFactory.DALArtifactMapperMock); ApiArtifactResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public void MapBOToModel() { var mapper = new BOLArtifactMapper(); BOArtifact bo = new BOArtifact(); bo.SetProperties("A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", "A"); ApiArtifactResponseModel response = mapper.MapBOToModel(bo); response.Created.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.EnvironmentId.Should().Be("A"); response.Filename.Should().Be("A"); response.Id.Should().Be("A"); response.JSON.Should().Be("A"); response.ProjectId.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.TenantId.Should().Be("A"); }
public async void Create_Errors() { ArtifactControllerMockFacade mock = new ArtifactControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiArtifactResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiArtifactResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiArtifactRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiArtifactResponseModel> >(mockResponse.Object)); ArtifactController controller = new ArtifactController(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 ApiArtifactRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiArtifactRequestModel>())); }
public async void All_Exists() { ArtifactControllerMockFacade mock = new ArtifactControllerMockFacade(); var record = new ApiArtifactResponseModel(); var records = new List <ApiArtifactResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ArtifactController controller = new ArtifactController(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 <ApiArtifactResponseModel>; 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 <ApiArtifactRequestModel> patch) { ApiArtifactResponseModel record = await this.ArtifactService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiArtifactRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiArtifactResponseModel> result = await this.ArtifactService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async void TestGet() { ApiArtifactResponseModel response = await this.Client.ArtifactGetAsync("A"); response.Should().NotBeNull(); }