コード例 #1
0
        private static bool DoesContractContainBreakingChanges(string dllName, string baselinePath, string breakingChangesPath)
        {
            TypeTree locally = new TypeTree(typeof(object));

            ContractEnforcement.BuildTypeTree(locally, ContractEnforcement.GetAssemblyLocally(dllName).GetExportedTypes());

            TypeTree baseline = JsonConvert.DeserializeObject <TypeTree>(File.ReadAllText(baselinePath));

            string localJson = JsonConvert.SerializeObject(locally, Formatting.Indented);

            File.WriteAllText($"{breakingChangesPath}", localJson);
            string baselineJson = JsonConvert.SerializeObject(baseline, Formatting.Indented);

            System.Diagnostics.Trace.TraceWarning($"String length Expected: {baselineJson.Length};Actual:{localJson.Length}");
            if (string.Equals(localJson, baselineJson, StringComparison.InvariantCulture))
            {
                return(false);
            }
            else
            {
                System.Diagnostics.Trace.TraceWarning($"Expected: {baselineJson}");
                System.Diagnostics.Trace.TraceWarning($"Actual: {localJson}");
                return(true);
            }
        }
コード例 #2
0
        private static bool CheckBreakingChanges(string dllName, string baselinePath, string breakingChangesPath)
        {
            TypeTree locally = new TypeTree(typeof(object));

            ContractEnforcement.BuildTypeTree(locally, ContractEnforcement.GetAssemblyLocally(dllName).GetExportedTypes());

            TypeTree baseline = JsonConvert.DeserializeObject <TypeTree>(File.ReadAllText(baselinePath));

            string localJson = JsonConvert.SerializeObject(locally, Formatting.Indented);

            File.WriteAllText($"{breakingChangesPath}", localJson);
            string baselineJson = JsonConvert.SerializeObject(baseline, Formatting.Indented);

            return(baselineJson == localJson);
        }
コード例 #3
0
        private static TypeTree BuildTypeTree(TypeTree root, Type[] types)
        {
            IEnumerable <Type> subclassTypes = types.Where((type) => type.IsSubclassOf(root.Type)).OrderBy(o => o.FullName);

            foreach (Type subclassType in subclassTypes)
            {
                root.Subclasses[subclassType.Name] = (ContractEnforcement.BuildTypeTree(new TypeTree(subclassType), types));
            }

            IEnumerable <KeyValuePair <string, MemberInfo> > memberInfos =
                root.Type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)
                .Select(memberInfo => new KeyValuePair <string, MemberInfo>($"{memberInfo.ToString()}{string.Join("-", ContractEnforcement.RemoveDebugSpecificAttributes(memberInfo.CustomAttributes))}", memberInfo))
                .OrderBy(o => o.Key);

            foreach (KeyValuePair <string, MemberInfo> memberInfo in memberInfos)
            {
                List <string> attributes = ContractEnforcement.RemoveDebugSpecificAttributes(memberInfo.Value.CustomAttributes)
                                           .Select((customAttribute) => customAttribute.AttributeType.Name)
                                           .ToList();
                attributes.Sort();

                string methodSignature = null;

                if (memberInfo.Value.MemberType == MemberTypes.Constructor | memberInfo.Value.MemberType == MemberTypes.Method | memberInfo.Value.MemberType == MemberTypes.Event)
                {
                    methodSignature = memberInfo.Value.ToString();
                }

                root.Members[
                    memberInfo.Key
                ] = new MemberMetadata(
                    memberInfo.Value.MemberType,
                    attributes,
                    methodSignature);
            }

            foreach (Type nestedType in root.Type.GetNestedTypes().OrderBy(o => o.FullName))
            {
                root.NestedTypes[nestedType.Name] = (ContractEnforcement.BuildTypeTree(new TypeTree(nestedType), types));
            }

            return(root);
        }