public async System.Threading.Tasks.Task UploadTestAsync_Ok() { string notFound = "A kért file nem található!"; string expected = "Object reference not set to an instance of an object."; string newFileName = "test.txt"; string expectedText = "valami szoveg"; Mock <IFileConfig> mockConfig = new Mock <IFileConfig>(); mockConfig.SetupGet(a => a.FilePath).Returns(@".\TargetData"); mockConfig.SetupGet(a => a.FileNotFound).Returns(notFound); var controllerContext = Create(newFileName, expectedText); FileHandlingController fc = new FileHandlingController(mockConfig.Object); fc.ControllerContext = controllerContext; var actionResult = await fc.UploadFile(); var contentResult = actionResult as OkResult; Assert.IsNotNull(contentResult); var actionResultGet = await fc.GetFile(newFileName); var contentResultGet = actionResultGet as OkNegotiatedContentResult <string>; Assert.IsNotNull(contentResult); var base64EncodedBytes = System.Convert.FromBase64String(contentResultGet.Content); var result = System.Text.Encoding.UTF8.GetString(base64EncodedBytes); Assert.AreEqual(expectedText, result); //File.Delete(@".\TargetData\test.txt"); }
public async System.Threading.Tasks.Task GetFileTestAsync_NotFound() { string notFound = "A kért file nem található!"; Mock <IFileConfig> mockConfig = new Mock <IFileConfig>(); mockConfig.SetupGet(a => a.FilePath).Returns(@".\TargetData"); mockConfig.SetupGet(a => a.FileNotFound).Returns(notFound); var file = "Test.txt"; _controller = new FileHandlingController(mockConfig.Object); var actionResult = await _controller.GetFile(file); var contentResult = actionResult as BadRequestErrorMessageResult; Assert.IsNotNull(contentResult); Assert.AreEqual(notFound, contentResult.Message); }
public async System.Threading.Tasks.Task GetFileTestAsync_Ok() { string notFound = "A kért file nem található!"; string expected = "teszt1 file"; Mock <IFileConfig> mockConfig = new Mock <IFileConfig>(); mockConfig.SetupGet(a => a.FilePath).Returns(@".\TargetData"); mockConfig.SetupGet(a => a.FileNotFound).Returns(notFound); var file = "Test1.txt"; _controller = new FileHandlingController(mockConfig.Object); var actionResult = await _controller.GetFile(file); var contentResult = actionResult as OkNegotiatedContentResult <string>; Assert.IsNotNull(contentResult); var base64EncodedBytes = System.Convert.FromBase64String(contentResult.Content); var result = System.Text.Encoding.UTF8.GetString(base64EncodedBytes); Assert.AreEqual(expected, result); }