예제 #1
0
 public void ChainedPathTest()
 {
     BasePath path = new BasePath("C:/code/");
     RelativePath relPath = new RelativePath("test/", path);
     RelativePath relPath2 = new RelativePath("file.txt", relPath);
     Assert.AreEqual("C:/code/test/file.txt", relPath2.AbsolutePath, "Chained relative path.");
 }
예제 #2
0
 public void ConstructFromRelativePathTest()
 {
     BasePath path = new BasePath("C:/code/");
     RelativePath relPath = new RelativePath("test/", path);
     Assert.AreEqual("test/", relPath.RelativePathComponent, "Relative path from constructor.");
     Assert.AreEqual(path, relPath.RelativeTo, "Relative to from constructor.");
 }
예제 #3
0
 public void PathComponentsTest()
 {
     BasePath path = new BasePath("C:/code/test/");
     Assert.AreEqual(3, path.PathComponents.Count, "PathComponents count");
     Assert.AreEqual("C:", path.PathComponents[0], "First path component");
     Assert.AreEqual("code", path.PathComponents[1], "Second path component");
     Assert.AreEqual("test", path.PathComponents[2], "Third path component");
 }
예제 #4
0
 /// <summary>
 /// Adds the resources for all InstallerActions to the zip package.
 /// </summary>
 public virtual void AddInstallerActionResources(ScriptPackage package, ScriptVersion version)
 {
     BasePath sourcePath = new BasePath(ScriptManifestTokens.Replace(package.SourcePath.AbsolutePath, package.Manifest, version));
     foreach (InstallerAction action in package.InstallerConfiguration.Actions)
     {
         action.PackResources(_currentZipFile, PackageBuilder.ResourcesArchivePath, sourcePath);
     }
 }
예제 #5
0
        public void IsFilePathTest()
        {
            BasePath path = new BasePath("C:/code/test/");
            Assert.IsFalse(path.IsFilePath, "Directory path IsFilePath");
            Assert.IsTrue(path.IsDirectoryPath, "Directory path IsDirectoryPath");

            path = new BasePath("C:/code/test/test.txt");
            Assert.IsTrue(path.IsFilePath, "File path IsFilePath");
            Assert.IsFalse(path.IsDirectoryPath, "File path IsDirectoryPath");
        }
예제 #6
0
        public void CombineTest()
        {
            BasePath path = new BasePath("C:/code/");
            IPath newPath = path.Combine("test/");
            Assert.AreEqual("C:/code/", path.AbsolutePath, "Original path object should not change.");
            Assert.AreEqual(path.AbsolutePath + "test/", newPath.AbsolutePath, "New path should include concatenated directory.");

            newPath = path.Combine("../test/");
            Assert.AreEqual("C:/test/", newPath.AbsolutePath, "New path should be able to handle relative path concatenation.");
        }
