public void PreApplicationStartCodeDoesNotForceRecompileIfNewVersionIsV1AndCurrentAssemblyIsNotMaxVersion()
        {
            // Arrange
            Version loadedVersion = null;
            bool    registeredForChangeNotification     = false;
            IEnumerable <AssemblyName> loadedAssemblies = GetAssemblies(LatestVersion, "5.0.0.0");

            var fileSystem = new TestFileSystem();

            fileSystem.AddFile("Index.cshtml");
            var buildManager = new TestBuildManager();
            var content      = AssemblyUtils.ThisAssemblyName.Version + Environment.NewLine;

            buildManager.Stream = new MemoryStream(Encoding.Default.GetBytes(content));

            var nameValueCollection            = GetAppSettings(enabled: null, webPagesVersion: new Version("1.0.0"));
            Action <Version> loadWebPages      = (version) => { loadedVersion = version; };
            Action           registerForChange = () => { registeredForChangeNotification = true; };

            // Act
            bool loaded = PreApplicationStartCode.StartCore(fileSystem, "", @"site\bin", nameValueCollection, loadedAssemblies, buildManager, loadWebPages, registerForChange, null);

            // Assert
            Assert.False(loaded);
            Assert.False(registeredForChangeNotification);
            VerifyVersionFile(buildManager, AssemblyUtils.ThisAssemblyName.Version);
            Assert.False(fileSystem.FileExists(@"site\bin\WebPagesRecompilation.deleteme"));
        }
        public void PreApplicationStartCodeForcesRecompileIfPreviousVersionIsNotTheSameAsCurrentVersion()
        {
            // Arrange
            Version loadedVersion = null;
            bool    registeredForChangeNotification     = false;
            IEnumerable <AssemblyName> loadedAssemblies = GetAssemblies(LatestVersion);

            var fileSystem = new TestFileSystem();

            fileSystem.AddFile("Index.cshtml");
            var buildManager = new TestBuildManager();
            var content      = "1.0.0.0" + Environment.NewLine;

            buildManager.Stream = new MemoryStream(Encoding.Default.GetBytes(content));

            var nameValueCollection            = GetAppSettings(enabled: null, webPagesVersion: new Version(LatestVersion));
            Action <Version> loadWebPages      = (version) => { loadedVersion = version; };
            Action           registerForChange = () => { registeredForChangeNotification = true; };

            // Act
            var ex = Assert.Throws <HttpCompileException>(() =>
                                                          PreApplicationStartCode.StartCore(fileSystem, "", @"site\bin", nameValueCollection, loadedAssemblies, buildManager, loadWebPages, registerForChange, null)
                                                          );

            // Assert
            Assert.Equal("Changes were detected in the Web Pages runtime version that require your application to be recompiled. Refresh your browser window to continue.", ex.Message);
            Assert.Equal(ex.Data["WebPages.VersionChange"], true);
            Assert.False(registeredForChangeNotification);
            VerifyVersionFile(buildManager, new Version(LatestVersion));
            Assert.True(fileSystem.FileExists(@"site\bin\WebPagesRecompilation.deleteme"));
        }
        public void PreApplicationStartCodeDoesNotForceRecompileIfNewVersionIsV1AndCurrentAssemblyIsNotMaxVersion()
        {
            // Arrange
            Version loadedVersion = null;
            bool registeredForChangeNotification = false;
            IEnumerable<AssemblyName> loadedAssemblies = GetAssemblies("2.1.0.0", "5.0.0.0");

            var fileSystem = new TestFileSystem();
            fileSystem.AddFile("Index.cshtml");
            var buildManager = new TestBuildManager();
            var content = AssemblyUtils.ThisAssemblyName.Version + Environment.NewLine;
            buildManager.Stream = new MemoryStream(Encoding.Default.GetBytes(content));

            var nameValueCollection = GetAppSettings(enabled: null, webPagesVersion: new Version("1.0.0"));
            Action<Version> loadWebPages = (version) => { loadedVersion = version; };
            Action registerForChange = () => { registeredForChangeNotification = true; };

            // Act
            bool loaded = PreApplicationStartCode.StartCore(fileSystem, "", @"site\bin", nameValueCollection, loadedAssemblies, buildManager, loadWebPages, registerForChange, null);

            // Assert
            Assert.False(loaded);
            Assert.False(registeredForChangeNotification);
            VerifyVersionFile(buildManager, AssemblyUtils.ThisAssemblyName.Version);
            Assert.False(fileSystem.FileExists(@"site\bin\WebPagesRecompilation.deleteme"));
        }
        public void PreApplicationStartCodeForcesRecompileIfPreviousVersionIsNotTheSameAsCurrentVersion()
        {
            // Arrange
            Version loadedVersion = null;
            bool registeredForChangeNotification = false;
            IEnumerable<AssemblyName> loadedAssemblies = GetAssemblies("2.1.0.0");

            var fileSystem = new TestFileSystem();
            fileSystem.AddFile("Index.cshtml");
            var buildManager = new TestBuildManager();
            var content = "1.0.0.0" + Environment.NewLine;
            buildManager.Stream = new MemoryStream(Encoding.Default.GetBytes(content));

            var nameValueCollection = GetAppSettings(enabled: null, webPagesVersion: new Version("2.1.0.0"));
            Action<Version> loadWebPages = (version) => { loadedVersion = version; };
            Action registerForChange = () => { registeredForChangeNotification = true; };

            // Act
            var ex = Assert.Throws<HttpCompileException>(() =>
                PreApplicationStartCode.StartCore(fileSystem, "", @"site\bin", nameValueCollection, loadedAssemblies, buildManager, loadWebPages, registerForChange, null)
            );

            // Assert
            Assert.Equal("Changes were detected in the Web Pages runtime version that require your application to be recompiled. Refresh your browser window to continue.", ex.Message);
            Assert.Equal(ex.Data["WebPages.VersionChange"], true);
            Assert.False(registeredForChangeNotification);
            VerifyVersionFile(buildManager, new Version("2.1.0.0"));
            Assert.True(fileSystem.FileExists(@"site\bin\WebPagesRecompilation.deleteme"));
        }