当前位置: 首页>>代码示例>>C#>>正文


C# UnitTests.MockEngine类代码示例

本文整理汇总了C#中Microsoft.Build.UnitTests.MockEngine的典型用法代码示例。如果您正苦于以下问题:C# MockEngine类的具体用法?C# MockEngine怎么用?C# MockEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MockEngine类属于Microsoft.Build.UnitTests命名空间,在下文中一共展示了MockEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PokeNoNamespace

        public void PokeNoNamespace()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileNoNs, out xmlInputPath);

            XmlPoke p = new XmlPoke();
            p.BuildEngine = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//variable/@Name";
            p.Value = new TaskItem("Mert");
            p.Execute();

            List<int> positions = new List<int>();
            positions.AddRange(new int[] { 117, 172, 227 });

            string result;
            using (StreamReader sr = new StreamReader(xmlInputPath))
            {
                result = sr.ReadToEnd();
                Regex r = new Regex("Mert");
                MatchCollection mc = r.Matches(result);

                foreach (Match m in mc)
                {
                    Assert.True(positions.Contains(m.Index), "This test should effect 3 positions. There should be 3 occurances of 'Mert'\n" + result);
                }
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:29,代码来源:XmlPoke_Tests.cs

示例2: PeekWithNamespaceNode

        public void PeekWithNamespaceNode()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPeek p = new XmlPeek();
            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//s:variable/.";
            p.Namespaces = "<Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";

            Assert.True(p.Execute()); // "Test should've passed"
            Assert.Equal(3, p.Result.Length); // "result Length should be 3"

            string[] results = new string[] {
                "<s:variable Type=\"String\" Name=\"a\" xmlns:s=\"http://nsurl\"></s:variable>",
                "<s:variable Type=\"String\" Name=\"b\" xmlns:s=\"http://nsurl\"></s:variable>",
                "<s:variable Type=\"String\" Name=\"c\" xmlns:s=\"http://nsurl\"></s:variable>"
            };

            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.True(p.Result[i].ItemSpec.Equals(results[i]), "Results don't match: " + p.Result[i].ItemSpec);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:27,代码来源:XmlPeek_Tests.cs

示例3: TestResourceAccess

        public void TestResourceAccess()
        {
            MyToolTaskExtension t = new MyToolTaskExtension();
            MockEngine engine = new MockEngine();

            t.BuildEngine = engine;

            // No need to actually check the outputted strings. We only care that this doesn't throw, which means that 
            // the resource strings were reachable.

            // Normal CSC messages first, from private XMakeTasks resources. They should be accessible with t.Log
            t.Log.LogErrorWithCodeFromResources("Csc.AssemblyAliasContainsIllegalCharacters", "PlanetSide", "Knights of the Old Republic");
            t.Log.LogWarningWithCodeFromResources("Csc.InvalidParameter");
            t.Log.LogMessageFromResources("Vbc.ParameterHasInvalidValue", "Rome Total War", "Need for Speed Underground");

            // Now shared messages. Should be accessible with the private LogShared property
            PropertyInfo logShared = typeof(ToolTask).GetProperty("LogShared", BindingFlags.Instance | BindingFlags.NonPublic);
            TaskLoggingHelper log = (TaskLoggingHelper)logShared.GetValue(t, null);
            log.LogWarningWithCodeFromResources("Shared.FailedCreatingTempFile", "Gothic II");
            log.LogMessageFromResources("Shared.CannotConvertStringToBool", "foo");

            // Now private Utilities messages. Should be accessible with the private LogPrivate property
            PropertyInfo logPrivate = typeof(ToolTask).GetProperty("LogPrivate", BindingFlags.Instance | BindingFlags.NonPublic);
            log = (TaskLoggingHelper)logPrivate.GetValue(t, null);
            log.LogErrorWithCodeFromResources("ToolTask.CommandTooLong", "Painkiller");
            log.LogWarningWithCodeFromResources("ToolTask.CouldNotStartToolExecutable", "Fallout Tactics", "Fallout 2");
            log.LogMessageFromResources("ToolsLocationHelper.InvalidRedistFile", "Deus Ex", "Fallout");
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:28,代码来源:ToolTaskExtension_Tests.cs

示例4: ResourceAccessSanityCheck

        public void ResourceAccessSanityCheck()
        {
            MyToolTaskExtension t = new MyToolTaskExtension();
            MockEngine engine = new MockEngine();

            t.BuildEngine = engine;
            t.Log.LogErrorFromResources("Beyond Good and Evil");
        }
开发者ID:ravpacheco,项目名称:msbuild,代码行数:8,代码来源:ToolTaskExtension_Tests.cs

示例5: ResourceAccessSanityCheck

        public void ResourceAccessSanityCheck()
        {
            Csc t = new Csc();
            MockEngine engine = new MockEngine();

            t.BuildEngine = engine;
            t.Log.LogErrorFromResources("Beyond Good and Evil");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:8,代码来源:ToolTaskExtension_Tests.cs

示例6: PrepareExecWrapper

 private ExecWrapper PrepareExecWrapper(string command)
 {
     IBuildEngine2 mockEngine = new MockEngine(true);
     ExecWrapper exec = new ExecWrapper();
     exec.BuildEngine = mockEngine;
     exec.Command = command;
     return exec;
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:8,代码来源:Exec_Tests.cs

示例7: NoFileOrDirectory

        public void NoFileOrDirectory()
        {
            WriteCodeFragment task = new WriteCodeFragment();
            MockEngine engine = new MockEngine(true);
            task.BuildEngine = engine;
            task.Language = "c#";
            bool result = task.Execute();

            Assert.AreEqual(false, result);
            engine.AssertLogContains("MSB3711");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:11,代码来源:WriteCodeFragment_Tests.cs

示例8: NoLanguage

        public void NoLanguage()
        {
            WriteCodeFragment task = new WriteCodeFragment();
            MockEngine engine = new MockEngine(true);
            task.BuildEngine = engine;
            task.OutputFile = new TaskItem("foo");
            bool result = task.Execute();

            Assert.AreEqual(false, result);
            engine.AssertLogContains("MSB3098");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:11,代码来源:WriteCodeFragment_Tests.cs

示例9: ResourceAccessSanityCheck

        public void ResourceAccessSanityCheck()
        {
            Assert.Throws<ArgumentException>(() =>
            {
                MyToolTaskExtension t = new MyToolTaskExtension();
                MockEngine engine = new MockEngine();

                t.BuildEngine = engine;
                t.Log.LogErrorFromResources("Beyond Good and Evil");
            }
           );
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:12,代码来源:ToolTaskExtension_Tests.cs

示例10: TestGeneralFrameworkMonikerGood

 public void TestGeneralFrameworkMonikerGood()
 {
     string targetFrameworkMoniker = ".NetFramework, Version=v4.5";
     MockEngine engine = new MockEngine();
     GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
     getReferencePaths.BuildEngine = engine;
     getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
     getReferencePaths.Execute();
     string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
     Assert.Equal(ToolLocationHelper.GetPathToReferenceAssemblies(new FrameworkNameVersioning(targetFrameworkMoniker)).Count, returnedPaths.Length);
     Assert.Equal(0, engine.Errors); // "Expected the log to contain no errors"
 }
开发者ID:cameron314,项目名称:msbuild,代码行数:12,代码来源:GetReferencePaths_Tests.cs

示例11: Setup

        public void Setup()
        {
            // Create a delegate helper to make the testing of a method which uses a lot of fileExists a bit easier
            _mockExists = new MockFileExists(_defaultSdkToolsPath);

            // We need an engine to see any logging messages the method may log
            _mockEngine = new MockEngine();

            // Dummy task to get a TaskLoggingHelper
            TaskToLogFrom loggingTask = new TaskToLogFrom();
            loggingTask.BuildEngine = _mockEngine;
            _log = loggingTask.Log;
            _log.TaskResources = AssemblyResources.PrimaryResources;
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:14,代码来源:SdkToolsPathUtility_Tests.cs

示例12: TestInputChecks1

 public void TestInputChecks1()
 {
     MockEngine engine = new MockEngine();
     SGenExtension sgen = new SGenExtension();
     sgen.BuildEngine = engine;
     sgen.BuildAssemblyName = "MyAsm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" + Path.GetInvalidPathChars()[0];
     sgen.BuildAssemblyPath = "C:\\SomeFolder\\MyAsm.dll";
     sgen.ShouldGenerateSerializer = true;
     sgen.UseProxyTypes = false;
     // This should result in a quoted parameter...
     sgen.KeyFile = "c:\\Some Folder\\MyKeyFile.snk";
     string commandLine = sgen.CommandLine();
     Assert.IsTrue(engine.Errors == 1);
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:14,代码来源:SGen_Tests.cs

示例13: ErrorInNamespaceDecl

        public void ErrorInNamespaceDecl()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPeek p = new XmlPeek();
            p.BuildEngine = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//s:variable/@Name";
            p.Namespaces = "<!THIS IS ERROR Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";

            bool executeResult = p.Execute();
            Assert.IsTrue(engine.Log.Contains("MSB3742"), "Engine Log: " + engine.Log);
            Assert.IsFalse(executeResult, "Execution should've failed");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:16,代码来源:XmlPeek_Tests.cs

示例14: EmptyMessage

        public void EmptyMessage()
        {
            MockEngine e = new MockEngine();
            Message m = new Message();
            m.BuildEngine = e;

            // don't set text

            bool retval = m.Execute();

            Console.WriteLine("===");
            Console.WriteLine(e.Log);
            Console.WriteLine("===");

            Assert.IsTrue(retval);
            Assert.IsTrue(e.Messages == 0);
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:17,代码来源:ErrorWarningMessage_Tests.cs

示例15: SomeInputsFailToCreate

        public void SomeInputsFailToCreate()
        {
            string temp = Path.GetTempPath();
            string file = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38e");
            string dir = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A38f");
            string invalid = "[email protected]#$%^&*()|";
            string dir2 = Path.Combine(temp, "2A333ED756AF4dc392E728D0F864A390");

            try
            {
                FileStream fs = File.Create(file);
                fs.Close(); //we're gonna try to delete it

                MakeDir t = new MakeDir();
                MockEngine engine = new MockEngine();
                t.BuildEngine = engine;

                t.Directories = new ITaskItem[]
                {
                    new TaskItem(dir),
                    new TaskItem(file),
                    new TaskItem(invalid),
                    new TaskItem(dir2)
                };

                bool success = t.Execute();

                Assert.IsTrue(!success);
                Assert.AreEqual(2, t.DirectoriesCreated.Length);
                Assert.AreEqual(dir, t.DirectoriesCreated[0].ItemSpec);
                Assert.AreEqual(dir2, t.DirectoriesCreated[1].ItemSpec);
                Assert.IsTrue
                (
                    engine.Log.Contains
                    (
                        String.Format(AssemblyResources.GetString("MakeDir.Comment"), dir)
                    )
                );
            }
            finally
            {
                Directory.Delete(dir);
                File.Delete(file);
                Directory.Delete(dir2);
            }
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:46,代码来源:MakeDir_Tests.cs


注:本文中的Microsoft.Build.UnitTests.MockEngine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。