コード例 #1
0
        /// <summary>
        /// Ensure the server is built.
        /// </summary>
        private void EnsureServer()
        {
            if (_server != null)
            {
                return;
            }

            EnsureDepsFile();

            var localDebugPath = EntryPointAssembly
                                 .GetCustomAttribute <LocalDebugPathAttribute>();

            if (localDebugPath == null)
            {
                throw new InvalidOperationException("Invalid assembly information.");
            }
            if (!Directory.Exists(localDebugPath.Path))
            {
                throw new InvalidOperationException($"Invalid assembly debug path \"{localDebugPath.Path}\".");
            }

            _host = CreateHostBuilder()
                    .UseEnvironment("Testing")
                    .ConfigureWebHost(builder =>
            {
                builder.UseContentRoot(localDebugPath.Path);
                builder.UseTestServer();
            })
                    .Build();

            PrepareHost(_host);
            _host.Start();
            _server = (TestServer)_host.Services.GetRequiredService <IServer>();
        }
コード例 #2
0
        /// <summary>
        /// Ensure the deps file is present.
        /// </summary>
        private void EnsureDepsFile()
        {
            if (EntryPointAssembly?.EntryPoint == null)
            {
                throw new InvalidOperationException("Invalid assembly entry point.");
            }
            var depsFileName = $"{EntryPointAssembly.GetName().Name}.deps.json";
            var depsFile     = new FileInfo(Path.Combine(AppContext.BaseDirectory, depsFileName));

            if (!depsFile.Exists)
            {
                throw new InvalidOperationException($"Missing deps file {depsFile.FullName}. Please make sure your test project made package-reference to Microsoft.AspNetCore.Mvc.Testing.");
            }
        }
コード例 #3
0
        bool GenerateManifest()
        {
            const string depNS = "http://schemas.microsoft.com/client/2007/deployment";

            string template = null;
            var    manifest = ManifestFile.ItemSpec;

            Log.LogMessage(MessageImportance.Normal, "Generating manifest file {0}", manifest);

            if (SilverlightManifestTemplate != null)
            {
                template = String.IsNullOrEmpty(SilverlightManifestTemplate.ItemSpec) ?
                           null :
                           SilverlightManifestTemplate.GetMetadata("FullPath");
            }

            XmlDocument doc = new XmlDocument();

            if (template != null)
            {
                if (!File.Exists(template))
                {
                    Log.LogError("Could not find manifest template '" + template + "'.");
                    return(false);
                }

                try
                {
                    doc.Load(template);
                }
                catch (XmlException ex)
                {
                    Log.LogError(null, null, null, template, ex.LineNumber, ex.LinePosition, 0, 0,
                                 "Error loading manifest template '" + ex.Source);
                    return(false);
                }
                catch (Exception ex)
                {
                    Log.LogError("Could not load manifest template '" + template + "'.");
                    Log.LogMessage(MessageImportance.Low, "Could not load manifest template '" + template + "': " + ex.ToString());
                    return(false);
                }
            }
            else
            {
                doc.LoadXml(@"<Deployment xmlns=""http://schemas.microsoft.com/client/2007/deployment"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""></Deployment>");
            }

            try
            {
                XmlNode deploymentNode = doc.DocumentElement;
                if (deploymentNode == null || deploymentNode.Name != "Deployment" || deploymentNode.NamespaceURI != depNS)
                {
                    Log.LogError("Missing or invalid root <Deployment> element in manifest template '" + template + "'.");
                    return(false);
                }
                if (deploymentNode.Attributes["EntryPointAssembly"] == null)
                {
                    deploymentNode.Attributes.Append(doc.CreateAttribute("EntryPointAssembly")).Value =
                        EntryPointAssembly.GetMetadata("Filename");
                }

                if (!String.IsNullOrEmpty(SilverlightAppEntry) && deploymentNode.Attributes["EntryPointType"] == null)
                {
                    deploymentNode.Attributes.Append(doc.CreateAttribute("EntryPointType")).Value = SilverlightAppEntry;
                }

                if (deploymentNode.Attributes["RuntimeVersion"] == null)
                {
                    //FIXME:

                    /*string fxVersion = MoonlightFrameworkBackend.GetFxVersion (proj.TargetFramework);
                     *
                     * if (proj.TargetRuntime is MonoDevelop.Core.Assemblies.MonoTargetRuntime) {
                     *      var package = proj.TargetRuntime.RuntimeAssemblyContext.GetPackage ("moonlight-web-" + fxVersion);
                     *      if (package != null && package.IsFrameworkPackage) {
                     *              runtimeVersion = package.Version;
                     *      } else {
                     *              LoggingService.LogWarning ("Moonlight core framework package not found, cannot determine " +
                     *                      "runtime version string. Falling back to default value.");
                     *      }
                     * }*/

                    deploymentNode.Attributes.Append(doc.CreateAttribute("RuntimeVersion")).Value =
                        String.IsNullOrEmpty(RuntimeVersion) ? "2.0.31005.0" : RuntimeVersion;
                }

                XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                mgr.AddNamespace("dep", depNS);
                XmlNode partsNode = deploymentNode.SelectSingleNode("dep:Deployment.Parts", mgr);
                if (partsNode == null)
                {
                    partsNode = deploymentNode.AppendChild(doc.CreateElement("Deployment.Parts", depNS));
                }

                AddAssemblyPart(doc, partsNode, EntryPointAssembly);

                foreach (ITaskItem ref_item in References)
                {
                    AddAssemblyPart(doc, partsNode, ref_item);
                }
            }
            catch (XmlException ex)
            {
                Log.LogError(null, null, null, template, ex.LineNumber, ex.LinePosition, 0, 0,
                             "Error processing manifest template: '" + ex.Source);
                return(false);
            }

            doc.Save(manifest);

            return(true);
        }