public void GetDocument_ReturnsCorrectDocument() { var document = _context.Documents.SingleOrDefault(x => x.Description == "Doc1"); Assert.IsNotNull(document); var result = _controller.GetDocument(document.Id); Assert.AreEqual(document.Url, result.Url); }
public async void GetDocumentWithIncorrectIdReturnsNotFound() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentsController(context, _mapper)) { var result = await controller.GetDocument(999); Assert.IsType <NotFoundResult>(result); } }
public async Task GetDocument_Success() { //Arrange------------------------------------------------------------------------------------------------------------------------------ _mockRepo.Setup(x => x.DocumentRepository.GetByIdAsync(It.IsAny <string>())) .ReturnsAsync(UnitTestsDataInput.Users.First().Documents.First()); _mockMapper.Setup(x => x.Map <DocumentForReturnDto>(It.IsAny <Document>())) .Returns(new DocumentForReturnDto()); var rout = new RouteData(); rout.Values.Add("userId", UnitTestsDataInput.userLogedInId); var claims = new[] { new Claim(ClaimTypes.NameIdentifier, UnitTestsDataInput.userLogedInId), }; var identity = new ClaimsIdentity(claims); var claimsPrincipal = new ClaimsPrincipal(identity); var mockContext = new Mock <HttpContext>(); mockContext.SetupGet(x => x.User).Returns(claimsPrincipal); _controller.ControllerContext = new ControllerContext { HttpContext = mockContext.Object, RouteData = rout }; //Act---------------------------------------------------------------------------------------------------------------------------------- var result = await _controller.GetDocument(It.IsAny <string>(), It.IsAny <string>()); var okResult = result as OkObjectResult; //Assert------------------------------------------------------------------------------------------------------------------------------- Assert.NotNull(okResult); Assert.IsType <DocumentForReturnDto>(okResult.Value); Assert.Equal(200, okResult.StatusCode); }
public async void GetDocumentModelStateErrorReturnsBadRequest() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentsController(context, _mapper)) { controller.ModelState.AddModelError("an error", "some error"); var result = await controller.GetDocument(1); Assert.IsType <BadRequestObjectResult>(result); } }
public async void GetDocumentByIdReturnsSingleDocument() { using (var context = DbTestContext.GenerateContextWithData()) using (var controller = new DocumentsController(context, _mapper)) { var result = await controller.GetDocument(3); var okObjectResult = Assert.IsType <OkObjectResult>(result); var resultValue = okObjectResult.Value; DocumentDto a3 = GetTestDocumentDtoFromContext(3); Assert.NotNull(resultValue); Assert.IsType <DocumentDto>(resultValue); DocumentDto a = (DocumentDto)resultValue; Assert.True(a.Equals(a3)); Assert.True(a.Equals(a3, true)); } }