public void ShouldGetDocumentById() { var testDocument = MakeNew(1); var response = _docsController.Create(testDocument); var result = Assert.IsType <OkObjectResult>(response.Result); Assert.NotNull(result.Value); var newDocument = Assert.IsType <Document>(result.Value); Assert.Null(newDocument.FirstReadTime); response = _docsController.Get(newDocument.Id); result = Assert.IsType <OkObjectResult>(response.Result); Assert.NotNull(result.Value); var document = Assert.IsType <Document>(result.Value); Assert.Equal(newDocument.Id, document.Id); Assert.Equal(testDocument.Title, document.Title); Assert.Equal(testDocument.Author, document.Author); Assert.NotNull(document.FirstReadTime); var testFirstTime = document.FirstReadTime; response = _docsController.Get(newDocument.Id); result = Assert.IsType <OkObjectResult>(response.Result); Assert.NotNull(result.Value); document = Assert.IsType <Document>(result.Value); Assert.Equal(testFirstTime, document.FirstReadTime); }
public void getDocumentTest() { var result = docController.Get().ToArray <dynamic>(); Assert.True(result[0].GetType().GetProperty("Name").GetValue(result[0], null) == "Test File.pdf"); Assert.True(result[0].GetType().GetProperty("Location").GetValue(result[0], null) == "/api/documents/Test File.pdf"); Assert.True(result[0].GetType().GetProperty("Size").GetValue(result[0], null) == 100); }
public void GetReturnsListOfDocuments() { //Arrange var moq = new Mock <IDocumentsRepository>(); moq.Setup(m => m.Get()).Returns(Task.FromResult(new List <Document>() as IEnumerable <Document>)); DocumentsController controller = new DocumentsController(moq.Object); //Act var result = controller.Get().Result; //Assert Assert.IsInstanceOfType(result, typeof(IEnumerable <Document>)); }
public async Task TestGetNotFoundResult() { //Arrange var documentId = Guid.Empty; var getDocumentById = new DocumentRepository.GetDocumentById(_ => Task.FromResult(Option <DocumentDatabaseDto> .None)); _documentsController = new DocumentsController(TestHelper.ValidReadEventsFunc(), TestHelper.SaveAndPublish, DocumentExistsByNumber, getDocumentById, TestHelper.GetCurrentUserId()); // Act var actionResult = await _documentsController.Get(documentId); // Assert var notFoundResult = actionResult as NotFoundResult; Assert.NotNull(notFoundResult); }
public async Task TestGetOkResult() { //Arrange var documentId = Guid.NewGuid(); _documentsController = new DocumentsController(TestHelper.ValidReadEventsFunc(), TestHelper.SaveAndPublish, DocumentExistsByNumber, TestHelper.GetDocumentById(), TestHelper.GetCurrentUserId()); // Act var actionResult = await _documentsController.Get(documentId); // Assert var okResult = actionResult as OkObjectResult; var document = okResult?.Value as Document; Assert.NotNull(okResult); Assert.NotNull(document); Assert.Equal(documentId, document.Id); }
public void GetIdReurnsDocument() { //Arrange var moq = new Mock <IDocumentsRepository>(); moq.Setup(m => m.Get(It.IsAny <object[]>())).Returns <object[]>(id => Task.FromResult(new Document { Id = (long)id[0] })); DocumentsController controller = new DocumentsController(moq.Object); long documentId = 2; //Act var result = controller.Get(documentId).Result; //Assert Assert.IsInstanceOfType(result, typeof(Document)); Assert.AreEqual(result.Id, documentId); }
public async Task GetAllDocumentsHttpStatusOkTest() { var actual = await _documentsController.Get() as OkObjectResult; actual.StatusCode.Should().Equals(200); }