public void GetNotExisiting_ShouldReturn404() { var controller = new DocsController(new DocumentContext()); var result = (StatusCodeResult)controller.Get(9); Assert.Equal(404, result.StatusCode); }
public void Delete_CreatedDocument() { var controller = new DocsController(new DocumentContext()); ContentResult result = (ContentResult)controller.Create(new Document(postBase64)); //Gets id from the newly created document int id = int.Parse(result.Content); //Checks if the document was added var getResult1 = (ObjectResult)controller.Get(); Assert.Equal(1, getResult1.Value); //Check swagger compliance var msg = (NoContentResult)controller.Delete(id); Assert.Equal(204, msg.StatusCode); //Checks if the document was removed var getResult0 = (ObjectResult)controller.Get(); Assert.Equal(0, getResult0.Value); }
public void GetAll_ShouldReturnNoContentResult() { var controller = new DocsController(new DocumentContext()); var result = (ObjectResult)controller.Get(); Assert.Equal(0, result.Value); }
public void PostInvalid_ShouldReturn501() { var controller = new DocsController(new DocumentContext()); ContentResult result = (ContentResult)controller.Create(new Document("asd")); var id = int.Parse(result.Content); Thread.Sleep(2000); var getResult = (StatusCodeResult)controller.Get(id); Assert.Equal(501, getResult.StatusCode); }
public void Post_ShouldCreateDocument() { var controller = new DocsController(new DocumentContext()); ContentResult result = (ContentResult)controller.Create(new Document(postBase64)); //Gets id from the newly created document var id = int.Parse(result.Content); //Sleep while another thread is doing the work Thread.Sleep(10000); //Gets content of Get Response var content = (ObjectResult)controller.Get(id); var document = (Document)content.Value; //Assure the base64 content was correct transfered Assert.Equal(document.Content, postBase64); }
public void TestDeleteFile() { // arrange // create mock var mockDocRepo = new Mock <IDocRepository>(); mockDocRepo.Setup(x => x.RemoveDoc(@"C:\Users\adils\source\repos\PDFService\PDFService\202000215104.pdf")).Returns(true); var docsController = new DocsController(mockDocRepo.Object); // Act var result = docsController.DeleteDoc(@"C:\Users\adils\source\repos\PDFService\PDFService\202000215104.pdf"); // Assert // it should return null as the provided location should be deleted by then. Assert.AreEqual(null, result.Value); }
public void TestDownloadFile() { // arrange // create mock var mockDocRepo = new Mock <IDocRepository>(); // Need to pass a binary value constructer otherwise it will fail when trying to dowload the file byte[] content = Encoding.ASCII.GetBytes("0x255044462D312E320A25E2E3CFD30A322030206F626A3C3C2F526563745B302030203020305D2F502033203020522F46542F5369672F46203133322F537562747970652F5769646765742F562031203020522F547970652F416E6E6F742F5428BEDEC74730155166B055293E3E0A656E646F626A0A312030206F626A3C3C2F4C"); mockDocRepo.Setup(x => x.GetDoc(@"C:\Users\adils\source\repos\PDFService\PDFService\202000215104.pdf")).Returns(new Doc() { Id = 4, Name = "202000215104.pdf", Data = content }); var docsController = new DocsController(mockDocRepo.Object); // Act var result = docsController.GetDoc(@"C:\Users\adils\source\repos\PDFService\PDFService\202000215104.pdf"); // Assert HttpResponseMessage response = new HttpResponseMessage(); // set response to OK response.StatusCode = System.Net.HttpStatusCode.OK; // set to BadRequest //response.StatusCode = System.Net.HttpStatusCode.BadRequest; Assert.AreEqual(response.StatusCode, result.Value.StatusCode); }