Beispiel #1
0
        public void FolderDataSourceFactory_MakeDataSource()
        {
            IDataSource source = FolderDataSourceTests.CreateFolderDataSource().Source;

            try
            {
                CollectionAssert.AreEquivalent(
                    FolderDataSourceTests.SuppliedFiles.Select(x => x.Path).ToArray(),
                    source.Select(x => x.Name).ToArray());
                CollectionAssert.AreEquivalent(
                    FolderDataSourceTests.SuppliedDirectories.Select(x => x.Path).ToArray(),
                    source.GetSubDataSources().Select(x => x.Name).ToArray());
            }
            finally
            {
                source.Dispose();
            }
        }
Beispiel #2
0
        public void FolderDataSource_OnChange()
        {
            const int expectedAdded   = 3;
            const int expectedChanged = 5;
            const int expectedRemoved = 12;

            const string addedPathFormatString   = @"C:\Just\Got\Added{0}.txt";
            const string changedPathFormatString = @"C:\Just\Got\Changed{0}.txt";
            const string removedPathFormatString = @"C:\Just\Got\Removed{0}.txt";

            DataSourceTuple tuple = FolderDataSourceTests.CreateFolderDataSource();

            try
            {
                int actualAdded   = 0;
                int actualChanged = 0;
                int actualRemoved = 0;

                tuple.Source.OnChange += (obj, e) =>
                {
                    if (e.EventType == DataSourceChangeEventType.Added)
                    {
                        actualAdded++;
                    }
                    else if (e.EventType == DataSourceChangeEventType.Changed)
                    {
                        actualChanged++;
                    }
                    else if (e.EventType == DataSourceChangeEventType.Removed)
                    {
                        actualRemoved++;
                    }
                    else
                    {
                        throw new InternalTestFailureException("Encountered unexpected `DataSourceChangeEventType`.");
                    }
                };

                for (int counter = 0; counter < expectedAdded; counter++)
                {
                    tuple.InvokeAdded.Invoke(
                        null,
                        new MockFolderDataChangeEventArgs(
                            new FilePath(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    addedPathFormatString,
                                    counter)),
                            DataSourceChangeEventType.Added,
                            null));
                }

                for (int counter = 0; counter < expectedChanged; counter++)
                {
                    tuple.InvokeChanged.Invoke(
                        null,
                        new MockFolderDataChangeEventArgs(
                            new FilePath(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    changedPathFormatString,
                                    counter)),
                            DataSourceChangeEventType.Changed,
                            null));
                }

                for (int counter = 0; counter < expectedRemoved; counter++)
                {
                    tuple.InvokeRemoved.Invoke(
                        null,
                        new MockFolderDataChangeEventArgs(
                            new FilePath(
                                string.Format(
                                    CultureInfo.InvariantCulture,
                                    removedPathFormatString,
                                    counter)),
                            DataSourceChangeEventType.Removed,
                            null));
                }

                Assert.AreEqual(expectedAdded, actualAdded);
                Assert.AreEqual(expectedChanged, actualChanged);
                Assert.AreEqual(expectedRemoved, actualRemoved);
            }
            finally
            {
                tuple.Source.Dispose();
            }
        }