public void UploadFilesController_Post_CorrectCall_ReturnsResult() { // Arrange var fileManagementResult = new FileManagementResult(); fileManagementResult.IsStored = true; fileManagementResult.FileName = "test.name"; fileManagementResult.Length = 10; var mockFormFile = new Mock <IFormFile>(); var user = "******"; var password = "******"; _mockFileManagementServices.Setup(x => x.StoreFilesAsync(It.IsAny <IFormFile>())).Returns(Task.FromResult(fileManagementResult)); _mockFileManagementServices.Setup(x => x.GetUnzipPath()).Returns("UnzipPath"); _mockFileManagementServices.Setup(x => x.GetFileSeparator()).Returns("\\"); _mockZipServices.Setup(x => x.UnzipFiles(fileManagementResult, It.IsAny <string>(), It.IsAny <string>())); NodeCollection nodeCollection = new NodeCollection(); nodeCollection.AddEntry("atest/unzip.txt", 0); _mockEncryptionServices.Setup(x => x.EncryptToString("atest")).Returns("atest"); _mockEncryptionServices.Setup(x => x.EncryptToString("unzip.txt")).Returns("unzip.txt"); _mockZipServices.Setup(x => x.GetFileAndFolderStructureAsync(fileManagementResult.FileName)).Returns(nodeCollection); //TODO: I havent had the time to finish all the tests for the exercise and I excuse myself. // I Hope you see this code and realize that "YEAH! this guy can write tests!" // Act var answer = _controller.Post(mockFormFile.Object, user, password); // Assert Assert.NotNull(answer); //as this is a template code, well just test is fine }
/* * gets a path and generates the node collection (the first kind of node in the chain) */ public NodeCollection GetFileAndFolderStructureAsync(string filePath) { NodeCollection nodeCollection = new NodeCollection(); using (ZipArchive zipFile = ZipFile.OpenRead(filePath)) { foreach (ZipArchiveEntry entry in zipFile.Entries) { nodeCollection.AddEntry(entry.FullName, 0); } } return(nodeCollection); }