Пример #1
0
        public void FileDescriptorTest()
        {
            string componentsDir = System.IO.Path.Combine(AppContext.BaseTestDirectory, "TestComponents");
            string componentFile = System.IO.Path.Combine(componentsDir, "Importer.dll");

            AssemblyFileDescriptor assembly = new AssemblyFileDescriptor(componentFile);

            Assert.IsTrue(assembly.isUpToDate());

            string id        = "MockComponent";
            string classname = "MockComponents.MockComponent"; //class exists and should be loaded
            ComponentMetadataDefinition compMetaDef = new ComponentMetadataDefinition(id, assembly.AbsolutePath, classname);

            Assert.AreEqual("MockComponents.MockComponent", compMetaDef.Classname);

            assembly.MetadataCollection.Add(compMetaDef);

            IList <FileDescriptor> files = new List <FileDescriptor>();

            files.Add(assembly);

            ComponentsLibraryCache cache = new ComponentsLibraryCache(AppContext.BaseTestDirectory);

            cache.AddComponentFiles(files);

            Assert.IsTrue(cache.ComponentFiles.Contains(assembly.AbsolutePath));

            ISet <string> filepaths = cache.GetUpToDateFiles();

            Assert.AreEqual(filepaths.Count, 1);
        }
Пример #2
0
        public void WrongCacheFilePathTest()
        {
            ComponentsLibraryCacheHelper_Accessor.s_defaultCacheLocation = "c:\\ComponentsLibrary.cache";

            ComponentsLibraryCache cache = ComponentsLibraryCacheHelper.LoadCacheFile();

            Assert.IsNull(cache);

            ComponentsLibraryCacheHelper_Accessor.s_defaultCacheLocation = null;

            cache = ComponentsLibraryCacheHelper.LoadCacheFile();

            Assert.IsNull(cache);
        }
Пример #3
0
        public void FileCacheHelperTest()
        {
            string cachePath = System.IO.Path.Combine(AppContext.BaseTestDirectory, "ComponentsLibrary.cache");

            ComponentsLibraryCacheHelper_Accessor.s_defaultCacheLocation = cachePath;
            ComponentsLibraryCache cache = ComponentsLibraryCacheHelper.LoadCacheFile();

            Assert.IsNull(cache);

            cache = new ComponentsLibraryCache(cachePath);

            Assert.IsTrue(cache.ComponentFiles != null);
            Assert.AreEqual(cache.AppExecutable, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

            ComponentsLibraryCacheHelper.StoreCacheFile(cache);

            Assert.IsFalse(cache.WasModified);
            Assert.IsTrue(ComponentsLibraryCacheHelper.CacheFileExists());

            ComponentsLibraryCacheHelper.DeleteCacheFile();

            Assert.IsFalse(ComponentsLibraryCacheHelper.CacheFileExists());
        }
        public void FileDescriptorTest()
        {
            string componentsDir = System.IO.Path.Combine(AppContext.BaseTestDirectory, "TestComponents");
            string componentFile = System.IO.Path.Combine(componentsDir, "Importer.dll");

            AssemblyFileDescriptor assembly = new AssemblyFileDescriptor(componentFile);

            Assert.IsTrue(assembly.isUpToDate());

            string id = "MockComponent";
            string classname = "MockComponents.MockComponent"; //class exists and should be loaded
            ComponentMetadataDefinition compMetaDef = new ComponentMetadataDefinition(id, assembly.AbsolutePath, classname);

            Assert.AreEqual("MockComponents.MockComponent", compMetaDef.Classname);

            assembly.MetadataCollection.Add(compMetaDef);

            IList<FileDescriptor> files = new List<FileDescriptor>();
            files.Add(assembly);

            ComponentsLibraryCache cache = new ComponentsLibraryCache(AppContext.BaseTestDirectory);
            cache.AddComponentFiles(files);

            Assert.IsTrue(cache.ComponentFiles.Contains(assembly.AbsolutePath));

            ISet<string> filepaths = cache.GetUpToDateFiles();

            Assert.AreEqual(filepaths.Count, 1);
        }
        public void FileCacheHelperTest()
        {
            string cachePath = System.IO.Path.Combine(AppContext.BaseTestDirectory, "ComponentsLibrary.cache");

            ComponentsLibraryCacheHelper_Accessor.s_defaultCacheLocation = cachePath;
            ComponentsLibraryCache cache = ComponentsLibraryCacheHelper.LoadCacheFile();

            Assert.IsNull(cache);

            cache = new ComponentsLibraryCache(cachePath);

            Assert.IsTrue(cache.ComponentFiles != null);
            Assert.AreEqual(cache.AppExecutable, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

            ComponentsLibraryCacheHelper.StoreCacheFile(cache);

            Assert.IsFalse(cache.WasModified);
            Assert.IsTrue(ComponentsLibraryCacheHelper.CacheFileExists());

            ComponentsLibraryCacheHelper.DeleteCacheFile();

            Assert.IsFalse(ComponentsLibraryCacheHelper.CacheFileExists());
        }
        /// <summary>
        /// Stores the cache in a binary file.
        /// </summary>
        /// <param name="cache">The library cache to be stored.</param>
        public static void StoreCacheFile(ComponentsLibraryCache cache)
        {
            cache.WasModified = false;
            try
            {
#if DEBUG
                Console.WriteLine("Storing components library cache file to " + s_defaultCacheLocation);
#endif
                using (FileStream fs = File.Create(s_defaultCacheLocation))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(fs, cache);
                }
            }
            catch (Exception)
            {
                cache.Clear();
            }
        }