Esempio n. 1
0
        public void LoadInfoWithHttp()
        {
            TypefaceReader reader;
            StreamLoader   loader;

            using (var http = new System.Net.Http.HttpClient())
            {
                using (reader = new TypefaceReader(http))
                {
                    Assert.IsNotNull(reader.Loader.Client, "The loader SHOULD have a client as it was provided");

                    var path = RootUrl;
                    path = path + UrlPath;
                    var info = reader.ReadTypeface(path);
                    ValidateHelvetica.AssertInfo(info, path, 8);

                    //check http is set
                    Assert.IsNotNull(reader.Loader.Client, "The loader should STILL have a client as it was provided");
                    Assert.IsFalse(reader.Loader.OwnsClient, "The loader should NOT own the client as it was  provided");

                    loader = reader.Loader;
                }
                //check clean up
                Assert.IsNull(reader.Loader, "The readers loader should have been set to null");
                Assert.IsNull(loader.Client, "The loaders http should have been set to null, but not disposed");

                //Simple check to make sure we are still able to use the http client
                var data = http.GetStringAsync(CheckAliveUrl).Result;
                Assert.IsNotNull(data);
                Assert.IsTrue(data.StartsWith("<Project "));
            }
        }
Esempio n. 2
0
        public void TryLoadFromUrlStream()
        {
            ITypefaceInfo info;
            bool          result;

            using (var reader = new TypefaceReader())
            {
                var path = RootUrl;

                //valid path
                path = path + UrlPath;

                using (var http = new HttpClient())
                {
                    //We need a seekable stream, so download to a buffer and use that.
                    var data = http.GetByteArrayAsync(path).Result;

                    using (var stream = new MemoryStream(data))
                        result = reader.TryReadTypeface(stream, path, out info);

                    Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                    Assert.IsNotNull(info, "Info was not returned");
                    Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                    //check the info
                    ValidateHelvetica.AssertInfo(info, path, 3);
                }
            }
        }
Esempio n. 3
0
        public void LoadInfoFromFullUrl()
        {
            var path = RootUrl;

            using (var reader = new TypefaceReader())
            {
                path = path + UrlPath;
                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 5);
            }
        }
Esempio n. 4
0
        public void LoadInfoFromFilePath()
        {
            using (var reader = new TypefaceReader())
            {
                var path = System.Environment.CurrentDirectory;
                path = Path.Combine(path, PartialFilePath);

                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 2);
            }
        }
Esempio n. 5
0
        public void LoadInfoFromDirectoryAndPath()
        {
            var path = System.Environment.CurrentDirectory;
            var di   = new System.IO.DirectoryInfo(path);

            using (var reader = new TypefaceReader(di))
            {
                path = PartialFilePath;
                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 4);
            }
        }
Esempio n. 6
0
        public void LoadInfoFromFileStream()
        {
            using (var reader = new TypefaceReader())
            {
                var path = System.Environment.CurrentDirectory;
                path = Path.Combine(path, PartialFilePath);

                using (var stream = new FileStream(path, FileMode.Open))
                {
                    var info = reader.ReadTypeface(stream, path);
                    ValidateHelvetica.AssertInfo(info, path, 1);
                }
            }
        }
Esempio n. 7
0
        public async Task AsyncLoadFromRelativeUrlString()
        {
            ITypefaceInfo info;

            var path = RootUrl;

            using (var reader = new TypefaceReader(new Uri(path)))
            {
                //valid path
                path = UrlPath;

                info = await reader.ReadTypefaceAsync(path);

                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path
                ValidateHelvetica.AssertInfo(info, null, 6);
            }
        }
Esempio n. 8
0
        public async Task AsyncLoadFromRelativeFile()
        {
            ITypefaceInfo info;

            var path = System.Environment.CurrentDirectory;

            using (var reader = new TypefaceReader(new DirectoryInfo(path)))
            {
                //valid path
                path = PartialFilePath;
                var file = new FileInfo(path);

                info = await reader.ReadTypefaceAsync(file);

                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path, as this will be changed
                ValidateHelvetica.AssertInfo(info, null, 7);
            }
        }
Esempio n. 9
0
        public async Task AsyncLoadFromAbsoluteUrl()
        {
            ITypefaceInfo info;

            using (var reader = new TypefaceReader())
            {
                var path = RootUrl;

                //valid path
                path = path + UrlPath;
                var uri = new Uri(path);

                info = await reader.ReadTypefaceAsync(uri);

                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info
                ValidateHelvetica.AssertInfo(info, path, 5);
            }
        }
Esempio n. 10
0
        public void TryLoadFromRelativeFile()
        {
            ITypefaceInfo info;
            bool          result;
            var           path = System.Environment.CurrentDirectory;

            using (var reader = new TypefaceReader(new DirectoryInfo(path)))
            {
                //valid path
                path = PartialFilePath;
                var file = new FileInfo(path);

                result = reader.TryReadTypeface(file, out info);

                Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path, as this will be changed
                ValidateHelvetica.AssertInfo(info, null, 7);
            }
        }
Esempio n. 11
0
        public void TryLoadFromRelativeUrl()
        {
            ITypefaceInfo info;
            bool          result;
            var           path = RootUrl;

            using (var reader = new TypefaceReader(new Uri(path)))
            {
                //valid path
                path = UrlPath;
                var uri = new Uri(path, UriKind.Relative);

                result = reader.TryReadTypeface(uri, out info);

                Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path
                ValidateHelvetica.AssertInfo(info, null, 6);
            }
        }
Esempio n. 12
0
        public void LoadInfoFromPartialUrl()
        {
            var            path = RootUrl;
            TypefaceReader reader;
            StreamLoader   loader;

            using (reader = new TypefaceReader(new Uri(path)))
            {
                path = UrlPath;
                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 6);

                //check http is set
                Assert.IsNotNull(reader.Loader.Client, "The loader should have a client as it was not provided, but needed");
                Assert.IsTrue(reader.Loader.OwnsClient, "The loader should own the client as it was not provided");

                loader = reader.Loader;
            }
            //check clean up
            Assert.IsNull(reader.Loader, "The readers loader should have been set to null");
            Assert.IsNull(loader.Client, "The loaders http should have been disposed and set to null");
        }
Esempio n. 13
0
        public void TryLoadFromAbsoluteUrl()
        {
            ITypefaceInfo info;
            bool          result;

            using (var reader = new TypefaceReader())
            {
                var path = RootUrl;

                //valid path
                path = path + UrlPath;
                var uri = new Uri(path);

                result = reader.TryReadTypeface(uri, out info);

                Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info
                ValidateHelvetica.AssertInfo(info, path, 5);
            }
        }
Esempio n. 14
0
        public void TryLoadFromFileStream()
        {
            ITypefaceInfo info;
            bool          result;

            using (var reader = new TypefaceReader())
            {
                // Success
                FileStream stream;

                var path = System.Environment.CurrentDirectory;
                path = Path.Combine(path, PartialFilePath);

                using (stream = new FileStream(path, FileMode.Open))
                {
                    result = reader.TryReadTypeface(stream, path, out info);
                }

                Assert.IsTrue(result, "Could not read the valid input from a stream");
                Assert.IsNotNull(info, "The info was not returned for the try method");
                ValidateHelvetica.AssertInfo(info, path, 1);
            }
        }