// [TestMethod] public void AddFile_RunAddUserAndAddFile_AndResultNewKey() { //Assign string login = "******"; string name = "Name"; string surName = "SurName"; string password = "******"; AddUserOperations addUserOperations = AddUserOperations.CreateUserOperations(login, password, name, surName); //HiveDatabaseService databaseService = new HiveDatabaseService(connectionString); sut.DoUserOperations(addUserOperations).Wait();; User user = sut.GetUser(addUserOperations.KeyUser).Result; string fileName = "filename"; string extension = "extension"; ResultService <AddFileOperations> addFileOperations = AddFileOperations .CreateFileOperations(user, fileName, extension) .OnError(a => throw new Exception(a)); //Act //sut.DoFileOperations(addFileOperations).Wait();; addFileOperations.OnSuccess(a => sut.DoFileOperations(a).Wait()); //Assert Assert.IsNotNull(user); }
public async Task <ResultService <File> > AddFileToUser(IFileServiceLogger fileServiceLogger, string userKey, Stream stream, string fileName, string extension) { fileServiceLogger.LogInfo($"Dewey.Dms.FileService.Services.AddFileToUser(userKey={userKey},fileName={fileName},extension={extension})"); try { User user = await _databaseService.GetUser(userKey); if (user == null) { fileServiceLogger.LogInfo( $"Dewey.Dms.FileService.Services.AddFileToUser(userKey={userKey},fileName={fileName},extension={extension}) - no such user"); return(ResultService <File> .Error($"No such user {userKey}")); } ResultService <AddFileOperations> resultAddFileOperations = AddFileOperations.CreateFileOperations(user, fileName, extension); if (resultAddFileOperations.IsError) { fileServiceLogger.LogInfo( $"Dewey.Dms.FileService.Services.AddFileToUser(userKey={userKey},fileName={fileName},extension={extension}) - {resultAddFileOperations.ErrorMessage}"); return(ResultService <File> .Error(resultAddFileOperations.ErrorMessage)); } AddFileOperations addFileOperations = resultAddFileOperations.Value; bool result = await _hdfsClient.WriteStream(stream, $"/dewey/{addFileOperations.Key}"); if (!result) { fileServiceLogger.LogInfo( $"Dewey.Dms.FileService.Services.AddFileToUser(userKey={userKey},fileName={fileName},extension={extension}) - problem writing file"); return(ResultService <File> .Error($"Internal server error")); } await _databaseService.DoFileOperations(addFileOperations); File file = await _databaseService.GetFile(addFileOperations.KeyUserFile); if (file == null) { fileServiceLogger.LogInfo( $"Dewey.Dms.FileService.Services.AddFileToUser(userKey={userKey},fileName={fileName},extension={extension}) - problem with read writing file"); return(ResultService <File> .Error($"Internal error")); } return(ResultService <File> .Ok(file)); } catch (Exception ex) { fileServiceLogger.LogError( $"Dewey.Dms.FileService.Services.AddFileToUser(userKey={userKey},fileName={fileName},extension={extension})", ex); return(ResultService <File> .Error("Internal server error")); } }
// [TestMethod] public void CloneFile_RunAddUserAndAddFileAndCloneFile_AndResultDeleteFile() { string login = "******"; string name = "Name"; string surName = "SurName"; string password = "******"; AddUserOperations addUserOperations = AddUserOperations.CreateUserOperations(login, password, name, surName); //HiveDatabaseService databaseService = new HiveDatabaseService(connectionString); sut.DoUserOperations(addUserOperations).Wait();; User user = sut.GetUser(addUserOperations.KeyUser).Result; AddUserOperations addUserOperationsOther = AddUserOperations.CreateUserOperations(login, password, name, surName); sut.DoUserOperations(addUserOperationsOther).Wait();; User userOther = sut.GetUser(addUserOperationsOther.KeyUser).Result; string fileName = "filename"; string extension = "extension"; AddFileOperations addFileOperations = AddFileOperations.CreateFileOperations(user, fileName, extension).OnError(a => throw new Exception(a)).Value;; sut.DoFileOperations(addFileOperations).Wait(); File file = sut.GetFile(addFileOperations.KeyUserFile).Result; CloneFileOperations cloneFileOperations = CloneFileOperations.CreateFileOperations(file, userOther).OnError(a => throw new Exception(a)).Value;; //Act sut.DoFileOperations(cloneFileOperations).Wait(); // Assert File fileRead = sut.GetFile(cloneFileOperations.KeyUserFile).Result; Assert.AreEqual(fileName, fileRead.FileName); Assert.AreEqual(extension, fileRead.Extension); Assert.AreEqual(cloneFileOperations.KeyUser, fileRead.KeyUser); Assert.AreEqual(cloneFileOperations.KeyUserFile, fileRead.Key); Assert.AreEqual(cloneFileOperations.Key, fileRead.LongKey); Assert.AreEqual(cloneFileOperations.OperationDate.ToString("yyyy-MM-dd HH:mm:ss"), file.LastOperationDate.ToString("yyyy-MM-dd HH:mm:ss")); Assert.IsFalse(fileRead.IsDeleted); Assert.IsTrue(fileRead.IsCloned); Assert.AreEqual(addFileOperations.Key, fileRead.Parent); }
public void GetFileUser_RunAddUserAndAddFile_AndResultListFile() { //Assign string login = "******"; string name = "Name"; string surName = "SurName"; string password = "******"; AddUserOperations addUserOperations = AddUserOperations.CreateUserOperations(login, password, name, surName); //HiveDatabaseService databaseService = new HiveDatabaseService(connectionString); sut.DoUserOperations(addUserOperations).Wait();; User user = sut.GetUser(addUserOperations.KeyUser).Result; string fileName = "filename"; string extension = "extension"; AddFileOperations addFileOperations = AddFileOperations.CreateFileOperations(user, fileName, extension).OnError(a => throw new Exception(a)).Value;; //Act sut.DoFileOperations(addFileOperations).Wait();; //Assert IEnumerable <File> files = sut.GetUserFile(addFileOperations.KeyUser).Result; //Assert Assert.IsNotNull(user); Assert.IsNotNull(files); File file = files.SingleOrDefault(); Assert.IsNotNull(file); Assert.AreEqual(fileName, file.FileName); Assert.AreEqual(extension, file.Extension); Assert.AreEqual(addFileOperations.KeyUser, file.KeyUser); Assert.AreEqual(addFileOperations.KeyUserFile, file.Key); Assert.AreEqual(addFileOperations.Key, file.LongKey); Assert.AreEqual(addFileOperations.OperationDate.ToString("yyyy-MM-dd HH:mm:ss"), file.LastOperationDate.ToString("yyyy-MM-dd HH:mm:ss")); Assert.IsFalse(file.IsDeleted); Assert.IsFalse(file.IsCloned); }