public async Task ShouldResolveAssetPath()
        {
            // after the manifest file was deleted
            // the asset path should still resolve

            using (var context = new StaticTestContext())
            {
                var assetPathMapper = context.GetAssetPathMapper();

                // baseline: the asset path mapper should
                // resolve the asset path
                var assetPath = await assetPathMapper("index.js");

                Assert.Equal(context.AssetPath, assetPath);

                // recreate the manifest directory
                // the asset path mapper should resolve the new asset path
                context.DeleteManifest();
                await context.WaitForStorageUpdate();

                assetPath = await assetPathMapper("index.js");

                Assert.Equal(context.AssetPath, assetPath);
            }
        }
示例#2
0
        public async Task ShouldResolveNewAssetPath()
        {
            // here we're testing that the SUT
            // detects the changes to the manifest file,
            // reloads it and resolves the new asset path

            using (var context = new StaticTestContext())
            {
                var assetPathMapper = context.GetAssetPathMapper();

                // baseline: the asset path mapper should
                // resolve the original asset path
                var assetPath = await assetPathMapper("index.js");

                Assert.Equal(context.AssetPath, assetPath);

                // rewrite the manifest file
                // the asset path mapper should resolve the new asset path
                await context.RewriteManifestFileAsync();

                await context.WaitForStorageContentsUpdate();

                assetPath = await assetPathMapper("index.js");

                Assert.Equal(context.AltAssetPath, assetPath);
            }
        }
        public async Task ShouldResolveNewAssetPath()
        {
            // here we're testing that the SUT
            // detects that the manifest folder was recreated,
            // reloads the manifest it and resolves the new asset path

            using (var context = new StaticTestContext())
            {
                var assetPathMapper = context.GetAssetPathMapper();

                // baseline: the asset path mapper should
                // resolve the original asset path
                var assetPath = await assetPathMapper("index.js");

                Assert.Equal(context.AssetPath, assetPath);

                // recreate the manifest directory
                // the asset path mapper should resolve the new asset path
                context.DeployAltAssets();
                await context.WaitForStorageContentsUpdate();

                assetPath = await assetPathMapper("index.js");

                Assert.Equal(context.AltAssetPath, assetPath);
            }
        }
        public async Task ShouldSkipSrcAttribute()
        {
            // here we're testing that the asset path mapper
            // correctly injected a valid asset path
            // into the razor view

            using (var context = new StaticTestContext())
            {
                var response = await context.Client.GetAsync("/Test/IndexInvalidAssetKey");

                var responseContent = await response.Content.ReadAsStringAsync();

                var content = $"<script></script>";

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(content, responseContent);
            }
        }
        public async Task ShouldServeItWithValidContentAndHeaders()
        {
            // we want to test that the SUT uses
            // specified settings to serve a static asset
            // with static file middleware

            using (var context = new StaticTestContext())
            {
                var assetPathMapper = context.GetAssetPathMapper();
                var assetPath       = await assetPathMapper("index.js");

                var response = await context.Client.GetAsync(assetPath);

                var responseContent = await response.Content.ReadAsStringAsync();

                var fileContent = await context.GetAssetFileContents();

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(fileContent, responseContent);
                Assert.Equal("public, max-age=31536000", response.Headers.CacheControl.ToString());
            }
        }