Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1621 for trunk/sources


Ignore:
Timestamp:
04/22/09 13:24:28 (16 years ago)
Author:
epitzer
Message:

New test case to ensure some coding conventions. (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs

    r1614 r1621  
    99using HeuristicLab.Persistence.Default.DebugString;
    1010using System.IO;
     11using System.Reflection;
    1112
    1213namespace HeuristicLab.Persistence.UnitTest {
     
    269270    }
    270271
     272    private string formatFullMemberName(MemberInfo mi) {     
     273      return new StringBuilder()
     274        .Append(mi.DeclaringType.Assembly.GetName().Name)
     275        .Append(": ")
     276        .Append(mi.DeclaringType.Namespace)
     277        .Append('.')
     278        .Append(mi.DeclaringType.Name)
     279        .Append('.')
     280        .Append(mi.Name).ToString();
     281    }
     282
     283    [TestMethod]
     284    public void CodingConventions() {
     285      List<string> lowerCaseMethodNames = new List<string>();
     286      List<string> lowerCaseProperties = new List<string>();
     287      List<string> lowerCaseFields = new List<string>();
     288      foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
     289        if (!a.GetName().Name.StartsWith("HeuristicLab"))
     290          continue;       
     291        foreach (Type t in a.GetTypes()) {
     292          foreach (MemberInfo mi in t.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) {
     293            if (char.IsLower(mi.Name[0])) {
     294              if (mi.MemberType == MemberTypes.Field)
     295                lowerCaseFields.Add(formatFullMemberName(mi));
     296              if (mi.MemberType == MemberTypes.Property)
     297                lowerCaseProperties.Add(formatFullMemberName(mi));
     298              if (mi.MemberType == MemberTypes.Method &&
     299                !mi.Name.StartsWith("get_") &&
     300                !mi.Name.StartsWith("set_") &&
     301                !mi.Name.StartsWith("add_") &&
     302                !mi.Name.StartsWith("remove_") )
     303                lowerCaseMethodNames.Add(formatFullMemberName(mi));
     304            }
     305          }
     306        }
     307      }
     308      //Assert.AreEqual("", lowerCaseFields.Aggregate("", (a, b) => a + "\r\n" + b));
     309      Assert.AreEqual("", lowerCaseMethodNames.Aggregate("", (a, b) => a + "\r\n" + b));
     310      Assert.AreEqual("", lowerCaseProperties.Aggregate("", (a, b) => a + "\r\n" + b));
     311    }
     312
    271313
    272314    [ClassInitialize]
Note: See TracChangeset for help on using the changeset viewer.