Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

applied new re-ordering rules to everything but nspec.cs and NspecAss…

…ertions.cs
  • Loading branch information...
commit 157f5698e9d4cb1ce933cffe911c9cadefcf1822 1 parent 85b95b4
@mattflo authored
View
156 NSpec.sln.DotSettings
@@ -26,7 +26,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/CodeIssueFilter/IssueTypesToHide/=_003CStaticSeverity_0020Severity_003D_00222_0022_0020Title_003D_0022Structural_0020Search_0020Hints_0022_0020GroupId_003D_0022StructuralSearch_0022_0020_002F_003E/@EntryIndexedValue">DoHide</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=FieldCanBeMadeReadOnly_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=FieldCanBeMadeReadOnly_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
- <s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=matt/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="matt"&gt;&lt;CSRemoveCodeRedundancies&gt;True&lt;/CSRemoveCodeRedundancies&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;DISABLED&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;IMPLICIT_WHEN_INITIALIZER_HAS_TYPE&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_IMPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;/Profile&gt;</s:String>
+ <s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=matt/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="matt"&gt;&lt;CSRemoveCodeRedundancies&gt;True&lt;/CSRemoveCodeRedundancies&gt;&lt;CSUseVar&gt;&lt;BehavourStyle&gt;DISABLED&lt;/BehavourStyle&gt;&lt;LocalVariableStyle&gt;IMPLICIT_WHEN_INITIALIZER_HAS_TYPE&lt;/LocalVariableStyle&gt;&lt;ForeachVariableStyle&gt;ALWAYS_IMPLICIT&lt;/ForeachVariableStyle&gt;&lt;/CSUseVar&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;/Profile&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">matt</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">NEXT_LINE</s:String>
@@ -39,6 +39,160 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/JavaScriptFormatOther/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
+ <s:String x:Key="/Default/CodeStyle/CSharpMemberOrderPattern/CustomPattern/@EntryValue">&lt;?xml version="1.0" encoding="utf-8" ?&gt;&#xD;
+&#xD;
+&lt;!--&#xD;
+I. Overall&#xD;
+&#xD;
+I.1 Each pattern can have &lt;Match&gt;....&lt;/Match&gt; element. For the given type declaration, the pattern with the match, evaluated to 'true' with the largest weight, will be used &#xD;
+I.2 Each pattern consists of the sequence of &lt;Entry&gt;...&lt;/Entry&gt; elements. Type member declarations are distributed between entries&#xD;
+I.3 If pattern has RemoveAllRegions="true" attribute, then all regions will be cleared prior to reordering. Otherwise, only auto-generated regions will be cleared&#xD;
+I.4 The contents of each entry is sorted by given keys (First key is primary, next key is secondary, etc). Then the declarations are grouped and en-regioned by given property&#xD;
+&#xD;
+II. Available match operands&#xD;
+&#xD;
+Each operand may have Weight="..." attribute. This weight will be added to the match weight if the operand is evaluated to 'true'.&#xD;
+The default weight is 1&#xD;
+&#xD;
+II.1 Boolean functions:&#xD;
+II.1.1 &lt;And&gt;....&lt;/And&gt;&#xD;
+II.1.2 &lt;Or&gt;....&lt;/Or&gt;&#xD;
+II.1.3 &lt;Not&gt;....&lt;/Not&gt;&#xD;
+&#xD;
+II.2 Operands&#xD;
+II.2.1 &lt;Kind Is="..."/&gt;. Kinds are: class, struct, interface, enum, delegate, type, constructor, destructor, property, indexer, method, operator, field, constant, event, member&#xD;
+II.2.2 &lt;Name Is="..." [IgnoreCase="true/false"] /&gt;. The 'Is' attribute contains regular expression&#xD;
+II.2.3 &lt;HasAttribute CLRName="..." [Inherit="true/false"] /&gt;. The 'CLRName' attribute contains regular expression&#xD;
+II.2.4 &lt;Access Is="..."/&gt;. The 'Is' values are: public, protected, internal, protected internal, private&#xD;
+II.2.5 &lt;Static/&gt;&#xD;
+II.2.6 &lt;Abstract/&gt;&#xD;
+II.2.7 &lt;Virtual/&gt;&#xD;
+II.2.8 &lt;Override/&gt;&#xD;
+II.2.9 &lt;Sealed/&gt;&#xD;
+II.2.10 &lt;Readonly/&gt;&#xD;
+II.2.11 &lt;ImplementsInterface CLRName="..."/&gt;. The 'CLRName' attribute contains regular expression&#xD;
+II.2.12 &lt;HandlesEvent /&gt;&#xD;
+--&gt;&#xD;
+&#xD;
+&lt;Patterns xmlns="urn:shemas-jetbrains-com:member-reordering-patterns"&gt;&#xD;
+&#xD;
+ &lt;!--Do not reorder COM interfaces and structs marked by StructLayout attribute--&gt;&#xD;
+ &lt;Pattern&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;Or Weight="100"&gt;&#xD;
+ &lt;And&gt;&#xD;
+ &lt;Kind Is="interface"/&gt;&#xD;
+ &lt;Or&gt;&#xD;
+ &lt;HasAttribute CLRName="System.Runtime.InteropServices.InterfaceTypeAttribute"/&gt;&#xD;
+ &lt;HasAttribute CLRName="System.Runtime.InteropServices.ComImport"/&gt;&#xD;
+ &lt;/Or&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;HasAttribute CLRName="System.Runtime.InteropServices.StructLayoutAttribute"/&gt;&#xD;
+ &lt;/Or&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;/Pattern&gt;&#xD;
+&#xD;
+ &lt;!--Special formatting of NUnit test fixture--&gt;&#xD;
+ &lt;Pattern RemoveAllRegions="true"&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And Weight="100"&gt;&#xD;
+ &lt;Kind Is="class"/&gt;&#xD;
+ &lt;HasAttribute CLRName="NUnit.Framework.TestFixtureAttribute" Inherit="true"/&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+&#xD;
+ &lt;!--Setup/Teardow--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And&gt;&#xD;
+ &lt;Kind Is="method"/&gt;&#xD;
+ &lt;Or&gt;&#xD;
+ &lt;HasAttribute CLRName="NUnit.Framework.SetUpAttribute" Inherit="true"/&gt;&#xD;
+ &lt;HasAttribute CLRName="NUnit.Framework.TearDownAttribute" Inherit="true"/&gt;&#xD;
+ &lt;HasAttribute CLRName="NUnit.Framework.FixtureSetUpAttribute" Inherit="true"/&gt;&#xD;
+ &lt;HasAttribute CLRName="NUnit.Framework.FixtureTearDownAttribute" Inherit="true"/&gt;&#xD;
+ &lt;/Or&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;Group Region="Setup/Teardown"/&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+ &#xD;
+ &lt;!--All other members--&gt;&#xD;
+ &lt;Entry/&gt;&#xD;
+ &#xD;
+ &lt;!--Test methods--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And Weight="100"&gt;&#xD;
+ &lt;Kind Is="method"/&gt;&#xD;
+ &lt;HasAttribute CLRName="NUnit.Framework.TestAttribute" Inherit="false"/&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;Sort&gt;&#xD;
+ &lt;Name/&gt;&#xD;
+ &lt;/Sort&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+ &lt;/Pattern&gt;&#xD;
+&#xD;
+ &lt;!--Default pattern--&gt;&#xD;
+ &lt;Pattern&gt;&#xD;
+&#xD;
+ &lt;!--public methods--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And Weight="100"&gt;&#xD;
+ &lt;Access Is="public"/&gt;&#xD;
+ &lt;Kind Is="method"/&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+&#xD;
+ &lt;!--private methods--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And Weight="100"&gt;&#xD;
+ &lt;Access Is="private"/&gt;&#xD;
+ &lt;Kind Is="method"/&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+ &#xD;
+ &lt;!--Constructors. Place static one first--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;Kind Is="constructor"/&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+&#xD;
+ &lt;!--public fields &amp; props--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And Weight="100"&gt;&#xD;
+ &lt;Access Is="public"/&gt;&#xD;
+ &lt;Kind Is="field"/&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+&#xD;
+ &lt;!--private fields &amp; props--&gt;&#xD;
+ &lt;Entry&gt;&#xD;
+ &lt;Match&gt;&#xD;
+ &lt;And Weight="100"&gt;&#xD;
+ &lt;Access Is="private"/&gt;&#xD;
+ &lt;Kind Is="field"/&gt;&#xD;
+ &lt;/And&gt;&#xD;
+ &lt;/Match&gt;&#xD;
+ &lt;/Entry&gt;&#xD;
+&#xD;
+&#xD;
+ &lt;!--all other members--&gt;&#xD;
+ &lt;Entry/&gt;&#xD;
+ &#xD;
+ &lt;/Pattern&gt;&#xD;
+ &#xD;
+&lt;/Patterns&gt;&#xD;
+&#xD;
+</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Constructor/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Generate/=Constructor/Options/=XmlDocumentation/@EntryIndexedValue">False</s:String>
<s:Boolean x:Key="/Default/CodeStyle/LiveTemplatesUseVar/UseVar/@EntryValue">False</s:Boolean>
View
10 NSpec/Conventions.cs
@@ -95,11 +95,6 @@ public MethodInfo GetMethodLevelAfter(Type type)
return GetMethodMatchingRegex(type, specification.After);
}
- MethodInfo GetMethodMatchingRegex(Type type, Regex regex)
- {
- return type.Methods().Where(mi => mi.DeclaringType == type).FirstOrDefault(mi => regex.IsMatch(mi.Name));
- }
-
public bool IsMethodLevelExample(string name)
{
return specification.Example.IsMatch(name);
@@ -133,6 +128,11 @@ public bool IsMethodLevelContext(string name)
return specification.Context.IsMatch(name);
}
+ MethodInfo GetMethodMatchingRegex(Type type, Regex regex)
+ {
+ return type.Methods().Where(mi => mi.DeclaringType == type).FirstOrDefault(mi => regex.IsMatch(mi.Name));
+ }
+
ConventionSpecification specification;
}
}
View
4 NSpec/Domain/ActionIndexer.cs
@@ -4,13 +4,13 @@ namespace NSpec.Domain
{
public class ActionRegister
{
- Action<string, string, Action> actionSetter;
-
public ActionRegister(Action<string, string, Action> actionSetter)
{
this.actionSetter = actionSetter;
}
+ Action<string, string, Action> actionSetter;
+
public Action this[string key]
{
set { actionSetter(key, null, value); }
View
54 NSpec/Domain/ClassContext.cs
@@ -8,7 +8,30 @@ namespace NSpec.Domain
{
public class ClassContext : Context
{
- List<Type> classHierarchyToClass = new List<Type>();
+ public override void Build(nspec instance = null)
+ {
+ BuildMethodLevelBefore();
+
+ BuildMethodLevelAct();
+
+ BuildMethodLevelAfter();
+
+ var nspec = type.Instance<nspec>();
+
+ nspec.tagsFilter = tagsFilter ?? new Tags();
+
+ base.Build(nspec);
+ }
+
+ public override bool IsSub(Type baseType)
+ {
+ while (baseType != null && baseType.IsAbstract)
+ {
+ baseType = baseType.BaseType;
+ }
+
+ return baseType == type;
+ }
IEnumerable<MethodInfo> GetMethodsFromHierarchy(Func<Type, MethodInfo> methodAccessor)
{
@@ -57,35 +80,10 @@ public ClassContext(Type type, Conventions conventions = null, Tags tagsFilter =
}
}
- public override void Build(nspec instance = null)
- {
- BuildMethodLevelBefore();
-
- BuildMethodLevelAct();
-
- BuildMethodLevelAfter();
-
- var nspec = type.Instance<nspec>();
-
- nspec.tagsFilter = tagsFilter ?? new Tags();
-
- base.Build(nspec);
- }
-
- public override bool IsSub(Type baseType)
- {
- while (baseType != null && baseType.IsAbstract)
- {
- baseType = baseType.BaseType;
- }
-
- return baseType == type;
- }
-
- Conventions conventions;
-
public Type type;
public Tags tagsFilter;
+ List<Type> classHierarchyToClass = new List<Type>();
+ Conventions conventions;
}
}
View
92 NSpec/Domain/Context.cs
@@ -37,18 +37,6 @@ public void RunAfters(nspec instance)
RecurseAncestors(c => c.RunAfters(instance));
}
- void RecurseAncestors(Action<Context> ancestorAction)
- {
- if (Parent != null) ancestorAction(Parent);
- }
-
- void RunBeforeAll()
- {
- BeforeAll.SafeInvoke();
-
- BeforeAll = null;
- }
-
public void AddExample(Example example)
{
example.Context = this;
@@ -112,17 +100,6 @@ public virtual void Run(ILiveFormatter formatter, bool failFast, nspec instance
Contexts.Do(c => c.Run(formatter, failFast, nspec));
}
- void WriteAncestors(ILiveFormatter formatter)
- {
- if (Parent == null) return;
-
- Parent.WriteAncestors(formatter);
-
- if (!alreadyWritten) formatter.Write(this);
-
- alreadyWritten = true;
- }
-
public virtual void Build(nspec instance = null)
{
instance.Context = this;
@@ -177,29 +154,6 @@ public virtual bool IsSub(Type baseType)
return false;
}
- public Context(string name = "", string tags = null, bool isPending = false)
- {
- Name = name.Replace("_", " ");
- Examples = new List<Example>();
- Contexts = new ContextCollection();
- Tags = Domain.Tags.ParseTags(tags);
- this.isPending = isPending;
- }
-
- public string Name;
- public int Level;
- public List<string> Tags;
- public List<Example> Examples;
- public ContextCollection Contexts;
- public Action Before, Act, After, BeforeAll;
- public Action<nspec> BeforeInstance, ActInstance, AfterInstance;
- public Context Parent;
- public Exception Exception;
- public Exception contextLevelExpectedException;
- bool isPending;
- nspec savedInstance;
- bool alreadyWritten;
-
public nspec GetInstance()
{
return savedInstance ?? Parent.GetInstance();
@@ -233,5 +187,51 @@ public void TrimSkippedDescendants()
Contexts.Do(c => c.TrimSkippedDescendants());
}
+
+ void RecurseAncestors(Action<Context> ancestorAction)
+ {
+ if (Parent != null) ancestorAction(Parent);
+ }
+
+ void RunBeforeAll()
+ {
+ BeforeAll.SafeInvoke();
+
+ BeforeAll = null;
+ }
+
+ void WriteAncestors(ILiveFormatter formatter)
+ {
+ if (Parent == null) return;
+
+ Parent.WriteAncestors(formatter);
+
+ if (!alreadyWritten) formatter.Write(this);
+
+ alreadyWritten = true;
+ }
+
+ public Context(string name = "", string tags = null, bool isPending = false)
+ {
+ Name = name.Replace("_", " ");
+ Examples = new List<Example>();
+ Contexts = new ContextCollection();
+ Tags = Domain.Tags.ParseTags(tags);
+ this.isPending = isPending;
+ }
+
+ public string Name;
+ public int Level;
+ public List<string> Tags;
+ public List<Example> Examples;
+ public ContextCollection Contexts;
+ public Action Before, Act, After, BeforeAll;
+ public Action<nspec> BeforeInstance, ActInstance, AfterInstance;
+ public Context Parent;
+ public Exception Exception;
+ public Exception contextLevelExpectedException;
+
+ nspec savedInstance;
+ bool alreadyWritten, isPending;
}
}
View
74 NSpec/Domain/ContextBuilder.cs
@@ -9,23 +9,6 @@ namespace NSpec.Domain
[Serializable]
public class ContextBuilder
{
- public ContextBuilder(ISpecFinder finder, Tags tagsFilter)
- : this(finder, new DefaultConventions()) {}
-
- public ContextBuilder(ISpecFinder finder, Conventions conventions)
- : this(finder, new Tags(), conventions) {}
-
- public ContextBuilder(ISpecFinder finder, Tags tagsFilter, Conventions conventions)
- {
- contexts = new ContextCollection();
-
- this.finder = finder;
-
- this.conventions = conventions;
-
- this.tagsFilter = tagsFilter;
- }
-
public ContextCollection Contexts()
{
contexts.Clear();
@@ -43,24 +26,6 @@ public ContextCollection Contexts()
return contexts;
}
- void Build(Context parent, IEnumerable<Type> allSpecClasses)
- {
- var derivedTypes = allSpecClasses.Where(s => parent.IsSub(s.BaseType));
-
- foreach (var derived in derivedTypes)
- {
- var classContext = CreateClassContext(derived);
-
- parent.AddContext(classContext);
-
- BuildMethodContexts(classContext, derived);
-
- BuildMethodLevelExamples(classContext, derived);
-
- Build(classContext, allSpecClasses);
- }
- }
-
public ClassContext CreateClassContext(Type type)
{
var tagAttributes = ((TagAttribute[])type.GetCustomAttributes(typeof(TagAttribute), false)).ToList();
@@ -101,6 +66,24 @@ public void BuildMethodLevelExamples(Context classContext, Type specClass)
});
}
+ void Build(Context parent, IEnumerable<Type> allSpecClasses)
+ {
+ var derivedTypes = allSpecClasses.Where(s => parent.IsSub(s.BaseType));
+
+ foreach (var derived in derivedTypes)
+ {
+ var classContext = CreateClassContext(derived);
+
+ parent.AddContext(classContext);
+
+ BuildMethodContexts(classContext, derived);
+
+ BuildMethodLevelExamples(classContext, derived);
+
+ Build(classContext, allSpecClasses);
+ }
+ }
+
string TagStringFor(MethodInfo method)
{
return TagStringFor(TagAttributesFor(method));
@@ -116,12 +99,29 @@ IEnumerable<TagAttribute> TagAttributesFor(MethodInfo method)
return (TagAttribute[])method.GetCustomAttributes(typeof(TagAttribute), false);
}
+ public ContextBuilder(ISpecFinder finder, Tags tagsFilter)
+ : this(finder, new DefaultConventions()) {}
+
+ public ContextBuilder(ISpecFinder finder, Conventions conventions)
+ : this(finder, new Tags(), conventions) {}
+
+ public ContextBuilder(ISpecFinder finder, Tags tagsFilter, Conventions conventions)
+ {
+ contexts = new ContextCollection();
+
+ this.finder = finder;
+
+ this.conventions = conventions;
+
+ this.tagsFilter = tagsFilter;
+ }
+
+ public Tags tagsFilter;
+
Conventions conventions;
ISpecFinder finder;
ContextCollection contexts;
-
- public Tags tagsFilter;
}
}
View
8 NSpec/Domain/ContextCollection.cs
@@ -6,10 +6,6 @@ namespace NSpec.Domain
{
public class ContextCollection : List<Context>
{
- public ContextCollection(IEnumerable<Context> contexts) : base(contexts) {}
-
- public ContextCollection() {}
-
public IEnumerable<Example> Examples()
{
return this.SelectMany(c => c.AllExamples());
@@ -63,5 +59,9 @@ public Example FindExample(string name)
{
return Examples().FirstOrDefault(e => e.Spec == name);
}
+
+ public ContextCollection(IEnumerable<Context> contexts) : base(contexts) {}
+
+ public ContextCollection() {}
}
}
View
14 NSpec/Domain/ContextRunner.cs
@@ -6,13 +6,6 @@ namespace NSpec.Domain
[Serializable]
public class ContextRunner
{
- public ContextRunner(ContextBuilder builder, IFormatter formatter, bool failFast)
- {
- this.failFast = failFast;
- this.builder = builder;
- this.formatter = formatter;
- }
-
public ContextCollection Run(ContextCollection contexts)
{
try
@@ -35,6 +28,13 @@ public ContextCollection Run(ContextCollection contexts)
return contexts;
}
+ public ContextRunner(ContextBuilder builder, IFormatter formatter, bool failFast)
+ {
+ this.failFast = failFast;
+ this.builder = builder;
+ this.formatter = formatter;
+ }
+
ContextBuilder builder;
bool failFast;
IFormatter formatter;
View
26 NSpec/Domain/Example.cs
@@ -37,9 +37,18 @@ public string FullName()
return Context.FullContext() + ". " + Spec + ".";
}
- public bool Passed
+ public bool Failed()
{
- get { return (HasRun && Exception == null); }
+ return Exception != null;
+ }
+
+ public void AssignProperException(Exception contextException)
+ {
+ if (Exception != null && contextException != null && Exception.GetType() != typeof(ExceptionNotThrown))
+ Exception = new ExampleFailureException("Context Failure: " + contextException.Message + ", Example Failure: " + Exception.Message, contextException);
+
+ if (Exception == null && contextException != null)
+ Exception = new ExampleFailureException("Context Failure: " + contextException.Message, contextException);
}
public Example(Expression<Action> expr) : this(Parse(expr), null, expr.Compile()) {}
@@ -66,11 +75,6 @@ public Example(MethodInfo methodLevelExample, string tags = null)
public bool Pending;
- public bool Failed()
- {
- return Exception != null;
- }
-
public bool HasRun;
public string Spec;
public List<string> Tags;
@@ -80,13 +84,9 @@ public bool Failed()
Action action;
- public void AssignProperException(Exception contextException)
+ public bool Passed
{
- if (Exception != null && contextException != null && Exception.GetType() != typeof(ExceptionNotThrown))
- Exception = new ExampleFailureException("Context Failure: " + contextException.Message + ", Example Failure: " + Exception.Message, contextException);
-
- if (Exception == null && contextException != null)
- Exception = new ExampleFailureException("Context Failure: " + contextException.Message, contextException);
+ get { return (HasRun && Exception == null); }
}
}
}
View
16 NSpec/Domain/Formatters/TiddlyWikiFormatter.cs
@@ -10,14 +10,6 @@ namespace NSpec.Domain.Formatters
[Serializable]
public class TiddlyWikiFormatter : IFormatter
{
- TiddlyWikiFormatter() {}
-
- public TiddlyWikiFormatter(string templateFile, string outputFile)
- {
- this.templateFile = templateFile;
- this.outputFile = outputFile;
- }
-
public void Write(ContextCollection contexts)
{
contexts.Do(c => this.tiddlers.Add(c.Name, this.BuildTiddlerFrom(c)));
@@ -117,6 +109,14 @@ string BuildSpec(Example e, int level)
return output + Environment.NewLine;
}
+ TiddlyWikiFormatter() {}
+
+ public TiddlyWikiFormatter(string templateFile, string outputFile)
+ {
+ this.templateFile = templateFile;
+ this.outputFile = outputFile;
+ }
+
SortedList<string, string> tiddlers = new SortedList<string, string>();
string templateFile;
string outputFile;
View
12 NSpec/Domain/MethodContext.cs
@@ -5,12 +5,6 @@ namespace NSpec.Domain
{
public class MethodContext : Context
{
- public MethodContext(MethodInfo method, string tags = null)
- : base(method.Name, tags)
- {
- this.method = method;
- }
-
public override void Build(nspec instance)
{
base.Build(instance);
@@ -27,6 +21,12 @@ public override void Build(nspec instance)
}
}
+ public MethodContext(MethodInfo method, string tags = null)
+ : base(method.Name, tags)
+ {
+ this.method = method;
+ }
+
MethodInfo method;
}
}
View
30 NSpec/Domain/RunnerInvocation.cs
@@ -6,11 +6,16 @@ namespace NSpec.Domain
[Serializable]
public class RunnerInvocation
{
- string dll;
- bool failFast;
- public string Tags;
- public IFormatter Formatter;
- public bool inDomain;
+ public ContextCollection Run()
+ {
+ var finder = new SpecFinder(this.dll, new Reflector());
+
+ var builder = new ContextBuilder(finder, new Tags().Parse(Tags), new DefaultConventions());
+
+ var runner = new ContextRunner(builder, Formatter, failFast);
+
+ return runner.Run(builder.Contexts().Build());
+ }
public RunnerInvocation(string dll, string tags)
: this(dll, tags, false) {}
@@ -26,15 +31,10 @@ public RunnerInvocation(string dll, string tags, IFormatter formatter, bool fail
Formatter = formatter;
}
- public ContextCollection Run()
- {
- var finder = new SpecFinder(this.dll, new Reflector());
-
- var builder = new ContextBuilder(finder, new Tags().Parse(Tags), new DefaultConventions());
-
- var runner = new ContextRunner(builder, Formatter, failFast);
-
- return runner.Run(builder.Contexts().Build());
- }
+ public string Tags;
+ public IFormatter Formatter;
+ public bool inDomain;
+ string dll;
+ bool failFast;
}
}
View
4 NSpec/Domain/SpecFinder.cs
@@ -10,8 +10,6 @@ namespace NSpec.Domain
[Serializable]
public class SpecFinder : ISpecFinder
{
- string filter;
-
public virtual IEnumerable<Type> SpecClasses()
{
var regex = new Regex(filter);
@@ -62,6 +60,8 @@ public SpecFinder(string specDLL, IReflector reflector, string filter = "")
public SpecFinder(Assembly assembly, IReflector reflector, string filter = "")
: this(reflector.GetTypesFrom(assembly), filter) {}
+ string filter;
+
public Type[] Types { get; set; }
}
View
6 NSpec/Domain/Tags.cs
@@ -5,9 +5,6 @@ namespace NSpec.Domain
{
public class Tags
{
- public List<string> IncludeTags = new List<string>();
- public List<string> ExcludeTags = new List<string>();
-
/// <summary>Parses a string containing tags into a collection of normalized tags</summary>
public static List<string> ParseTags(string tags)
{
@@ -83,5 +80,8 @@ public bool HasTagFilters()
{
return IncludeTags.Any() || ExcludeTags.Any();
}
+
+ public List<string> IncludeTags = new List<string>();
+ public List<string> ExcludeTags = new List<string>();
}
}
View
4 NSpec/TagAttribute.cs
@@ -5,11 +5,11 @@ namespace NSpec
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class TagAttribute : Attribute
{
- public string Tags { get; set; }
-
public TagAttribute(string tags)
{
Tags = tags;
}
+
+ public string Tags { get; set; }
}
}
View
2  README.md
@@ -9,3 +9,5 @@ The Nspec test suite is written in NUnit. The test project is NSpecSpecs. Not to
I prefer using ncrunch to run the NSpec test suite. But you can also use Specwatchr, since it has support for NUnit. To do so make sure that you have the current version of NUnit installed since the dotnet.watchr.rb file contains a hard reference to the 2.5.9 binary.
` NUnitRunner.nunit_path = 'C:\program files (x86)\nunit 2.5.9\bin\net-2.0\nunit-console-x86.exe' `
+
+If you have Resharper 6.1 there is a team-shared settings file in the repository. Please use the settings to format any new code you write.
Please sign in to comment.
Something went wrong with that request. Please try again.