Esempio n. 1
0
        public void Test()
        {
            var targetDirectory   = AppDomain.CurrentDomain.BaseDirectory;
            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\MacroResolverProject\");

            var solution = new TestSolution(solutionDirectory);

            solution.RestoreNuget();

            var usageLibrary = solution.Project("UsageLibrary");

            var errors = new List <string>();

            using (var runner = new BuildEngineRunner(usageLibrary.Path))
            {
                var preBuildTask = runner.Create <PreBuildAdaptationExecutionTask>();
                preBuildTask.Setup(usageLibrary);

                preBuildTask.References = usageLibrary.GetReferences().ToArray();
                preBuildTask.Execute();

                var postBuildTask = runner.Create <PostBuildAdaptationExecutionTask>();
                postBuildTask.Execute();
                errors.AddRange(CheckTaskEvents(solutionDirectory, runner.GetEvents(preBuildTask)));
                errors.AddRange(CheckTaskEvents(solutionDirectory, runner.GetEvents(postBuildTask)));
            }
            if (errors.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, errors));
            }
        }
        public void AttributeUsageTest()
        {
            var targetDirectory   = AppDomain.CurrentDomain.BaseDirectory;
            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\GenericProject\");

            var solution     = new TestSolution(solutionDirectory);
            var usageLibrary = solution.Project("UsageLibrary");

            var errors = new List <string>();

            using (var runner = new BuildEngineRunner(usageLibrary.Path))
            {
                var preBuildTask = runner.Create <PreBuildAdaptationExecutionTask>();
                preBuildTask.Setup(usageLibrary);

                preBuildTask.References = usageLibrary.GetReferences().ToArray();
                preBuildTask.Execute();

                var postBuildTask = runner.Create <PostBuildAdaptationExecutionTask>();
                postBuildTask.Execute();

                var preMessages  = runner.GetEvents(preBuildTask).Messages;
                var postMessages = runner.GetEvents(postBuildTask).Messages;
                var preWarnings  = runner.GetEvents(preBuildTask).Warnings;

                errors.AddRange(preWarnings.AssertContains(0, "Unexpected internal error"));

                errors.AddRange(runner.GetEvents(postBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Custom.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Custom.AssertEmpty());

                foreach (AttributeTargets value in Enum.GetValues(typeof(AttributeTargets)))
                {
                    if (value == AttributeTargets.All)
                    {
                        continue;
                    }

                    errors.AddRange(preWarnings.AssertContains(1,
                                                               $"DefinitionLibrary.{value}.EmptyAttribute has no Setup, PreBuid or PostBuild entries. Skipping..."));

                    var expectedCount = 1;
                    if (value == AttributeTargets.Field)
                    {
                        expectedCount = 2;
                    }

                    errors.AddRange(preMessages.AssertContains(expectedCount, string.Join(",", "PreBuild", value, "PreBuildAttribute")));
                    errors.AddRange(postMessages.AssertContains(expectedCount, string.Join(",", "PostBuild", value, "PostBuildAttribute")));
                    errors.AddRange(preMessages.AssertContains(expectedCount, string.Join(",", "PreBuild", value, "AllAttribute")));
                    errors.AddRange(postMessages.AssertContains(expectedCount, string.Join(",", "PostBuild", value, "AllAttribute")));
                }
            }
            if (errors.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, errors));
            }
        }
        public void Test()
        {
            var targetDirectory   = AppDomain.CurrentDomain.BaseDirectory;
            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\GenericProject\");

            var solution     = new TestSolution(solutionDirectory);
            var usageLibrary = solution.Project("UsageAttributeInitialization");

            var errors = new List <string>();

            using (var runner = new BuildEngineRunner(usageLibrary.Path))
            {
                var preBuildTask = runner.Create <PreBuildAdaptationExecutionTask>();
                preBuildTask.Setup(usageLibrary);

                preBuildTask.References = usageLibrary.GetReferences().ToArray();
                preBuildTask.Execute();

                var postBuildTask = runner.Create <PostBuildAdaptationExecutionTask>();
                postBuildTask.Execute();

                errors.AddRange(runner.GetEvents(preBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Custom.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Custom.AssertEmpty());
            }
            if (errors.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, errors));
            }
        }
