Beispiel #1
0
        public void Resolve_with_protocol_and_special_home_character()
        {
            FileInfo fileInfo = CreateFileForTheCurrentDirectory();

            CustomUriBuilder builder = new CustomUriBuilder("file://~/" + TemporaryFileName, null);

            Assert.AreEqual(fileInfo.FullName, builder.Uri.LocalPath,
                            "The file name with file://~ must have resolved to a file " +
                            "in the current directory of the currently executing domain.");
        }
Beispiel #2
0
        public void Resolve_with_protocol_and_special_home_character_in_parent_directory()
        {
            FileInfo file = new FileInfo(Path.GetFullPath(
                                             Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemporaryFileName)));

            CustomUriBuilder builder = new CustomUriBuilder("file://~/../" + TemporaryFileName, string.Empty);

            string fileNameOneDirectoryUp = file.Directory.Parent.FullName + "\\" + TemporaryFileName;

            Assert.AreEqual(fileNameOneDirectoryUp, builder.Uri.LocalPath,
                            "The file name with file://~/.. must have resolved to a file " +
                            "in the parent directory of the currently executing domain.");
        }
        public void CreateWithRelativePath()
        {
            string file = @"../NUnit/CommonTests/Utilities/sample.txt";

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            IResource resource = loader.Create(builder.Uri);

            Assert.IsNotNull(resource);

            TextReader reader = new StreamReader(resource.Stream);
            string line = reader.ReadLine();
            Assert.That(line, Is.EqualTo("hello"));
        }
        public void Url_should_raise_exception_FileNotFoundException_on_FileInfo_property()
        {
            string uri = "http://www.apache.org/";

            CustomUriBuilder builder = new CustomUriBuilder(uri, AppDomain.CurrentDomain.BaseDirectory);

            using (IResource resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                FileInfo file = resource.FileInfo;
                file.GetType();
            }
        }
        public void CreateWithAbsolutePath()
        {
            string file = "file://"+Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\NUnit\CommonTests\Utilities\sample.txt");

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            IResource resource = loader.Create(builder.Uri);

            Assert.IsNotNull(resource);

            TextReader reader = new StreamReader(resource.Stream);
            string line = reader.ReadLine();
            Assert.That(line, Is.EqualTo("hello"));
        }
Beispiel #6
0
        public void CreateWithRelativePath()
        {
            string file = @"../NUnit/CommonTests/Utilities/sample.txt";

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            IResource resource = loader.Create(builder.Uri);

            Assert.IsNotNull(resource);

            TextReader reader = new StreamReader(resource.Stream);
            string     line   = reader.ReadLine();

            Assert.That(line, Is.EqualTo("hello"));
        }
Beispiel #7
0
        public void CreateWithAbsolutePath()
        {
            string file = "file://" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\NUnit\CommonTests\Utilities\sample.txt");

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            IResource resource = loader.Create(builder.Uri);

            Assert.IsNotNull(resource);

            TextReader reader = new StreamReader(resource.Stream);
            string     line   = reader.ReadLine();

            Assert.That(line, Is.EqualTo("hello"));
        }
Beispiel #8
0
        public void Test_resource_creation_in_same_base_directory_with_Relative()
        {
            string file = "SqlMap_MSSQL_SqlClient.config";

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            using (IResource resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    string line = reader.ReadLine();
                    Assert.That(line, Is.EqualTo(@"<?xml version=""1.0"" encoding=""utf-8""?>"));
                }
            }
        }
Beispiel #9
0
        public void Test_resource_creation_with_absolute_path_and_slash()
        {
            string file = "file:///" + Common.Resources.Resources.ApplicationBase + Path.DirectorySeparatorChar + "SqlMap_MSSQL_SqlClient.config";

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            using (IResource resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    string line = reader.ReadLine();
                    Assert.That(line, Is.EqualTo(@"<?xml version=""1.0"" encoding=""utf-8""?>"));
                }
            }
        }
Beispiel #10
0
        public void Test_resource_creation_with_relative_path()
        {
            string file = @"../../Fixtures/Utilities/sample.txt";

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            using (IResource resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    string line = reader.ReadLine();
                    Assert.That(line, Is.EqualTo("hello"));
                }
            }
        }
