コード例 #1
0
        public async Task ShouldCreateDirectory()
        {
            //Arrange
            await using var context = GetDbContext(true);
            var mockResolver    = new Mock <IUserResolver>();
            var authManager     = new AuthorizationManager(context, Mapper, mockResolver.Object);
            var directoryMnager = new DirectoryManager(context, Mapper, null);
            var repoManager     = new RepositoryManager(context, Mapper, directoryMnager, authManager);
            var user            = await SeedUserAsync(context);

            mockResolver.Setup(x => x.GetUserAsync()).Returns(Task.FromResult(Mapper.Map <UserDTO>(user)));
            var repoRoot = await repoManager.CreateRepositoryAsync(user.Id, "Test Repo");

            //Act
            var dirName   = "Test Directory";
            var directory = await directoryMnager.CreateDirectoryAsync(dirName, repoRoot.Id);

            var parent = await context.Set <Directory>()
                         .Include(x => x.SubDirectories)
                         .SingleOrDefaultAsync(x => x.Id == repoRoot.Id);

            //Assert
            Assert.NotNull(directory);
            Assert.True(directory.Id > 0);
            Assert.Equal(dirName, directory.Name);
            Assert.Single(parent.SubDirectories);
            Assert.Equal(parent.SubDirectories.First().Id, directory.Id);
        }
コード例 #2
0
ファイル: FileManagerTests.cs プロジェクト: nedkovps/HARRepo
        public async Task ShouldUpdateFileLocation()
        {
            //Arrange
            await using var context = GetDbContext(true);
            var mockResolver    = new Mock <IUserResolver>();
            var mockFileStorage = new Mock <IFileStorage>();
            var authManager     = new AuthorizationManager(context, Mapper, mockResolver.Object);
            var fileManager     = new Implementations.FileManager(context, Mapper, mockFileStorage.Object);
            var directoryMnager = new DirectoryManager(context, Mapper, fileManager);
            var repoManager     = new RepositoryManager(context, Mapper, directoryMnager, authManager);
            var filePath        = Guid.NewGuid().ToString();

            mockFileStorage.Setup(x => x.UploadAsync(It.IsAny <string>())).Returns(Task.FromResult(filePath));
            mockFileStorage.Setup(x => x.DeleteAsync(It.IsAny <string>())).Returns(Task.CompletedTask);
            var user = await SeedUserAsync(context);

            mockResolver.Setup(x => x.GetUserAsync()).Returns(Task.FromResult(Mapper.Map <UserDTO>(user)));
            var repoRoot = await repoManager.CreateRepositoryAsync(user.Id, "Test Repo");

            var directory = await directoryMnager.CreateDirectoryAsync("Test Directory", repoRoot.Id);

            var fileName = "FileName.har";
            var file     = await fileManager.UploadFileAsync(repoRoot.Id, fileName, "{}");

            //Act
            await fileManager.UpdateFileLocationAsync(file.Id, directory.Id);

            var fileFromDB = await context.Set <File>()
                             .FindAsync(file.Id);

            Assert.NotNull(fileFromDB);
            Assert.Equal(directory.Id, fileFromDB.DirectoryId);
        }