public void CreateRowViewModel() { const string file1Name = "File1"; const string file2Name = "File2"; using (var leftDirectory = new Infrastructure.TestDirectory()) using (var rightDirectory = new Infrastructure.TestDirectory()) { leftDirectory.CreateFiles(new Dictionary <string, DateTime> { { file1Name, DateTime.Now }, { file2Name, DateTime.Now } }); rightDirectory.CreateFiles(new Dictionary <string, DateTime> { { file1Name, DateTime.Now }, { file2Name, DateTime.Now } }); bool useAddRowEvent = false; var synchronizedDirectories = GetSynchronizedDirectories(leftDirectory.FullPath, rightDirectory.FullPath); var factory = new RowViewModelFactory(); factory.AddRowEvent += (IRowViewModel parent, IRowViewModel child) => { useAddRowEvent = true; }; var rowViewModel = factory.CreateRowViewModel(synchronizedDirectories); // Пока не выполнялась загрузка, события добавления записи происходить не должны. Assert.False(useAddRowEvent); Assert.Empty(rowViewModel.ChildRows); } }
public async Task LoadDirectoryAndFile() { const string directoryAndFileName = "Item"; using (var leftDirectory = new Infrastructure.TestDirectory()) using (var rightDirectory = new Infrastructure.TestDirectory()) { var updateDate = DateTime.Now; leftDirectory.CreateFiles(new Dictionary <string, DateTime> { { directoryAndFileName, updateDate } }); // В директорию надо поместить хотя бы один файл, чтобы она была видна. Infrastructure.TestDirectory.CreateFiles(rightDirectory.CreateDirectory(directoryAndFileName), new Dictionary <string, DateTime> { { "1", updateDate } }); var settingsRow = new TestSettingsRow { LeftDirectory = new SettingsDirectory(leftDirectory.FullPath), RightDirectory = new SettingsDirectory(rightDirectory.FullPath) }; var testSynchronizedItemsStatusAndCommandsUpdater = new TestSynchronizedItemsStatusAndCommandsUpdater(); var synchronizedDirectories = new SynchronizedItems(settingsRow, new SynchronizedItemFactory(new ItemFactory()), testSynchronizedItemsStatusAndCommandsUpdater); await synchronizedDirectories.Load(); Assert.Equal(2, synchronizedDirectories.ChildItemsCount); // Одна модель на директории, одна модель на файлы. // Сначала директория, потом файл. var childDirectories1 = synchronizedDirectories.ChildItems[0]; Assert.Equal(directoryAndFileName, childDirectories1.LeftItem.Name); Assert.Equal(directoryAndFileName, childDirectories1.RightItem.Name); Assert.NotNull(childDirectories1.RightItem.Directory); Assert.True(childDirectories1.RightItem.IsDirectory); // Даже если элемент отсутствует, а присутствующий является директорией, то и этот должен быть директорией. Assert.Null(childDirectories1.LeftItem.Directory); Assert.True(childDirectories1.LeftItem.IsDirectory); var childDirectories2 = synchronizedDirectories.ChildItems[1]; Assert.Equal(directoryAndFileName, childDirectories2.LeftItem.Name); Assert.Equal(directoryAndFileName, childDirectories2.RightItem.Name); Assert.Null(childDirectories2.LeftItem.Directory); Assert.False(childDirectories2.LeftItem.IsDirectory); Assert.Null(childDirectories2.RightItem.Directory); Assert.False(childDirectories2.RightItem.IsDirectory); } }
public async Task LoadFiles() { const string file1Name = "File1"; const string file2Name = "File2"; const string file3Name = "File3"; var updateFileDate = DateTime.Now; var filesDirectoinaries = new Dictionary <string, DateTime> { { file1Name, updateFileDate }, { file2Name, updateFileDate }, { file3Name, updateFileDate } }; using (var leftDirectory = new Infrastructure.TestDirectory()) using (var rightDirectory = new Infrastructure.TestDirectory()) { leftDirectory.CreateFiles(filesDirectoinaries); rightDirectory.CreateFiles(filesDirectoinaries); var settingsRow = new TestSettingsRow { LeftDirectory = new SettingsDirectory(leftDirectory.FullPath), RightDirectory = new SettingsDirectory(rightDirectory.FullPath) }; var testSynchronizedItemsStatusAndCommandsUpdater = new TestSynchronizedItemsStatusAndCommandsUpdater(); var synchronizedDirectories = new SynchronizedItems(settingsRow, new SynchronizedItemFactory(new ItemFactory()), testSynchronizedItemsStatusAndCommandsUpdater); await synchronizedDirectories.Load(); Assert.Equal(3, synchronizedDirectories.ChildItemsCount); var directories = synchronizedDirectories.ChildItems[0]; Assert.Equal(file1Name, directories.LeftItem.Name); Assert.Equal(file1Name, directories.RightItem.Name); // Это файлы. Assert.False(directories.LeftItem.IsDirectory); Assert.Null(directories.LeftItem.Directory); Assert.False(directories.RightItem.IsDirectory); Assert.Null(directories.RightItem.Directory); directories = synchronizedDirectories.ChildItems[1]; Assert.Equal(file2Name, directories.LeftItem.Name); Assert.Equal(file2Name, directories.RightItem.Name); // Это файлы. Assert.False(directories.LeftItem.IsDirectory); Assert.Null(directories.LeftItem.Directory); Assert.False(directories.RightItem.IsDirectory); Assert.Null(directories.RightItem.Directory); directories = synchronizedDirectories.ChildItems[2]; Assert.Equal(file3Name, directories.LeftItem.Name); Assert.Equal(file3Name, directories.RightItem.Name); // Это файлы. Assert.False(directories.LeftItem.IsDirectory); Assert.Null(directories.LeftItem.Directory); Assert.False(directories.RightItem.IsDirectory); Assert.Null(directories.RightItem.Directory); } }