public void VerifyThatUpdateFileRowsWorks(FileStore fileStore)
        {
            this.fileStoreRow.Setup(x => x.Thing).Returns(fileStore);

            var fileStoreFileAndFolderHandler = new FileStoreFileAndFolderHandler <FileStore>(this.fileStoreRow.Object);

            fileStoreFileAndFolderHandler.UpdateFileRows();

            //one file at root level
            Assert.AreEqual(1, this.containedRows.OfType <FileRowViewModel>().Count());

            //two folders with one file
            Assert.AreEqual(2, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1));

            //one file in all subfolders
            Assert.AreEqual(1,
                            this.containedRows.OfType <FolderRowViewModel>()
                            .Where(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1)
                            .SelectMany(x => x.ContainedRows.OfType <FolderRowViewModel>())
                            .Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1)
                            );

            this.fileStoreRow.Object.Thing.File.RemoveAt(this.fileStoreRow.Object.Thing.File.Count - 1);

            fileStoreFileAndFolderHandler.UpdateFileRows();

            //no file at root level anymore
            Assert.AreEqual(0, this.containedRows.OfType <FileRowViewModel>().Count());
        }
        public void VerifyThatUpdateFolderRowPositionWorks(FileStore fileStore)
        {
            this.fileStoreRow.Setup(x => x.Thing).Returns(fileStore);

            var fileStoreFileAndFolderHandler = new FileStoreFileAndFolderHandler <FileStore>(this.fileStoreRow.Object);

            fileStoreFileAndFolderHandler.UpdateFileRows();

            //one folder with one subfolder
            Assert.AreEqual(1, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1));

            //two folders at root level
            Assert.AreEqual(2, this.containedRows.OfType <FolderRowViewModel>().Count());

            var subFolder        = fileStore.Folder.First(x => x.ContainingFolder != null);
            var containingFolder = subFolder.ContainingFolder;

            //Move a folder to root
            subFolder.ContainingFolder = null;
            fileStoreFileAndFolderHandler.UpdateFolderRowPosition(subFolder);

            //no folders with one subfolder anymore
            Assert.AreEqual(0, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1));

            //Three folders at root level
            Assert.AreEqual(3, this.containedRows.OfType <FolderRowViewModel>().Count());

            //Move a folder from root to subfolder
            subFolder.ContainingFolder = containingFolder;
            fileStoreFileAndFolderHandler.UpdateFolderRowPosition(subFolder);

            //one folder with one subfolder
            Assert.AreEqual(1, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1));

            //two folders at root level
            Assert.AreEqual(2, this.containedRows.OfType <FolderRowViewModel>().Count());
        }
        public void VerifyThatUpdateFileRowPositionWorks(FileStore fileStore)
        {
            this.fileStoreRow.Setup(x => x.Thing).Returns(fileStore);

            var fileStoreFileAndFolderHandler = new FileStoreFileAndFolderHandler <FileStore>(this.fileStoreRow.Object);

            fileStoreFileAndFolderHandler.UpdateFileRows();

            //one file at root level
            Assert.AreEqual(1, this.containedRows.OfType <FileRowViewModel>().Count());

            //two folders with one file
            Assert.AreEqual(2, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1));

            //one file in all subfolders
            Assert.AreEqual(1,
                            this.containedRows.OfType <FolderRowViewModel>()
                            .Where(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1)
                            .SelectMany(x => x.ContainedRows.OfType <FolderRowViewModel>())
                            .Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1)
                            );

            //Add Revision from subfolder file in root folder
            var folder          = fileStore.Folder.First(x => x.ContainingFolder != null);
            var file            = fileStore.File.First(x => x.FileRevision.Any(y => y.ContainingFolder == folder));
            var initialRevision = file.FileRevision.First();

            var secondRevision = new FileRevision(Guid.NewGuid(), null, null)
            {
                Name             = "File",
                CreatedOn        = DateTime.UtcNow,
                Creator          = initialRevision.Creator,
                ContainingFolder = null
            };

            file.FileRevision.Add(secondRevision);
            fileStoreFileAndFolderHandler.UpdateFileRowPosition(file, secondRevision);

            //two files at root level
            Assert.AreEqual(2, this.containedRows.OfType <FileRowViewModel>().Count());

            //two folders with one file
            Assert.AreEqual(2, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1));

            //no files in all subfolders
            Assert.AreEqual(0,
                            this.containedRows.OfType <FolderRowViewModel>()
                            .Where(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1)
                            .SelectMany(x => x.ContainedRows.OfType <FolderRowViewModel>())
                            .Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1)
                            );

            var thirdRevision = new FileRevision(Guid.NewGuid(), null, null)
            {
                Name             = "File",
                CreatedOn        = DateTime.UtcNow,
                Creator          = secondRevision.Creator,
                ContainingFolder = initialRevision.ContainingFolder
            };

            file.FileRevision.Add(thirdRevision);
            fileStoreFileAndFolderHandler.UpdateFileRowPosition(file, thirdRevision);

            //one file at root level
            Assert.AreEqual(1, this.containedRows.OfType <FileRowViewModel>().Count());

            //two folders with one file
            Assert.AreEqual(2, this.containedRows.OfType <FolderRowViewModel>().Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1));

            //one file in all subfolders
            Assert.AreEqual(1,
                            this.containedRows.OfType <FolderRowViewModel>()
                            .Where(x => x.ContainedRows.OfType <FolderRowViewModel>().Count() == 1)
                            .SelectMany(x => x.ContainedRows.OfType <FolderRowViewModel>())
                            .Count(x => x.ContainedRows.OfType <FileRowViewModel>().Count() == 1)
                            );
        }