Ejemplo n.º 1
0
        public void GetEmbeddedJavaScript_PreparesJavaScriptCorrectly(string resource, string expectedResult)
        {
            // Arrange
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(resource));
            var getManifestResourceStream = new Func <string, Stream>(name => stream);
            var cache = new ConcurrentDictionary <string, string>();

            // Act
            var result = JavaScriptResources.GetEmbeddedJavaScript("test.js", getManifestResourceStream, cache);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 2
0
        public void GetEmbeddedJavaScript_LoadsEmbeddedResourceFromManifestStream()
        {
            // Arrange
            var resource = "window.alert('An alert');";
            var stream   = new MemoryStream(Encoding.UTF8.GetBytes(resource));
            var getManifestResourceStream = new Func <string, Stream>(name => stream);
            var cache = new ConcurrentDictionary <string, string>();

            // Act
            var result = JavaScriptResources.GetEmbeddedJavaScript("test.js", getManifestResourceStream, cache);

            // Assert
            Assert.Equal(resource, result);
        }
Ejemplo n.º 3
0
        public void GetEmbeddedJavaScript_AddsResourceToCacheWhenRead()
        {
            // Arrange
            var resource = "window.alert('An alert');";
            var stream   = new MemoryStream(Encoding.UTF8.GetBytes(resource));
            var getManifestResourceStream = new Func <string, Stream>(name => stream);
            var cache = new ConcurrentDictionary <string, string>();

            // Act
            var result = JavaScriptResources.GetEmbeddedJavaScript("test.js", getManifestResourceStream, cache);

            // Assert
            Assert.Collection(cache, kvp =>
            {
                Assert.Equal("test.js", kvp.Key);
                Assert.Equal(resource, kvp.Value);
            });
        }
Ejemplo n.º 4
0
        public void GetEmbeddedJavaScript_LoadsResourceFromCacheAfterInitialCall()
        {
            // Arrange
            var resource  = "window.alert('An alert');";
            var stream    = new MemoryStream(Encoding.UTF8.GetBytes(resource));
            var callCount = 0;
            var getManifestResourceStream = new Func <string, Stream>(name =>
            {
                callCount++;
                return(stream);
            });
            var cache = new ConcurrentDictionary <string, string>();

            // Act
            var result = JavaScriptResources.GetEmbeddedJavaScript("test.js", getManifestResourceStream, cache);

            result = JavaScriptResources.GetEmbeddedJavaScript("test.js", getManifestResourceStream, cache);

            // Assert
            Assert.Equal(1, callCount);
        }