public async Task Search_Return_All_Removed_Items_Successful()
        {
            var nodes = TestData.CreateFiles();

            // Remove fake nodes
            var enumerable = nodes as Node[] ?? nodes.ToArray();

            foreach (var node in enumerable.ToArray())
            {
                node.IsDeleted = true;
            }

            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();


            fakeUnitOfWork.Setup(t => t.NodeRepository.GetAllNodesForUserWithPredicate(It.IsAny <string>(), false)).ReturnsAsync(enumerable);

            var searchService = MockingManager.GetSearchService(fakeUnitOfWork.Object);

            // Act
            var result = await searchService.SearchFilesAsync("*****@*****.**", null, true);

            // Assert

            Assert.Equal(2, result.Count());
        }
Beispiel #2
0
        public async Task RestoreFile_RestoringRemovedFile_Successful()
        {
            var nodes = TestData.CreateFiles();

            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();


            fakeUnitOfWork.Setup(t => t.NodeRepository.GetAllNodesForUserWithPredicate(It.IsAny <string>(), false)).ReturnsAsync(nodes);

            var fakeBlobService = MockingManager.GetBlobService(fakeUnitOfWork.Object);
            var fileService     = MockingManager.GetFileService(fakeUnitOfWork.Object, fakeBlobService);

            // Act

            // Remove
            var removeRequest = await fileService.RemoveFileAsync(new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda6be1"), fakeEmail);

            Assert.Equal(fileService.State.TypeOfError, TypeOfServiceError.Success);
            // Restore
            var restoreRequest = await fileService.RestoreRemovedFileAsync(new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda6be1"),
                                                                           fakeEmail);

            // Assert
            Assert.NotNull(restoreRequest);
        }
Beispiel #3
0
        public async Task ReplaceFile_ReplacingFileAndPlacingInRequestedFolder_Successful()
        {
            var nodes = TestData.CreateFiles();


            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();


            fakeUnitOfWork.Setup(t => t.NodeRepository.GetAllNodesForUserWithPredicate(It.IsAny <string>(), false)).ReturnsAsync(nodes);

            var fakeBlobService = MockingManager.GetBlobService(fakeUnitOfWork.Object);
            var fileService     = MockingManager.GetFileService(fakeUnitOfWork.Object, fakeBlobService);

            // Act
            var replaceRequest = await fileService.ReplaceFileAsync(fakeEmail, new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda6be1"),
                                                                    new ReplaceRequest()
            {
                DestanationFolderId = new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda3xj5"),
            });


            // Assert
            Assert.Equal(fileService.State.TypeOfError, TypeOfServiceError.Success);
            Assert.Equal(replaceRequest.DirectoryId, new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda3xj5"));
        }
Beispiel #4
0
        public async Task GetUserFile_WhenRequestedFromAnonymousReturnError_Successful()
        {
            // Arrange
            var fakeUnitOfWork  = MockingManager.GetFakeUnitOfWork();
            var fakeBlobService = MockingManager.GetBlobService(fakeUnitOfWork.Object);
            var fileService     = MockingManager.GetFileService(fakeUnitOfWork.Object, fakeBlobService);

            // Act
            var result = await fileService.GetFileAsync(new Guid(), fakeEmail, 1);

            // Assert
            Assert.Equal(fileService.State.TypeOfError, TypeOfServiceError.Forbidden);
        }
Beispiel #5
0
        public async Task GetUserFile_WhenRequestedExistedFileReturnFileStream_Successful()
        {
            var nodes = TestData.CreateFiles();

            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();


            fakeUnitOfWork.Setup(t => t.NodeRepository.GetAllNodesForUserWithPredicate(It.IsAny <string>(), false)).ReturnsAsync(nodes);

            var fakeBlobService = MockingManager.GetBlobService(fakeUnitOfWork.Object);
            var fileService     = MockingManager.GetFileService(fakeUnitOfWork.Object, fakeBlobService);
            // Act
            var result = await fileService.GetFileAsync(new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda6be1"), fakeEmail, 1);

            // Assert
            Assert.NotNull(result.Item1);
        }
Beispiel #6
0
        public async Task RenameFile_ReturnOkWhenFileRenamed_Successful()
        {
            var nodes = TestData.CreateFiles();

            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();


            fakeUnitOfWork.Setup(t => t.NodeRepository.GetAllNodesForUserWithPredicate(It.IsAny <string>(), false)).ReturnsAsync(nodes);

            var fakeBlobService = MockingManager.GetBlobService(fakeUnitOfWork.Object);
            var fileService     = MockingManager.GetFileService(fakeUnitOfWork.Object, fakeBlobService);

            // Act
            var result = await fileService.RenameFileAsync(new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda6be1"), "new-name", fakeEmail);

            // Assert
            Assert.Equal(result.Name, "new-name");
        }
Beispiel #7
0
        public async Task GetUserFile_WhenRequestedFileNotExistReturnNotFound_Successful()
        {
            var nodes = TestData.CreateFiles();

            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();


            fakeUnitOfWork.Setup(t => t.NodeRepository.GetAllNodesForUserWithPredicate(It.IsAny <string>(), false)).ReturnsAsync(nodes);

            var fakeBlobService = MockingManager.GetBlobService(fakeUnitOfWork.Object);
            var fileService     = MockingManager.GetFileService(fakeUnitOfWork.Object, fakeBlobService);

            // Act
            var result = await fileService.GetFileAsync(new Guid(), fakeEmail, 1);

            // Assert
            Assert.Equal(fileService.State.TypeOfError, TypeOfServiceError.NotFound);
            Assert.NotNull(result.Item2);
        }
        public async Task Search_Returns_Non_Deleted_Files_Or_Folders_Successful()
        {
            // Arrange
            var fakeUnitOfWork = MockingManager.GetFakeUnitOfWork();

            var node1 = new Node()
            {
                IsDirectory = false,
                ContentType = "application/json",
                Name        = "name",
                IsDeleted   = false,
                OwnerId     = new Guid().ToString(),
                Created     = DateTime.Now,
                FolderId    = null,
                Id          = new Guid("37e32a9e-bd72-48e2-9a7b-5c4fdbda6be1")
            };
            var fileVersion = new FileVersion()
            {
                Created       = DateTime.Today,
                MD5Hash       = "111-222-333-444",
                PathToFile    = "path_to_azure_file",
                Size          = 1151651561,
                Node          = node1,
                VersionOfFile = 1
            };

            node1.FileVersions.Add(fileVersion);

            fakeUnitOfWork.Setup(t => t.NodeRepository.GetFolderByIdAsync(It.IsAny <Guid>())).ReturnsAsync(node1);

            var searchService = MockingManager.GetSearchService(fakeUnitOfWork.Object);

            fakeUnitOfWork.VerifyAll();
            // Act
            var result = await searchService.SearchFilesAsync("*****@*****.**", "name", false);

            // Assert
            Assert.Equal(1, result.Count());
        }