public void PreApplicationStartCodeThrowsIfVersionSpecifiedInConfigIsNotAvailable()
        {
            // Arrange
            Version loadedVersion = null;

            var binDirectory = DeploymentUtil.GetBinDirectory();
            IEnumerable <AssemblyName> loadedAssemblies = GetAssemblies("1.0.0.0", AssemblyUtils.ThisAssemblyName.Version.ToString());

            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.5"));
            Action <Version> loadWebPages      = (version) => { loadedVersion = version; };
            Action           registerForChange = () => { };

            // Act and Assert
            Assert.Throws <InvalidOperationException>(() =>
                                                      PreApplicationStartCode.StartCore(fileSystem, "", binDirectory, nameValueCollection, loadedAssemblies, buildManager: buildManager, loadWebPages: loadWebPages, registerForChangeNotification: registerForChange, getAssemblyNameThunk: null),
                                                      String.Format("Specified Web Pages version \"1.5.0.0\" could not be found. Update your web.config to specify a different version. Current version: \"{0}\".",
                                                                    AssemblyUtils.ThisAssemblyName.Version));
        }
        public void PreApplicationStartCodeDoesNotLoadIfAHigherVersionIsAvailableInBin()
        {
            // Arrange
            Version loadedVersion = null;
            bool    registeredForChangeNotification     = false;
            IEnumerable <AssemblyName> loadedAssemblies = GetAssemblies(LatestVersion, "8.0.0.0");

            var binDirectory = DeploymentUtil.GetBinDirectory();

            var fileSystem = new TestFileSystem();

            fileSystem.AddFile("Index.cshtml");
            fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
            var buildManager        = new TestBuildManager();
            var nameValueCollection = GetAppSettings(enabled: null, webPagesVersion: null);
            Action <Version>            loadWebPages      = (version) => { loadedVersion = version; };
            Action                      registerForChange = () => { registeredForChangeNotification = true; };
            Func <string, AssemblyName> getAssembyName    = _ => new AssemblyName("System.Web.WebPages.Deployment, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            // Act
            bool loaded = PreApplicationStartCode.StartCore(fileSystem, "", binDirectory, nameValueCollection, loadedAssemblies, buildManager, loadWebPages, registerForChange, getAssembyName);

            // Assert
            Assert.False(loaded);
            Assert.Null(loadedVersion);
            Assert.False(registeredForChangeNotification);
            Assert.Equal(0, buildManager.Stream.Length);
        }
        public void PreApplicationStartCodeThrowsIfVersionIsSpecifiedInConfigAndDifferentVersionExistsInBin()
        {
            // Arrange
            Version loadedVersion = null;

            var binDirectory = DeploymentUtil.GetBinDirectory();
            IEnumerable <AssemblyName> loadedAssemblies = GetAssemblies("1.0.0.0", AssemblyUtils.ThisAssemblyName.Version.ToString());

            var fileSystem = new TestFileSystem();

            fileSystem.AddFile("Index.cshtml");
            fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
            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 = () => { };
            Func <string, AssemblyName> getAssembyName    = _ => new AssemblyName("System.Web.WebPages.Deployment, Version=" + AssemblyUtils.ThisAssemblyName.Version + ", Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            // Act and Assert
            Assert.Throws <InvalidOperationException>(() =>
                                                      PreApplicationStartCode.StartCore(fileSystem, "", binDirectory, nameValueCollection, loadedAssemblies, buildManager: buildManager, loadWebPages: loadWebPages, registerForChangeNotification: registerForChange, getAssemblyNameThunk: getAssembyName),
                                                      String.Format(@"Conflicting versions of ASP.NET Web Pages detected: specified version is ""1.0.0.0"", but the version in bin is ""{0}"". To continue, remove files from the application's bin directory or remove the version specification in web.config.",
                                                                    AssemblyUtils.ThisAssemblyName.Version));
        }
Example #4
0
        public void PreApplicationStartCodeDoesNothingIfItIsAvailableInBinAndFileExistsInRootOfWebSite()
        {
            // Arrange
            Version loadedVersion = null;
            bool    registeredForChangeNotification = false;
            var     webPagesVersion = AssemblyUtils.ThisAssemblyName.Version;
            IEnumerable <AssemblyName> loadedAssemblies = GetAssemblies(AssemblyUtils.ThisAssemblyName.Version.ToString());

            var fileSystem   = new TestFileSystem();
            var binDirectory = DeploymentUtil.GetBinDirectory();

            var buildManager = new TestBuildManager();

            fileSystem.AddFile("Default.cshtml");
            fileSystem.AddFile(Path.Combine(binDirectory, "System.Web.WebPages.Deployment.dll"));
            var nameValueCollection = GetAppSettings(enabled: null, webPagesVersion: null);
            Action <Version>            loadWebPages      = (version) => { loadedVersion = version; };
            Action                      registerForChange = () => { registeredForChangeNotification = true; };
            Func <string, AssemblyName> getAssembyName    = _ => new AssemblyName("System.Web.WebPages.Deployment, Version=" + AssemblyUtils.ThisAssemblyName.Version.ToString() + ", Culture=neutral, PublicKeyToken=2f9147bba06de483");

            // Act
            bool loaded = PreApplicationStartCode.StartCore(fileSystem, "", binDirectory, nameValueCollection, loadedAssemblies, buildManager, loadWebPages, registerForChange, getAssembyName);

            // Assert
            Assert.False(loaded);
            Assert.Null(loadedVersion);
            Assert.False(registeredForChangeNotification);
            Assert.Equal(0, buildManager.Stream.Length);
        }