public async Task AddTechnologyReturnsBadRequest() { var entityTechnologyUrl = new EntityTechnologyUrl() { Label = "", Url = "" }; var entityTechnology = new EntityTechnology("id", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var entity = new Entity() { Technologies = new EntityTechnology[] { entityTechnology } }; var mockQueue = new Mock <IQueue>(); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "admin"), new Claim(ClaimTypes.Name, ""), new Claim(ClaimTypes.PrimaryGroupSid, "1"), })), } }; _controller.ControllerContext = context; _mockRepository.Setup(m => m.AddTechnology(It.IsAny <EntityTechnology>(), It.IsAny <string>(), _mockTechnologyRepository.Object)) .ThrowsAsync(new ArgumentException()); var result = await _controller.AddTechnology(_mockRepository.Object, mockQueue.Object, _mockTechnologyRepository.Object, entityTechnology, ""); Assert.IsType <BadRequestObjectResult>(result); }
public async Task UpdateTechnologyStatusReturnsUnauthorized() { var entityTechnologyUrl = new EntityTechnologyUrl() { Label = "", Url = "" }; var entityTechnology = new EntityTechnology("id", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var mockQueue = new Mock <IQueue>(); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "admin"), new Claim(ClaimTypes.Name, ""), new Claim(ClaimTypes.PrimaryGroupSid, "2"), })), } }; _controller.ControllerContext = context; var result = await _controller.UpdateTechnologyStatus(_mockRepository.Object, mockQueue.Object, "1", entityTechnology); Assert.IsType <UnauthorizedResult>(result); }
public async Task UpdateTechnologyStatusCallsReplaceOneReturnsNoContent() { var entityTechnologyUrl = new EntityTechnologyUrl() { Label = "", Url = "" }; var newEntityTechnologyUrl = new EntityTechnologyUrl() { Label = "label", Url = "url" }; var entityTechnology = new EntityTechnology("id", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var entity = new Entity() { Technologies = new EntityTechnology[] { entityTechnology } }; var patchedEntityTechnology = new EntityTechnology("id", "new status", new EntityTechnologyUrl[] { newEntityTechnologyUrl }); var updatedEntityTechnology = entityTechnology; updatedEntityTechnology.UpdateEntityTechnology(patchedEntityTechnology); var replaceOneResult = new ReplaceOneResult.Acknowledged(1, 1, null); var mockQueue = new Mock <IQueue>(); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "admin"), new Claim(ClaimTypes.Name, ""), new Claim(ClaimTypes.PrimaryGroupSid, "1"), })), } }; _controller.ControllerContext = context; _mockRepository.Setup(m => m.FindTechnologyByIdAsync(It.IsAny <string>(), It.IsAny <string>(), null)) .ReturnsAsync(entityTechnology); _mockRepository.Setup(m => m.FindByIdAsync(It.IsAny <string>(), null)).ReturnsAsync(entity); var result = await _controller.UpdateTechnologyStatus(_mockRepository.Object, mockQueue.Object, "1", patchedEntityTechnology); _mockRepository.Verify(m => m.UpdateEntityTechnology("1", updatedEntityTechnology)); mockQueue.Verify(m => m.PublishAsync("history", It.IsAny <string>())); Assert.IsType <NoContentResult>(result); }
public void UpdateEntityTechnologyChangesEntityTechnologyAttributes() { var entityTechnologyUrl = new EntityTechnologyUrl() { Label = "", Url = "" }; var newEntityTechnologyUrl = new EntityTechnologyUrl() { Label = "label", Url = "url" }; var entityTechnology = new EntityTechnology("id", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var updatedEntityTechnology = new EntityTechnology("id2", "status", new EntityTechnologyUrl[] { newEntityTechnologyUrl }); entityTechnology.UpdateEntityTechnology(updatedEntityTechnology); Assert.Equal(entityTechnology.Status, updatedEntityTechnology.Status); Assert.Equal(entityTechnology.EntityTechnologyUrls, updatedEntityTechnology.EntityTechnologyUrls); }
public async Task GetEntityTechnologiesByIdWithoutGroupTechnologiesReturnsOkObjectResult() { var entityTechnologyUrl = new EntityTechnologyUrl() { Label = "", Url = "" }; var entityTechnology = new EntityTechnology("id", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var entityTechnologyList = new List <EntityTechnology>() { entityTechnology }; var entityService = new EntityService(); _mockRepository.Setup(m => m.FindTechnologies(_mockTechnologyRepository.Object, "id")) .ReturnsAsync(entityTechnologyList); _mockRepository.Setup(m => m.FindTechnologies(_mockTechnologyRepository.Object, "referenceId")) .ReturnsAsync(new List <EntityTechnology>()); var result = await _controller.GetEntityTechnologies( _mockRepository.Object, _mockTechnologyRepository.Object, entityService, "id"); Assert.IsType <OkObjectResult>(result); }
public async Task AddTechnologyReturnsNoContent() { var entityTechnologyUrl = new EntityTechnologyUrl() { Label = "", Url = "" }; var entityTechnology = new EntityTechnology("id", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var newEntityTechnology = new EntityTechnology("id2", "status", new EntityTechnologyUrl[] { entityTechnologyUrl }); var updateResult = new UpdateResult.Acknowledged(1, 1, null); var entity = new Entity() { Technologies = new EntityTechnology[] { entityTechnology } }; var mockQueue = new Mock <IQueue>(); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "admin"), new Claim(ClaimTypes.Name, ""), new Claim(ClaimTypes.PrimaryGroupSid, "1"), })), } }; _controller.ControllerContext = context; _mockRepository.Setup(m => m.AddTechnology(It.IsAny <EntityTechnology>(), "id", _mockTechnologyRepository.Object)) .ReturnsAsync(updateResult); var result = await _controller.AddTechnology(_mockRepository.Object, mockQueue.Object, _mockTechnologyRepository.Object, entityTechnology, "1"); mockQueue.Verify(m => m.PublishAsync("history", It.IsAny <string>())); Assert.IsType <NoContentResult>(result); }