Ejemplo n.º 1
0
        public void FileContentIsntStoredIfTransactionWasRolledBack()
        {
            string storagePath = string.Empty;

            using (var unitOfWork = new UnitOfWork())
            {
                var folder = new Folder
                {
                    Name = "Test folder",
                };
                Repository.Data.Save(folder);

                var file = new File
                {
                    //Folder = folder,
                    DisplayName = "Test file",
                    Name = "TestFile.txt",
                    ContentType = FileType.txt
                };
                Stream stream = new MemoryStream();
                byte[] buffer = Guid.NewGuid().ToByteArray();
                stream.Write(buffer, 0, buffer.Length);
                file.FileStream = new Lazy<Stream>(() => stream);
                Repository.Data.Save(file);
                storagePath = file.StoragePath;

                unitOfWork.Rollback();
            }

            string path = string.Format(@"{0}\{1}", ConfiguredStorageDirectory, storagePath);
            Assert.False(System.IO.File.Exists(path));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a copy of the file in a new parent folder.
        /// </summary>
        /// <param name="newParentFolder">New parent folder.</param>
        /// <param name="file">Copied file.</param>
        /// <returns>The file copy, without file value.</returns>
        public File Copy(Folder newParentFolder, File file)
        {
            if (newParentFolder == null)
                throw new NullReferenceException("The new ParentFolder can't be null");

            return Copy(newParentFolder.Id, file);
        }
 public void TryCreateIdenticalFolder()
 {
     string folderName = "Folder - " + Guid.NewGuid().ToString();
     var folder1 = new Folder { Name = folderName, Parent = null };
     Repository.Data.Save(folder1);
     var folder2 = folder1.Clone();
     Assert.Throws<ValidationArgumentException>(() => Repository.Data.Save(folder2));
 }
        public void ValidationFolderInsertTest()
        {
            var folder = new Folder
                         	{
                         		Name = string.Empty //Value is required
                         	};

            Assert.Throws<ValidationArgumentException>(() => Repository.Data.Save(folder));
        }
Ejemplo n.º 5
0
        public void CopyFileEnterParameterFolderIdTest()
        {
            var folder1 = new Folder { Name = "Folder1" };
            Repository.Data.Save(folder1);
            File file1 = new File { ContentType = FileType.txt, Name = "Dummy", DisplayName = "Dummy"};
            Repository.Data.Save(file1);
            File copyFile1 = _service.Copy(folder1.Id, file1);

            //Assert.Equal(folder1, copyFile1.Folder);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Move folder from one parent folder to another parent folder.
        /// </summary>
        /// <param name="newParentFolderId">Parent folder Id.</param>
        /// <param name="folder">Folder which is moved.</param>
        public void Move(Guid newParentFolderId, Folder folder)
        {
            if (folder == null)
                throw new NullReferenceException("The moved folder can't be null");

            if(folder.Id == Guid.Empty)
                throw new ArgumentOutOfRangeException("folderId", "Value can't be Guid.Empty");

            folder.Parent = (newParentFolderId == Guid.Empty) ? null : Repository.Data.Get<Folder>(newParentFolderId);;
            Repository.Data.Save(folder);
        }
Ejemplo n.º 7
0
        public void MoveFolderTestEnterParameterFolderTest()
        {
            var folder1 = new Folder { Name = "Folder1" };
            Repository.Data.Save(folder1);

            var folder2 = new Folder { Name = "Folder2" };
            Repository.Data.Save(folder2);

            _service.Move(folder1, folder2);
            Assert.Equal(folder1, folder2.Parent);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Move file from a folder to another folder.
        /// </summary>
        /// <param name="newParentFolder">New folder.</param>
        /// <param name="file">The file which will be moved.</param>
        public void Move(Folder newParentFolder, File file)
        {
            if (newParentFolder == null)
                throw new NullReferenceException("The new ParentFolder can't be null");

            if (newParentFolder.Id == Guid.Empty)
                throw new ArgumentOutOfRangeException("newParentFolderId", "Value can't be Guid.Empty");

            if (file == null)
                throw new NullReferenceException("File can't be null");

            //Repository.Data.Save(file.Folder = newParentFolder);
        }
Ejemplo n.º 9
0
        public void MoveFolderCheckEnterParametersTest()
        {
            Assert.Throws<NullReferenceException>(() => _service.Move((Folder)null, (Folder)null));

            Folder folder1 = new Folder{Name = "Folder1"};
            Folder folder2 = new Folder();

            Assert.Throws<ArgumentOutOfRangeException>(() => _service.Move(folder1.Id, folder2));

            Repository.Data.Save(folder1);

            Assert.Throws<ArgumentOutOfRangeException>(() => _service.Move(folder1.Id, folder2));
        }
        public void ValidationFileInsertTest()
        {
            var folder = new Folder {Name = "Folder1"};
            Repository.Data.Save(folder);
            Assert.NotNull(folder);

            var file = new File
                       	{
                            ContentType = FileType.image,
                       		DisplayName = string.Empty,
                       		Name = string.Empty,
                       	};

            Assert.Throws<ValidationArgumentException>(() => Repository.Data.Save(file));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Move folder from one parent folder to another parent folder.
 /// </summary>
 /// <param name="newParentFolder">Parent folder.</param>
 /// <param name="folder">Folder which is moved.</param>
 public void Move(Folder newParentFolder, Folder folder)
 {
     Move(newParentFolder == null ? Guid.Empty : newParentFolder.Id, folder);
 }
Ejemplo n.º 12
0
        public void FileContentIsStoredLoadedDeletedTogetherWithFileEntity()
        {
            //Create new file with content, save it and check if file was stored on the disk.
            var folder = new Folder
                         	{
                         		Name = "Test folder",
                         	};
            Repository.Data.Save(folder);

            var file = new File
                       	{
                       		//Folder = folder,
                       		DisplayName = "Test file",
                       		Name = "TestFile.txt",
                            ContentType = FileType.txt
                       	};
            Stream stream = new MemoryStream();
            byte[] buffer = Guid.NewGuid().ToByteArray();
            stream.Write(buffer, 0, buffer.Length);
            file.FileStream = new Lazy<Stream>(() => stream);
            Repository.Data.Save(file);
            Assert.NotEmpty(file.StoragePath);
            Assert.Equal(file.Size, buffer.Length);
            string path = string.Format(@"{0}\{1}", ConfiguredStorageDirectory, file.StoragePath);
            var fileInfo = new FileInfo(path);
            Assert.True(fileInfo.Exists);
            Assert.Equal(fileInfo.Length, buffer.Length);

            //Get file and check if file content is initialized.
            Repository.Data.Cache.Clear(file);
            var retrievedFile = Repository.Data.Get<File>(file.Id);
            Assert.False(string.IsNullOrEmpty(retrievedFile.StoragePath));
            Assert.Equal(retrievedFile.Size, buffer.Length);
            Assert.NotEqual(retrievedFile.FileStream.Value, null);
            Assert.Equal(retrievedFile.FileStream.Value.Length, buffer.Length);

            //Initialize file with the new file content, save it and check if old file content was deleted from the disk and new one was stored.
            byte[] newBuffer = Guid.NewGuid().ToByteArray().Take(5).ToArray();
            Stream newStream = new MemoryStream();
            newStream.Write(newBuffer, 0, newBuffer.Length);
            retrievedFile.FileStream = new Lazy<Stream>(() => newStream);
            retrievedFile.Name = "NewTestFile.txt";
            Repository.Data.Save(retrievedFile);
            Assert.NotEmpty(retrievedFile.StoragePath);
            Assert.Equal(retrievedFile.Size, newBuffer.Length);
            string newPath = string.Format(@"{0}\{1}", ConfiguredStorageDirectory, retrievedFile.StoragePath);
            var newFileInfo = new FileInfo(newPath);
            Assert.True(newFileInfo.Exists);
            Assert.Equal(newFileInfo.Length, newBuffer.Length);
            Assert.False(System.IO.File.Exists(path));

            //Delete file and check if file content was also deleted from the disk.
            Repository.Data.Delete(retrievedFile);
            Repository.Data.Cache.Clear(retrievedFile);
            var deletedFile = Repository.Data.Get<File>(retrievedFile.Id);
            Assert.Null(deletedFile);
            Assert.False(System.IO.File.Exists(newPath));
        }