public void NoIssuesWithExcludeAttributesFile(ApiCompatFrontend frontend)
        {
            using TempFile excludeAttributesFile = TempFile.Create();

            File.WriteAllLines(excludeAttributesFile.Path, new string[] { "T:System.ComponentModel.DesignerAttribute", "T:AttributeDifference.FooAttribute", "T:System.ComponentModel.DefaultValueAttribute" });

            string runOutput = Helpers.RunApiCompat(_implementationPath, new string[] { _contractPath }, new string[] { excludeAttributesFile.Path }, null, null, frontend);

            Assert.Contains("Total Issues: 0", runOutput);
        }
        public void AttributeDifferenceIsFoundWithExcludeAttributesFile(ApiCompatFrontend frontend)
        {
            using TempFile excludeAttributesFile = TempFile.Create();

            File.WriteAllLines(excludeAttributesFile.Path, new string[] { "T:System.ComponentModel.DisplayNameAttribute", "T:AttributeDifference.FooAttribute" });

            string runOutput = Helpers.RunApiCompat(_implementationPath, new string[] { _contractPath }, new string[] { excludeAttributesFile.Path }, "implementation", "contract", frontend);

            Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DesignerAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1' in the implementation but not the contract.", runOutput);
            Assert.Contains("Total Issues: 3", runOutput);
        }
        public void AttributeDifferenceIsFound(ApiCompatFrontend frontend)
        {
            string runOutput = Helpers.RunApiCompat(_implementationPath, _contractPath, "implementation", "contract", frontend);

            Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DesignerAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1' in the implementation but not the contract.", runOutput);
            Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1' in the implementation but not the contract.", runOutput);
            Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'T' on member 'AttributeDifference.AttributeDifferenceClass1.GenericMethodWithAttribute<T>()' in the implementation but not the contract.", runOutput);
            Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'T' on member 'AttributeDifference.AttributeDifferenceClass1.GenericMethodWithAttribute<T>()' in the implementation but not the contract.", runOutput);
            Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1.MethodWithAttribute()' in the implementation but not the contract.", runOutput);
            Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on parameter 'myParameter' on member 'AttributeDifference.AttributeDifferenceClass1.MethodWithAttribute(System.String, System.Object)' in the implementation but not the contract.", runOutput);
            Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'TOne' on member 'AttributeDifference.AttributeDifferenceGenericCLass<TOne, TTwo>' in the implementation but not the contract.", runOutput);
            Assert.Contains("Total Issues: 6", runOutput);
        }
Exemplo n.º 4
0
        public static string RunApiCompat(string left, IEnumerable <string> rightDirs, IEnumerable <string> excludeAttributesFiles, string leftName, string rightName, ApiCompatFrontend frontend)
        {
            using var writer = new StringWriter();
            string frameworkRuntimePath = Path.GetDirectoryName(typeof(object).Assembly.Location);

            if (frontend == ApiCompatFrontend.Console)
            {
                string[] args = GetApiCompatArgs(left, rightDirs, excludeAttributesFiles, leftName, rightName, frameworkRuntimePath);
                new ApiCompatRunner(writer).Run(args);
            }
            else if (frontend == ApiCompatFrontend.MSBuildTask)
            {
                new ApiCompatTask(writer)
                {
                    Contracts = new string[] { left },
                    ImplementationDirectories = rightDirs
                                                .Concat(new string[] { frameworkRuntimePath }).ToArray(),
                    ContractDepends   = new string[] { frameworkRuntimePath },
                    LeftOperand       = leftName,
                    RightOperand      = rightName,
                    ExcludeAttributes = excludeAttributesFiles?.ToArray()
                }.Execute();
            }

            return(writer.ToString());
        }
Exemplo n.º 5
0
 public static string RunApiCompat(string left, string rightDirs, string leftName, string rightName, ApiCompatFrontend frontend) => RunApiCompat(left, new string[] { rightDirs }, Enumerable.Empty <string>(), leftName, rightName, frontend);
Exemplo n.º 6
0
 public static string RunApiCompat(string left, string rightDirs, ApiCompatFrontend frontend) => RunApiCompat(left, rightDirs, null, null, frontend);