Example #1
0
        public void HashString_NullContent()
        {
            var hasher = new Hasher(new Mock<IRetryableFileOpener>(MockBehavior.Strict).Object);

            var ex = Assert.Throws<InvalidOperationException>(() => hasher.GetHash((string)null));

            Assert.AreEqual("Can't calculate hash for null content.", ex.Message);
        }
Example #2
0
        public void HashString(string content, string expectedHash)
        {
            var hasher = new Hasher(new Mock<IRetryableFileOpener>(MockBehavior.Strict).Object);

            var hash = hasher.GetHash(content);

            Assert.AreEqual(expectedHash, hash);
        }
Example #3
0
        public void HashFileInfo_FileDoesntExist()
        {
            var info = new FileInfo("fakeFile");
            var hasher = new Hasher(new RetryableFileOpener());
            var ex = Assert.Throws<FileNotFoundException>(() => hasher.GetHash(info));
            //mono 3 uses " instead of ' around file name
			Assert.True(ex.Message.StartsWith("Could not find file"));
			Assert.True(ex.Message.Contains(info.FullName));
        }
Example #4
0
        public void HashFileInfo(string data)
        {
            var info = new FileInfo(data);

            var retryableFileOpener = new Mock<IRetryableFileOpener>(MockBehavior.Strict);
            retryableFileOpener.Setup(rfo => rfo.OpenFileStream(info, 5, FileMode.Open, FileAccess.Read, FileShare.Read))
                .Returns(new MemoryStream(Encoding.ASCII.GetBytes(data)));

            var hasher = new Hasher(retryableFileOpener.Object);

            Assert.AreEqual(hasher.GetHash(data), hasher.GetHash(info));
        }
        public void CanRenderDistinctBundlesIfSameOutputButDifferentFileNames()
        {
            var hasher = new Hasher(new RetryableFileOpener());

            javaScriptBundleFactory.FileReaderFactory.SetContents(javaScript);

            var tag = javaScriptBundleFactory
                        .WithHasher(hasher)
                        .Create()
                        .Add("~/js/test.js")
                        .Render("~/js/output#.js");

            javaScriptBundleFactory.FileReaderFactory.SetContents(javaScript2);

            var tag2 = javaScriptBundleFactory
                        .WithHasher(hasher)
                        .Create()
                        .Add("~/js/test2.js")
                        .Render("~/js/output#.js");

            Assert.AreNotEqual(tag, tag2);
        }
        public void CanRenderDistinctBundlesIfSameOutputButDifferentArbitrary()
        {
            var hasher = new Hasher(new RetryableFileOpener());

            var tag = javaScriptBundleFactory
                    .WithHasher(hasher)
                    .Create()
                    .AddString(javaScript)
                    .Render("~/js/output#.js");

            var tag2 = javaScriptBundleFactory
                    .WithHasher(hasher)
                    .Create()
                    .AddString(javaScript2)
                    .Render("~/js/output#.js");

            Assert.AreNotEqual(tag, tag2);
        }
Example #7
0
        public void CanRenderDistinctBundlesIfSameOutputButDifferentFileNames()
        {
            var hasher = new Hasher(new RetryableFileOpener());

            CSSBundle cssBundle = cssBundleFactory
                .WithHasher(hasher)
                .WithDebuggingEnabled(false)
                .Create();

            CSSBundle cssBundle2 = cssBundleFactory
                .WithHasher(hasher)
                .WithDebuggingEnabled(false)
                .Create();

            cssBundleFactory.FileReaderFactory.SetContents(css);

            string tag = cssBundle
                            .Add("/css/first.css")
                            .Render("/css/output#.css");

            cssBundleFactory.FileReaderFactory.SetContents(css2);

            string tag2 = cssBundle2
                            .Add("/css/second.css")
                            .Render("/css/output#.css");

            Assert.AreNotEqual(tag, tag2);
        }
Example #8
0
        public void CanRenderDistinctBundlesIfSameOutputButDifferentArbitrary()
        {
            var hasher = new Hasher(new RetryableFileOpener());

            CSSBundle cssBundle = cssBundleFactory
                .WithHasher(hasher)
                .WithDebuggingEnabled(false)
                .Create();

            CSSBundle cssBundle2 = cssBundleFactory
                .WithHasher(hasher)
                .WithDebuggingEnabled(false)
                .Create();

            string tag = cssBundle
                            .AddString(css)
                            .Render("/css/output#.css");

            string tag2 = cssBundle2
                            .AddString(css2)
                            .Render("/css/output#.css");

            Assert.AreNotEqual(tag, tag2);
        }