예제 #7
0
        public void WriteTest()
        {
            IPath outputFile = new BasePath(TestHelperMethods.GetOutputDirectory() + "repo" + ScriptRepository.DefaultExtension);
            if (File.Exists(outputFile.AbsolutePath))
                File.Delete(outputFile.AbsolutePath);

            JsonFileHandler<ScriptRepository> handler = new JsonFileHandler<ScriptRepository>();
            handler.Write(outputFile, repo);

            Assert.IsTrue(File.Exists(outputFile.AbsolutePath));
        }
 public void WriteRepositoryListTest()
 {
     JsonFileHandler<ScriptRepositoryList> handler = new JsonFileHandler<ScriptRepositoryList>();
     IPath path = new BasePath(this.getOutputDirectory() + "repositoryList.json");
     try
     {
         handler.Write(path, this.repoList);
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
        public void ReadRepositoryListTest()
        {
            this.WriteRepositoryListTest();

            JsonFileHandler<ScriptRepositoryList> handler = new JsonFileHandler<ScriptRepositoryList>();
            IPath path = new BasePath(TestHelperMethods.GetOutputDirectory() + "repositoryList.json");
            ScriptRepositoryList readList = handler.Read(path);
            Assert.IsNotNull(readList);
            Assert.IsNotNull(readList.Repositories);
            Assert.AreEqual(this.repoList.Repositories.Count, readList.Repositories.Count);
            Assert.AreEqual(this.repoList.Repositories[0].Name, readList.Repositories[0].Name);
            Assert.AreEqual(this.repoList.Repositories[0].URI, readList.Repositories[0].URI);
        }
예제 #10
0
        public void BasePathConstructorTest()
        {
            BasePath path = new BasePath("C:/code/test/");
            Assert.AreEqual("C:/code/test/", path.AbsolutePath, "Path set by the constructor");

            try
            {
                path = new BasePath(null);
                Assert.Fail("Passing null to constructor should throw exception");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null || context.Instance == null || !(context.Instance is InstallerAction))
            return value;

            InstallerAction action = (InstallerAction)context.Instance;
            ScriptPackage package = action.Configuration.Package;
            ScriptManifest manifest = package.Manifest;

            if (this.openFileDialog == null)
            {
            this.InitializeDialog();
            }

            if (value is String)
            {
            if (action.Configuration != null && action.Configuration.Package != null)
            {
                RelativePath path = new RelativePath((string)value, package.SourcePath);
                String pathStr = ScriptManifestTokens.Replace(path.AbsolutePath, manifest, manifest.LatestVersion);
                if (path.IsFilePath)
                {
                    this.openFileDialog.FileName = pathStr.Replace('/', '\\');
                }
                else
                {
                    this.openFileDialog.FileName = "";
                    this.openFileDialog.InitialDirectory = pathStr.Replace('/', '\\');
                }
            }
            else
                this.openFileDialog.FileName = (string)value;
            }

            if (this.openFileDialog.ShowDialog() == DialogResult.OK)
            {
            if (action.Configuration != null && action.Configuration.Package != null)
            {
                BasePath sourcePath = new BasePath(ScriptManifestTokens.Replace(package.SourcePath.AbsolutePath, manifest, manifest.LatestVersion));
                RelativePath relPath = new RelativePath(this.openFileDialog.FileName, sourcePath);
                value = relPath.RelativePathComponent;
            }
            else
                value = (new System.IO.FileInfo(this.openFileDialog.FileName)).Name;
            }

            return value;
        }
예제 #12
0
 public void ReadBrokenFileTest()
 {
     //Read a simple test object file that is not formed correctly and check the results.
     SimpleTestObject readObj = null;
     IPath path = new BasePath(TestHelperMethods.GetTestFilesDirectory() + "SimpleBrokenTestObject.json");
     try
     {
         readObj = handler.Read(path);
         Assert.Fail("Read broken file did not throw an exception as expected");
     }
     catch (JsonReaderException e)
     {
         Assert.IsNotNull(e); //I don't think this will ever fail, but still..
     }
     Assert.IsNull(readObj);
 }
예제 #13
0
        public void ReadAsyncTest()
        {
            IPath path = new BasePath(TestHelperMethods.GetTestFilesDirectory() + "SimpleTestObject.json");
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            SimpleTestObject obj = null;
            handler.ReadComplete += delegate(object sender, ReadCompleteEventArgs<SimpleTestObject> e)
            {
                obj = e.Data;
                manualEvent.Set();
            };
            handler.ReadAsync(path);
            manualEvent.WaitOne(5000, false);
            Assert.IsNotNull(obj);
            Assert.AreEqual(SimpleTestObject.DefaultName, obj.Name);
            Assert.AreEqual(SimpleTestObject.DefaultId, obj.Id);
        }
예제 #14
0
        public void ReadTest()
        {
            IPath inputFile = new BasePath(TestHelperMethods.GetOutputDirectory() + "repo" + ScriptRepository.DefaultExtension);
            if (!File.Exists(inputFile.AbsolutePath))
                this.WriteTest();

            Assert.IsTrue(File.Exists(inputFile.AbsolutePath), "File to read does not exist");

            JsonFileHandler<ScriptRepository> handler = new JsonFileHandler<ScriptRepository>();
            ScriptRepository readRepo = handler.Read(inputFile);

            Assert.IsNotNull(readRepo, "Repository should not be null");
            Assert.AreEqual(repo.Scripts.Count, readRepo.Scripts.Count, "Number of scripts in default category incorrect");
            Assert.AreEqual(repo.Name, readRepo.Name, "Repository name incorrect");
            Assert.AreEqual(repo.Categories.Count, readRepo.Categories.Count, "Category count incorrect");
            Assert.AreEqual(repo.Categories[0].Scripts.Count, readRepo.Categories[0].Scripts.Count, "Category.Scripts count incorrect");
        }
예제 #15
0
        public void BasePathSetPathTest()
        {
            BasePath path = new BasePath("C:/code/test/");
            Assert.AreEqual("C:/code/test/", path.AbsolutePath, "Path set by the constructor");

            path.AbsolutePath = "C:/test/";
            Assert.AreEqual("C:/test/", path.AbsolutePath, "Change path.");

            try
            {
                path.AbsolutePath = null;
                Assert.Fail("Setting Path to null should throw ArgumentNullException.");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }
        }
예제 #16
0
        public void ReadBrokenFileAsyncTest()
        {
            IPath path = new BasePath(TestHelperMethods.GetTestFilesDirectory() + "SimpleBrokenTestObject.json");
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            Exception exception = null;
            handler.ReadComplete += delegate(object sender, ReadCompleteEventArgs<SimpleTestObject> e)
            {
                Assert.Fail("LoadComplete event should not fire when parsing broken file.");
            };
            handler.SerializationError += delegate(object sender, ErrorEventArgs e)
            {
                exception = e.Exception;
                manualEvent.Set();
            };
            handler.ReadAsync(path);
            manualEvent.WaitOne(5000, false);
            Assert.IsNotNull(exception);
        }
예제 #17
0
        public void ConstructorIncorrectInputTest()
        {
            BasePath path = new BasePath("C:/code/");

            try
            {
                RelativePath relPath = new RelativePath(null, path);
                Assert.Fail("Passing null path to constructor should throw exception");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }

            try
            {
                RelativePath relPath = new RelativePath("test/", null);
                Assert.Fail("Passing null relativeTo to constructor should throw exception");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }

            BasePath filePath = new BasePath("C:/code/test.txt");
            Assert.IsTrue(filePath.IsFilePath);
            try
            {
                RelativePath relPath = new RelativePath("../folder/", filePath);
                Assert.Fail("Creating a path relative to a file should throw exception");
            }
            catch (ArgumentException e)
            {
                Assert.IsNotNull(e);
            }
        }
예제 #18
0
        public void WriteTest()
        {
            IPath outputFile = new BasePath(TestHelperMethods.GetOutputDirectory() + "SimpleTestObject.json");
            SimpleTestObject obj = new SimpleTestObject() { Name = SimpleTestObject.DefaultName, Id = SimpleTestObject.DefaultId };

            //Remove the file if it already exists, so we test that it actually writes a file.
            if (System.IO.File.Exists(outputFile.AbsolutePath))
                System.IO.File.Delete(outputFile.AbsolutePath);

            handler.Write(outputFile, obj);
            Assert.IsTrue(System.IO.File.Exists(outputFile.AbsolutePath));

            obj = handler.Read(outputFile);
            Assert.AreEqual(SimpleTestObject.DefaultName, obj.Name);
            Assert.AreEqual(SimpleTestObject.DefaultId, obj.Id);
        }
예제 #19
0
        public void WriteNullTest()
        {
            IPath outputFile = new BasePath(TestHelperMethods.GetOutputDirectory() + "FileHandlerWriteNullTest.json");
            try
            {
                handler.Write(outputFile, null);
                Assert.Fail("Write null did not throw exception as expected");
            }
            catch (Exception e)
            {
                Assert.IsNotNull(e); //I don't think this will ever fail, but still..
            }
            Assert.IsFalse(System.IO.File.Exists(outputFile.AbsolutePath));

            SimpleTestObject obj = new SimpleTestObject() { Name = SimpleTestObject.DefaultName, Id = SimpleTestObject.DefaultId };
            try
            {
                IPath path = null;
                handler.Write(path, obj);
                Assert.Fail("Write null did not throw exception as expected");
            }
            catch (Exception e)
            {
                Assert.IsNotNull(e); //I don't think this will ever fail, but still..
            }
        }
예제 #20
0
 public void WriteIncorrectPathTest()
 {
     IPath outputFile = new BasePath(":non&existing^%$file.json");
     SimpleTestObject obj = new SimpleTestObject() { Name = SimpleTestObject.DefaultName, Id = SimpleTestObject.DefaultId };
     try
     {
         handler.Write(outputFile, obj);
         Assert.Fail("Write to incorrect path did not throw exception as expected");
     }
     catch (ArgumentException e)
     {
         Assert.IsNotNull(e); //I don't think this will ever fail, but still..
     }
     Assert.IsFalse(System.IO.File.Exists(outputFile.AbsolutePath));
 }
예제 #21
0
 public void ReadTest()
 {
     //Read a simple test object file and check the results.
     IPath path = new BasePath(TestHelperMethods.GetTestFilesDirectory() + "SimpleTestObject.json");
     SimpleTestObject readObj = handler.Read(path);
     Assert.IsNotNull(readObj, "Read object is null");
     Assert.IsNotNull(readObj.Name, "Read object's name is null");
     Assert.AreEqual(SimpleTestObject.DefaultName, readObj.Name, "Read object's name incorrect");
     Assert.AreEqual(SimpleTestObject.DefaultId, readObj.Id, "Read object's Id incorrect");
 }
예제 #22
0
 public void ReadOnlineFileTest()
 {
     SimpleTestObject readObj = null;
     IPath path = new BasePath(TestHelperMethods.GetOnlineTestFilesDirectory() + "SimpleTestObject.json");
     try
     {
         readObj = handler.Read(path);
         Assert.Fail("Read online uri did not throw exception");
     }
     catch (ArgumentException e)
     {
         Assert.IsNotNull(e); //I don't think this will ever fail, but still..
     }
     Assert.IsNull(readObj);
 }
        public void ReadTest()
        {
            // Write installer config.
            this.WriteTest();

            // Read and compare manifest
            JsonFileHandler<InstallerConfiguration> handler = new JsonFileHandler<InstallerConfiguration>();
            IPath path = new BasePath(TestHelperMethods.GetOutputDirectory() + "/myscript" + InstallerConfiguration.DefaultExtension);
            InstallerConfiguration readConfig = handler.Read(path);
            Assert.IsNotNull(readConfig);
            Assert.AreEqual(config.Actions.Count, readConfig.Actions.Count);
            Assert.AreEqual(config, config.Actions[0].Configuration);
            Assert.AreEqual(((CopyFileAction)config.Actions[0]).Source, ((CopyFileAction)readConfig.Actions[0]).Source);
            Assert.AreEqual(((CopyFileAction)config.Actions[0]).Target, ((CopyFileAction)readConfig.Actions[0]).Target);
            Assert.AreEqual(((CopyFileAction)config.Actions[0]).UseScriptId, ((CopyFileAction)readConfig.Actions[0]).UseScriptId);
            Assert.AreEqual(((CopyDirAction)config.Actions[1]).Source, ((CopyDirAction)readConfig.Actions[1]).Source);
            Assert.AreEqual(((CopyDirAction)config.Actions[1]).Target, ((CopyDirAction)readConfig.Actions[1]).Target);
            Assert.AreEqual(((CopyDirAction)config.Actions[1]).UseScriptId, ((CopyDirAction)readConfig.Actions[1]).UseScriptId);
            Assert.AreEqual(((AssignHotkeyAction)config.Actions[2]).Keys, ((AssignHotkeyAction)readConfig.Actions[2]).Keys);
            Assert.AreEqual(((RunMaxscriptAction)config.Actions[3]).Source, ((RunMaxscriptAction)readConfig.Actions[3]).Source);
        }
예제 #24
0
        public void ReadNonExistingFileAsyncTest()
        {
            IPath path = new BasePath("C:/nonexistingfile.json");
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            Exception exception = null;
            handler.ReadComplete += delegate(object sender, ReadCompleteEventArgs<SimpleTestObject> e)
            {
                Assert.Fail("LoadComplete event should not fire when trying to read non-existing file.");
            };
            handler.ReadError += delegate(object sender, ErrorEventArgs e)
            {
                exception = e.Exception;
                manualEvent.Set();
            };
            handler.ReadAsync(path);
            manualEvent.WaitOne(5000, false);
            Assert.IsNotNull(exception);
        }
예제 #25
0
 public void ConstructFromAbsolutePathTest()
 {
     BasePath path = new BasePath("C:/code/");
     RelativePath relPath = new RelativePath("C:/code/test/", path);
     Assert.AreEqual("test/", relPath.RelativePathComponent, "Relative path from constructor when supplying absolute path.");
 }
예제 #26
0
 public void ToUriTest()
 {
     BasePath path = new BasePath("C:/code/test/");
     Uri expected = new Uri("C:/code/test/");
     Assert.AreEqual(expected, path.ToUri(), "ToUri conversion.");
 }
예제 #27
0
        public void GetAbsolutePathTest()
        {
            BasePath path = new BasePath("C:/code/");
            RelativePath relPath = new RelativePath("test/", path);
            Assert.AreEqual("C:/code/test/", relPath.AbsolutePath, "Absolute path.");

            relPath = new RelativePath("../test/", path);
            Assert.AreEqual("C:/test/", relPath.AbsolutePath, "Absolute path 2.");
        }
 public void WriteTest()
 {
     JsonFileHandler<InstallerConfiguration> handler = new JsonFileHandler<InstallerConfiguration>();
     IPath path = new BasePath(TestHelperMethods.GetOutputDirectory() + "/myscript" + InstallerConfiguration.DefaultExtension);
     try
     {
         handler.Write(path, this.config);
     }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }
예제 #29
0
        public void SetRelativeToTest()
        {
            BasePath path = new BasePath("C:/code/");
            BasePath path2 = new BasePath("C:/path/");
            RelativePath relPath = new RelativePath("test/", path);
            Assert.AreEqual("C:/code/test/", relPath.AbsolutePath, "Initial path.");

            relPath.RelativeTo = path2;
            Assert.AreEqual("C:/path/test/", relPath.AbsolutePath, "Absolute path after changing RelativeTo.");

            try
            {
                relPath.RelativeTo = null;
                Assert.Fail("Setting RelativeTo to null should throw ArgumentNullException.");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }
        }
예제 #30
0
        public void ReadOnlineFileAsyncTest()
        {
            IPath path = new BasePath(TestHelperMethods.GetOnlineTestFilesDirectory() + "SimpleTestObject.json");
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            SimpleTestObject obj = null;
            handler.ReadComplete += delegate(object sender, ReadCompleteEventArgs<SimpleTestObject> e)
            {
                obj = e.Data;
                manualEvent.Set();
            };
            handler.ReadError += delegate(object sender, ErrorEventArgs e)
            {
                manualEvent.Set();
            };
            //TODO make sure this really doesn't block the calling thread. The timeout of 15s regardless of waitone seems to suggest that it does..
            handler.ReadAsync(path);
            manualEvent.WaitOne(1000, false);
            Assert.IsNotNull(obj);
            Assert.AreEqual(SimpleTestObject.DefaultName, obj.Name);
            Assert.AreEqual(SimpleTestObject.DefaultId, obj.Id);
        }