Beispiel #11
0
        public void Test_resource_creation_with_absolute_path()
        {
            string file = "file://" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\Fixtures\Utilities\sample.txt");

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            using (IResource resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    string line = reader.ReadLine();
                    Assert.That(line, Is.EqualTo("hello"));
                }
            }
        }
        /// <summary>
        /// ConfigurationWatcher Test
        /// </summary>
        [Test] public void ConfigurationWatcherTest()
        {
            //Assembly a = Assembly.GetExecutingAssembly();
            //Uri uri = new System.Uri(a.CodeBase);
            //string binDirectory = Path.GetDirectoryName(uri.LocalPath);
            string   fileName = "test.config";
            FileInfo fi       = new FileInfo(fileName);

            if (!fi.Exists)
            {
                using (FileStream fs = fi.Create());
            }


            // Configure a watcher
            ConfigureHandler configureDelegate = new ConfigureHandler(Configure);

            ConfigWatcherHandler.ClearFilesMonitored();

            CustomUriBuilder builder = new CustomUriBuilder(fileName, AppDomain.CurrentDomain.BaseDirectory);

            IResource resource = new FileResource(builder.Uri);

            ConfigWatcherHandler.AddFileToWatch(resource.FileInfo);

            TimerCallback callBakDelegate = new TimerCallback(ConfigWatcherTest.OnConfigFileChange);

            StateConfig state = new StateConfig();

            state.FileName         = fileName;
            state.ConfigureHandler = configureDelegate;

            new ConfigWatcherHandler(callBakDelegate, state);

            resource.FileInfo.LastWriteTime = DateTime.Now;

            resource.FileInfo.Refresh();

            // Let's give a small bit of time for the change to propagate.
            // The ConfigWatcherHandler class has a timer which
            // waits for 500 Millis before delivering
            // the event notification.
            System.Threading.Thread.Sleep(600);

            Assert.IsTrue(_hasChanged);
        }
        [Test(Description = "Create With Relative Path")] public void Test_resource_creation_with_relative_path()
        {
            var relPath = Utility.GetAssemblyRelativeBasePath("Fixtures/Utilities/sample.txt");
            var file    = relPath + @"Fixtures/Utilities/sample.txt";

            var builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);

            using (var resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    var line = reader.ReadLine();
                    Assert.That(line, Is.EqualTo("hello"));
                }
            }
        }
Beispiel #14
0
        public void Test_resource_creation_with_special_uri_character()
        {
            string path = Path.GetFullPath("dir#");

            Directory.CreateDirectory(path);
            string filePath = Path.Combine(path, "file.txt");

            using (StreamWriter text = File.CreateText(filePath))
            {
                text.WriteLine("hello world");
            }

            CustomUriBuilder builder = new CustomUriBuilder(filePath, AppDomain.CurrentDomain.BaseDirectory);

            using (IResource resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    Assert.That(reader.ReadLine(), Is.EqualTo("hello world"));
                }
            }
        }
        [Test] public void Test_resource_creation_with_space_in_path()
        {
            var path = Path.GetFullPath("spaced dir");

            Directory.CreateDirectory(path);
            var filePath = Path.Combine(path, "spaced file.txt");

            using (var text = File.CreateText(filePath))
            {
                text.WriteLine("hello world");
            }

            var builder = new CustomUriBuilder("file://" + filePath, AppDomain.CurrentDomain.BaseDirectory);

            using (var resource = loader.Create(builder.Uri))
            {
                Assert.IsNotNull(resource);

                using (TextReader reader = new StreamReader(resource.Stream))
                {
                    Assert.That(reader.ReadLine(), Is.EqualTo("hello world"));
                }
            }
        }
Beispiel #16
0
        public void Non_existing_resource_should_raise_ResourceException()
        {
            string file = "/Something/file1.txt";

            CustomUriBuilder builder = new CustomUriBuilder(file, AppDomain.CurrentDomain.BaseDirectory);
        }