Esempio n. 4
0
        public void Test()
        {
            var targetDirectory   = AppDomain.CurrentDomain.BaseDirectory;
            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\SetupProject\");

            var solution     = new TestSolution(solutionDirectory);
            var usageLibrary = solution.Project("UsageLibrary");

            var errors = new List <string>();

            using (var runner = new BuildEngineRunner(usageLibrary.Path))
            {
                var preBuildTask = runner.Create <PreBuildAdaptationExecutionTask>();
                preBuildTask.Setup(usageLibrary);

                preBuildTask.References = usageLibrary.GetReferences().ToArray();
                preBuildTask.Execute();

                var postBuildTask = runner.Create <PostBuildAdaptationExecutionTask>();
                postBuildTask.Execute();

                var preBuildMessages = runner.GetEvents(preBuildTask).Messages;
                errors.AddRange(preBuildMessages.AssertContains(1, "@Setup Base"));
                errors.AddRange(preBuildMessages.AssertContains(1, "@Setup EmptyAttribute"));
                errors.AddRange(preBuildMessages.AssertContains(1, "@Setup PostBuildAttribute"));
                errors.AddRange(preBuildMessages.AssertContains(1, "@Setup PreBuildAttribute"));
                errors.AddRange(preBuildMessages.AssertContains(1, "@PreBuildAttribute"));

                if (!errors.Any())
                {
                    for (int i = 0; i < preBuildMessages.Count; i++)
                    {
                        if (preBuildMessages[i].Message.Contains("@Setup base"))
                        {
                            break;
                        }

                        if (preBuildMessages[i].Message.Contains("@Setup EmptyAttribute") ||
                            preBuildMessages[i].Message.Contains("@Setup PostBuildAttribute") ||
                            preBuildMessages[i].Message.Contains("@Setup PreBuildAttribute"))
                        {
                            errors.Add($"Wrong setup call order, {preBuildMessages[i].Message} was before base");
                        }
                    }
                }


                var postBuildMessages = runner.GetEvents(postBuildTask).Messages;
                errors.AddRange(postBuildMessages.AssertContains(1, "@PostBuildAttribute"));

                errors.AddRange(runner.GetEvents(preBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Custom.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Custom.AssertEmpty());
            }
            if (errors.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, errors));
            }
        }
        public void Test()
        {
            var targetDirectory   = AppDomain.CurrentDomain.BaseDirectory;
            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\SourceCodeIsolationProject\");

            var solution = new TestSolution(solutionDirectory);

            solution.RestoreNuget();

            var usageLibrary = solution.Project("UsageLibrary");

            var errors = new List <string>();

            using (var runner = new BuildEngineRunner(usageLibrary.Path))
            {
                var preBuildTask = runner.Create <PreBuildAdaptationExecutionTask>();
                preBuildTask.Setup(usageLibrary);

                preBuildTask.References = usageLibrary.GetReferences().ToArray();
                preBuildTask.Execute();

                errors.AddRange(runner.GetEvents(preBuildTask).Messages.AssertContains(1, string.Join(",", "PreBuild", "Escaped")));
                errors.AddRange(runner.GetEvents(preBuildTask).Messages.AssertContains(2, string.Join(",", "PreBuild", "Mixed")));
                errors.AddRange(runner.GetEvents(preBuildTask).Messages.AssertContains(1, string.Join(",", "PreBuild", "Unescaped")));
                errors.AddRange(runner.GetEvents(preBuildTask).Messages.AssertContains(3, "Suspicious attributes isolation test"));
                errors.AddRange(runner.GetEvents(preBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Custom.AssertEmpty());

                if (errors.Any())
                {
                    Assert.Fail(string.Join(Environment.NewLine, errors));
                }

                var replaceCompileItemsTask = runner.Create <ReplaceCompileItemsTask>();
                replaceCompileItemsTask.Test         = true;
                replaceCompileItemsTask.ItemsCompile = preBuildTask.ArtifactsCompile.Enumerate().Union(preBuildTask.ItemsCompile).ToArray();
                replaceCompileItemsTask.Execute();

                errors.AddRange(runner.GetEvents(replaceCompileItemsTask).Messages.AssertContains(1, "2 files will be replaced"));
                errors.AddRange(runner.GetEvents(replaceCompileItemsTask).Warnings.AssertCount(1));
                errors.AddRange(runner.GetEvents(replaceCompileItemsTask).Warnings.AssertContains(1, "Mixed isolation detected in"));
                errors.AddRange(runner.GetEvents(replaceCompileItemsTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(replaceCompileItemsTask).Custom.AssertEmpty());

                if (errors.Any())
                {
                    Assert.Fail(string.Join(Environment.NewLine, errors));
                }

                Assert.AreEqual(2, replaceCompileItemsTask.CompilesToRemove.Length);
                Assert.AreEqual(2, replaceCompileItemsTask.CompilesToAdd.Length);

                Assert.IsTrue(replaceCompileItemsTask.CompilesToRemove.Count(i => i.ItemSpec.EndsWith("Mixed.cs")) == 1);
                Assert.IsTrue(replaceCompileItemsTask.CompilesToRemove.Count(i => i.ItemSpec.EndsWith("Unescaped.cs")) == 1);
            }
        }
        public void CallOrderingTest()
        {
            var targetDirectory   = AppDomain.CurrentDomain.BaseDirectory;
            var solutionDirectory = Path.Combine(targetDirectory, @"TestReferences\Projects\GenericProject\");

            var solution     = new TestSolution(solutionDirectory);
            var usageLibrary = solution.Project("UsageOrderingLibrary");

            var errors = new List <string>();

            using (var runner = new BuildEngineRunner(usageLibrary.Path))
            {
                var preBuildTask = runner.Create <PreBuildAdaptationExecutionTask>();
                preBuildTask.Setup(usageLibrary);

                preBuildTask.References = usageLibrary.GetReferences().ToArray();
                preBuildTask.Execute();

                var postBuildTask = runner.Create <PostBuildAdaptationExecutionTask>();
                postBuildTask.Execute();

                var preMessages  = runner.GetEvents(preBuildTask).Messages;
                var postMessages = runner.GetEvents(postBuildTask).Messages;

                errors.AddRange(runner.GetEvents(preBuildTask).Warnings.AssertContains(0, "Unexpected internal error"));
                errors.AddRange(runner.GetEvents(postBuildTask).Warnings.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Errors.AssertEmpty());
                errors.AddRange(runner.GetEvents(preBuildTask).Custom.AssertEmpty());
                errors.AddRange(runner.GetEvents(postBuildTask).Custom.AssertEmpty());

                var regex = new Regex("^[^,]+,[^,]+,[^,]+,[^,]+,[^,]+$");

                var sequence = new List <AttributeTargets>
                {
                    AttributeTargets.Assembly,
                    AttributeTargets.Field | AttributeTargets.Event,                                               //event as field
                    AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, //param of method
                    AttributeTargets.Constructor | AttributeTargets.Method,
                    AttributeTargets.Property | AttributeTargets.Event,                                            //event as property
                    AttributeTargets.GenericParameter,                                                             //param of type definition
                    AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate,
                    AttributeTargets.Module
                };

                var filteredMessages = preMessages.Select(m => m.Message).Where(m => regex.IsMatch(m)).ToList();
                var minIndex         = 0;
                for (int i = 0; i < filteredMessages.Count; i++)
                {
                    var message = filteredMessages[i];
                    var index   = sequence.Skip(minIndex)
                                  .ToList()
                                  .FindIndex(p => p.HasFlag((AttributeTargets)Enum.Parse(typeof(AttributeTargets), message.Split(',')[1])));
                    if (index == -1)
                    {
                        Assert.Fail($"Unexpected message {i}: {message} min({minIndex}:{sequence[minIndex]}) position");
                    }
                    minIndex += index;
                }

                filteredMessages = postMessages.Select(m => m.Message).Where(m => regex.IsMatch(m)).ToList();
                minIndex         = 0;
                for (int i = 0; i < filteredMessages.Count; i++)
                {
                    var message = filteredMessages[i];
                    var index   = sequence.Skip(minIndex)
                                  .ToList()
                                  .FindIndex(p => p.HasFlag((AttributeTargets)Enum.Parse(typeof(AttributeTargets), message.Split(',')[1])));
                    if (index == -1)
                    {
                        Assert.Fail($"Unexpected message {i}: {message} min({minIndex}:{sequence[minIndex]}) position");
                    }
                    minIndex += index;
                }
            }
            if (errors.Any())
            {
                Assert.Fail(string.Join(Environment.NewLine, errors));
            }
        }