19 changed files with 770 additions and 445 deletions
@ -1,70 +1,70 @@
@@ -1,70 +1,70 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: trecio |
||||
* Date: 2011-09-23 |
||||
* Time: 19:53 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using developwithpassion.specifications.extensions; |
||||
using developwithpassion.specifications.rhinomocks; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using Machine.Specifications; |
||||
using Machine.Fakes.Adapters.Rhinomocks; |
||||
|
||||
namespace ICSharpCode.MachineSpecifications.Tests |
||||
{ |
||||
[Subject(typeof(ClassFilterBuilder))] |
||||
public class When_building_class_filter_from_test_selection : Observes<ClassFilterBuilder> |
||||
{ |
||||
const string NAMESPACE_FILTER = "Namespace"; |
||||
static DefaultClass classAddedExplicitly, classInNamespace, classOutsideNamespace, classNestedInAddedExplicitly, classNestedInClassInNamespace; |
||||
static SelectedTests selectedTests; |
||||
static IProjectContent projectContent; |
||||
static IList<string> result; |
||||
|
||||
Establish ctx = () => { |
||||
projectContent = fake.an<IProjectContent>(); |
||||
projectContent.setup(x => x.SystemTypes).Return(new SystemTypes(projectContent)); |
||||
var compilationUnit = new DefaultCompilationUnit(projectContent); |
||||
|
||||
classAddedExplicitly = new DefaultClass(compilationUnit, "ClassAddedExplicitly"); |
||||
classNestedInAddedExplicitly = new DefaultClass(compilationUnit, classAddedExplicitly); |
||||
classNestedInAddedExplicitly.FullyQualifiedName = "ClassAddedExplicitly.InnerClass"; |
||||
classAddedExplicitly.InnerClasses.Add(classNestedInAddedExplicitly); |
||||
|
||||
classInNamespace = new DefaultClass(compilationUnit, "Namespace.OtherNamespace.ClassInNamespace"); |
||||
classNestedInClassInNamespace = new DefaultClass(compilationUnit, classInNamespace); |
||||
classNestedInClassInNamespace.FullyQualifiedName = "Namespace.OtherNamespace.ClassInNamespace.InnerClass"; |
||||
classInNamespace.InnerClasses.Add(classNestedInClassInNamespace); |
||||
classOutsideNamespace = new DefaultClass(compilationUnit, "Namespace2.ClassOutsideNamespac"); |
||||
|
||||
var project = fake.an<IProject>(); |
||||
projectContent.setup(x => x.Classes).Return(new[]{classInNamespace, classOutsideNamespace}); |
||||
|
||||
selectedTests = new SelectedTests(project, NAMESPACE_FILTER, classAddedExplicitly, null); |
||||
}; |
||||
|
||||
Because of = () => |
||||
result = sut.BuildFilterFor(selectedTests, projectContent); |
||||
|
||||
It should_add_dotnet_name_of_selected_test_class = () => |
||||
result.ShouldContain(classAddedExplicitly.DotNetName); |
||||
|
||||
It should_add_class_included_in_selected_namespace = () => |
||||
result.ShouldContain(classInNamespace.DotNetName); |
||||
|
||||
It should_not_include_class_not_included_in_namespace = () => |
||||
result.ShouldNotContain(classOutsideNamespace.DotNetName); |
||||
|
||||
It should_not_include_class_nested_in_selected_test_class = () => |
||||
result.ShouldNotContain(classNestedInAddedExplicitly.DotNetName); |
||||
|
||||
It should_include_class_nested_in_class_from_selected_namespace = () => |
||||
result.ShouldContain(classNestedInClassInNamespace.DotNetName); |
||||
} |
||||
} |
||||
///*
|
||||
// * Created by SharpDevelop.
|
||||
// * User: trecio
|
||||
// * Date: 2011-09-23
|
||||
// * Time: 19:53
|
||||
// *
|
||||
// * To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
// */
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using developwithpassion.specifications.extensions;
|
||||
//using developwithpassion.specifications.rhinomocks;
|
||||
//using ICSharpCode.SharpDevelop.Dom;
|
||||
//using ICSharpCode.SharpDevelop.Project;
|
||||
//using ICSharpCode.UnitTesting;
|
||||
//using Machine.Specifications;
|
||||
//using Machine.Fakes.Adapters.Rhinomocks;
|
||||
//
|
||||
//namespace ICSharpCode.MachineSpecifications.Tests
|
||||
//{
|
||||
// [Subject(typeof(ClassFilterBuilder))]
|
||||
// public class When_building_class_filter_from_test_selection : Observes<ClassFilterBuilder>
|
||||
// {
|
||||
// const string NAMESPACE_FILTER = "Namespace";
|
||||
// static DefaultClass classAddedExplicitly, classInNamespace, classOutsideNamespace, classNestedInAddedExplicitly, classNestedInClassInNamespace;
|
||||
// static SelectedTests selectedTests;
|
||||
// static IProjectContent projectContent;
|
||||
// static IList<string> result;
|
||||
//
|
||||
// Establish ctx = () => {
|
||||
// projectContent = fake.an<IProjectContent>();
|
||||
// projectContent.setup(x => x.SystemTypes).Return(new SystemTypes(projectContent));
|
||||
// var compilationUnit = new DefaultCompilationUnit(projectContent);
|
||||
//
|
||||
// classAddedExplicitly = new DefaultClass(compilationUnit, "ClassAddedExplicitly");
|
||||
// classNestedInAddedExplicitly = new DefaultClass(compilationUnit, classAddedExplicitly);
|
||||
// classNestedInAddedExplicitly.FullyQualifiedName = "ClassAddedExplicitly.InnerClass";
|
||||
// classAddedExplicitly.InnerClasses.Add(classNestedInAddedExplicitly);
|
||||
//
|
||||
// classInNamespace = new DefaultClass(compilationUnit, "Namespace.OtherNamespace.ClassInNamespace");
|
||||
// classNestedInClassInNamespace = new DefaultClass(compilationUnit, classInNamespace);
|
||||
// classNestedInClassInNamespace.FullyQualifiedName = "Namespace.OtherNamespace.ClassInNamespace.InnerClass";
|
||||
// classInNamespace.InnerClasses.Add(classNestedInClassInNamespace);
|
||||
// classOutsideNamespace = new DefaultClass(compilationUnit, "Namespace2.ClassOutsideNamespac");
|
||||
//
|
||||
// var project = fake.an<IProject>();
|
||||
// projectContent.setup(x => x.Classes).Return(new[]{classInNamespace, classOutsideNamespace});
|
||||
//
|
||||
// selectedTests = new SelectedTests(project, NAMESPACE_FILTER, classAddedExplicitly, null);
|
||||
// };
|
||||
//
|
||||
// Because of = () =>
|
||||
// result = sut.BuildFilterFor(selectedTests, projectContent);
|
||||
//
|
||||
// It should_add_dotnet_name_of_selected_test_class = () =>
|
||||
// result.ShouldContain(classAddedExplicitly.DotNetName);
|
||||
//
|
||||
// It should_add_class_included_in_selected_namespace = () =>
|
||||
// result.ShouldContain(classInNamespace.DotNetName);
|
||||
//
|
||||
// It should_not_include_class_not_included_in_namespace = () =>
|
||||
// result.ShouldNotContain(classOutsideNamespace.DotNetName);
|
||||
//
|
||||
// It should_not_include_class_nested_in_selected_test_class = () =>
|
||||
// result.ShouldNotContain(classNestedInAddedExplicitly.DotNetName);
|
||||
//
|
||||
// It should_include_class_nested_in_class_from_selected_namespace = () =>
|
||||
// result.ShouldContain(classNestedInClassInNamespace.DotNetName);
|
||||
// }
|
||||
//}
|
||||
|
||||
@ -1,193 +1,193 @@
@@ -1,193 +1,193 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: trecio |
||||
* Date: 2011-06-18 |
||||
* Time: 15:12 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.Linq; |
||||
using developwithpassion.specifications.extensions; |
||||
using developwithpassion.specifications.dsl; |
||||
using developwithpassion.specifications.rhinomocks; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using Machine.Specifications; |
||||
using ICSharpCode.UnitTesting; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using Rhino.Mocks; |
||||
|
||||
namespace ICSharpCode.MachineSpecifications.Tests |
||||
{ |
||||
[Subject(typeof(MSpecTestFramework))] |
||||
public class When_checking_if_is_a_test_project : Observes<MSpecTestFramework> |
||||
{ |
||||
static IProject testProject; |
||||
static IProject nonTestProject; |
||||
|
||||
static bool resultForTestProject; |
||||
static bool resultForNonTestProject; |
||||
|
||||
const string MSpecAssemblyName = "Machine.Specifications"; |
||||
|
||||
Establish ctx = () => |
||||
{ |
||||
testProject = fake.an<IProject>(); |
||||
var mspecReference = MockRepository.GenerateStub<ReferenceProjectItem>(testProject); |
||||
mspecReference.setup(x => x.ShortName).Return(MSpecAssemblyName); |
||||
testProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { mspecReference })); |
||||
|
||||
nonTestProject = fake.an<IProject>(); |
||||
var otherReference = MockRepository.GenerateStub<ReferenceProjectItem>(nonTestProject); |
||||
mspecReference.setup(x => x.ShortName).Return("System.Configuration"); |
||||
nonTestProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { otherReference })); |
||||
}; |
||||
|
||||
Because of = () => |
||||
{ |
||||
resultForTestProject = sut.IsTestProject(testProject); |
||||
resultForNonTestProject = sut.IsTestProject(nonTestProject); |
||||
}; |
||||
|
||||
It should_return_true_for_project_which_has_reference_to_test_framework = () => |
||||
resultForTestProject.ShouldBeTrue(); |
||||
|
||||
It should_return_false_for_project_which_has_no_reference_to_test_framework = () => |
||||
resultForNonTestProject.ShouldBeFalse(); |
||||
} |
||||
|
||||
public abstract class MSpecTestFrameworkFieldsConcern : Observes<MSpecTestFramework> |
||||
{ |
||||
protected static ICompilationUnit CompilationUnit; |
||||
|
||||
Establish ctx = () => |
||||
{ |
||||
var ProjectContent = fake.an<IProjectContent>(); |
||||
ProjectContent.setup(x => x.SystemTypes).Return(new SystemTypes(ProjectContent)); |
||||
CompilationUnit = new DefaultCompilationUnit(ProjectContent); |
||||
}; |
||||
|
||||
protected const string MSpecItTypeName = "Machine.Specifications.It"; |
||||
protected const string MSpecBehavesTypeName = "Machine.Specifications.Behaves_like"; |
||||
protected const string MSpecBehaviorTypeName = "Machine.Specifications.BehaviorsAttribute"; |
||||
|
||||
protected static IClass SetupClass(bool isAbstract, IList<IField> fields, IList<IAttribute> attributes) |
||||
{ |
||||
var c = fake.an<IClass>(); |
||||
c.setup(x => x.IsAbstract).Return(isAbstract); |
||||
c.setup(x => x.Fields).Return(fields); |
||||
c.setup(x => x.Attributes).Return(attributes); |
||||
return c; |
||||
} |
||||
|
||||
protected static IField SetupField(string returnTypeName) |
||||
{ |
||||
var field = fake.an<IField>(); |
||||
field.ReturnType = SetupReturnType(returnTypeName); |
||||
return field; |
||||
} |
||||
|
||||
protected static IAttribute SetupBehaviorAttribute() |
||||
{ |
||||
var attribute = fake.an<IAttribute>(); |
||||
attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName)); |
||||
return attribute; |
||||
} |
||||
|
||||
protected static IReturnType SetupReturnType(string typeName) |
||||
{ |
||||
var returnType = fake.an<IReturnType>(); |
||||
returnType.Stub(x => x.FullyQualifiedName).Return(typeName); |
||||
return returnType; |
||||
} |
||||
} |
||||
|
||||
[Subject(typeof(MSpecTestFramework))] |
||||
public class When_checking_if_is_a_test_class : MSpecTestFrameworkFieldsConcern |
||||
{ |
||||
static IClass classWithoutSpecificationMembers; |
||||
static IClass classWithSpecificationMembers; |
||||
static IClass classWithBehavior; |
||||
static IClass classWithSpecificationMembersAndBehaviorAttribute; |
||||
|
||||
static bool resultForClassWithBehaviorAttribute; |
||||
static bool resultForClassWithSpecifications; |
||||
static bool resultForClassWithBehavior; |
||||
static bool resultForClassWithoutSpecifications; |
||||
|
||||
Establish ctx = () => |
||||
{ |
||||
classWithoutSpecificationMembers = SetupClass(false, new IField[0], new IAttribute[0]); |
||||
classWithSpecificationMembers = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[0]); |
||||
classWithBehavior = SetupClass(false, new IField[] { SetupField(MSpecBehavesTypeName) }, new IAttribute[0]); |
||||
classWithSpecificationMembersAndBehaviorAttribute = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[] { SetupBehaviorAttribute() }); |
||||
}; |
||||
|
||||
Because of = () => |
||||
{ |
||||
resultForClassWithoutSpecifications = sut.IsTestClass(classWithoutSpecificationMembers); |
||||
resultForClassWithSpecifications = sut.IsTestClass(classWithSpecificationMembers); |
||||
resultForClassWithBehavior = sut.IsTestClass(classWithBehavior); |
||||
resultForClassWithBehaviorAttribute = sut.IsTestClass(classWithSpecificationMembersAndBehaviorAttribute); |
||||
}; |
||||
|
||||
It should_return_false_for_class_without_specification_members = () => |
||||
resultForClassWithoutSpecifications.ShouldBeFalse(); |
||||
|
||||
It should_return_true_for_class_with_specification_members = () => |
||||
resultForClassWithSpecifications.ShouldBeTrue(); |
||||
|
||||
It should_return_true_for_class_with_behavior = () => |
||||
resultForClassWithBehavior.ShouldBeTrue(); |
||||
|
||||
It should_return_false_for_class_with_behavior_attribute = () => |
||||
resultForClassWithBehaviorAttribute.ShouldBeFalse(); |
||||
} |
||||
|
||||
public class When_enumerating_test_members : MSpecTestFrameworkFieldsConcern |
||||
{ |
||||
static IClass behaviorClass; |
||||
static IField testSpecificationInBehavior; |
||||
|
||||
static IClass testClass; |
||||
static IField testSpecification; |
||||
static IField otherField; |
||||
static IField behavesLikeField; |
||||
|
||||
static IEnumerable<TestMember> result; |
||||
|
||||
const string BehaviorClassName = "Test.Behavior"; |
||||
|
||||
Establish ctx = () => |
||||
{ |
||||
var itReturnType = SetupReturnType(MSpecItTypeName); |
||||
|
||||
behaviorClass = new DefaultClass(CompilationUnit, "BehaviorClass"); |
||||
testSpecificationInBehavior = new DefaultField(itReturnType, "testSpecificationInBehavior", ModifierEnum.None, DomRegion.Empty, behaviorClass); |
||||
behaviorClass.Fields.Add(testSpecificationInBehavior); |
||||
|
||||
testClass = new DefaultClass(CompilationUnit, "TestClass"); |
||||
testSpecification = new DefaultField(itReturnType, "testSpecification", ModifierEnum.None, DomRegion.Empty, testClass); |
||||
testClass.Fields.Add(testSpecification); |
||||
otherField = new DefaultField(fake.an<IReturnType>(), "OtherField", ModifierEnum.None, DomRegion.Empty, testClass); |
||||
testClass.Fields.Add(otherField); |
||||
|
||||
var behavesLikeReturnType = new ConstructedReturnType(SetupReturnType(MSpecBehavesTypeName), new List<IReturnType>{new DefaultReturnType(behaviorClass)}); |
||||
behavesLikeField = new DefaultField(behavesLikeReturnType, "behavesLikeField", ModifierEnum.None, new DomRegion(), testClass); |
||||
testClass.Fields.Add(behavesLikeField); |
||||
}; |
||||
|
||||
Because of = () => result = sut.GetTestMembersFor(testClass); |
||||
|
||||
It should_contain_field_with_it_return_type = () => |
||||
result.Select(m => m.Member).ShouldContain(testSpecification); |
||||
|
||||
It should_not_contain_field_with_arbitrary_return_type = () => |
||||
result.Select(m => m.Member).ShouldNotContain(otherField); |
||||
|
||||
It should_contain_imported_field_from_behavior = () => |
||||
result.Select(m => m.Member).ShouldContain(member => member.FullyQualifiedName == "TestClass.testSpecificationInBehavior"); |
||||
} |
||||
} |
||||
///*
|
||||
// * Created by SharpDevelop.
|
||||
// * User: trecio
|
||||
// * Date: 2011-06-18
|
||||
// * Time: 15:12
|
||||
// *
|
||||
// * To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
// */
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Collections.ObjectModel;
|
||||
//using System.Linq;
|
||||
//using developwithpassion.specifications.extensions;
|
||||
//using developwithpassion.specifications.dsl;
|
||||
//using developwithpassion.specifications.rhinomocks;
|
||||
//using ICSharpCode.SharpDevelop.Project;
|
||||
//using Machine.Specifications;
|
||||
//using ICSharpCode.UnitTesting;
|
||||
//using ICSharpCode.SharpDevelop.Dom;
|
||||
//using Rhino.Mocks;
|
||||
//
|
||||
//namespace ICSharpCode.MachineSpecifications.Tests
|
||||
//{
|
||||
// [Subject(typeof(MSpecTestFramework))]
|
||||
// public class When_checking_if_is_a_test_project : Observes<MSpecTestFramework>
|
||||
// {
|
||||
// static IProject testProject;
|
||||
// static IProject nonTestProject;
|
||||
//
|
||||
// static bool resultForTestProject;
|
||||
// static bool resultForNonTestProject;
|
||||
//
|
||||
// const string MSpecAssemblyName = "Machine.Specifications";
|
||||
//
|
||||
// Establish ctx = () =>
|
||||
// {
|
||||
// testProject = fake.an<IProject>();
|
||||
// var mspecReference = MockRepository.GenerateStub<ReferenceProjectItem>(testProject);
|
||||
// mspecReference.setup(x => x.ShortName).Return(MSpecAssemblyName);
|
||||
// testProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { mspecReference }));
|
||||
//
|
||||
// nonTestProject = fake.an<IProject>();
|
||||
// var otherReference = MockRepository.GenerateStub<ReferenceProjectItem>(nonTestProject);
|
||||
// mspecReference.setup(x => x.ShortName).Return("System.Configuration");
|
||||
// nonTestProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { otherReference }));
|
||||
// };
|
||||
//
|
||||
// Because of = () =>
|
||||
// {
|
||||
// resultForTestProject = sut.IsTestProject(testProject);
|
||||
// resultForNonTestProject = sut.IsTestProject(nonTestProject);
|
||||
// };
|
||||
//
|
||||
// It should_return_true_for_project_which_has_reference_to_test_framework = () =>
|
||||
// resultForTestProject.ShouldBeTrue();
|
||||
//
|
||||
// It should_return_false_for_project_which_has_no_reference_to_test_framework = () =>
|
||||
// resultForNonTestProject.ShouldBeFalse();
|
||||
// }
|
||||
//
|
||||
// public abstract class MSpecTestFrameworkFieldsConcern : Observes<MSpecTestFramework>
|
||||
// {
|
||||
// protected static ICompilationUnit CompilationUnit;
|
||||
//
|
||||
// Establish ctx = () =>
|
||||
// {
|
||||
// var ProjectContent = fake.an<IProjectContent>();
|
||||
// ProjectContent.setup(x => x.SystemTypes).Return(new SystemTypes(ProjectContent));
|
||||
// CompilationUnit = new DefaultCompilationUnit(ProjectContent);
|
||||
// };
|
||||
//
|
||||
// protected const string MSpecItTypeName = "Machine.Specifications.It";
|
||||
// protected const string MSpecBehavesTypeName = "Machine.Specifications.Behaves_like";
|
||||
// protected const string MSpecBehaviorTypeName = "Machine.Specifications.BehaviorsAttribute";
|
||||
//
|
||||
// protected static IClass SetupClass(bool isAbstract, IList<IField> fields, IList<IAttribute> attributes)
|
||||
// {
|
||||
// var c = fake.an<IClass>();
|
||||
// c.setup(x => x.IsAbstract).Return(isAbstract);
|
||||
// c.setup(x => x.Fields).Return(fields);
|
||||
// c.setup(x => x.Attributes).Return(attributes);
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// protected static IField SetupField(string returnTypeName)
|
||||
// {
|
||||
// var field = fake.an<IField>();
|
||||
// field.ReturnType = SetupReturnType(returnTypeName);
|
||||
// return field;
|
||||
// }
|
||||
//
|
||||
// protected static IAttribute SetupBehaviorAttribute()
|
||||
// {
|
||||
// var attribute = fake.an<IAttribute>();
|
||||
// attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName));
|
||||
// return attribute;
|
||||
// }
|
||||
//
|
||||
// protected static IReturnType SetupReturnType(string typeName)
|
||||
// {
|
||||
// var returnType = fake.an<IReturnType>();
|
||||
// returnType.Stub(x => x.FullyQualifiedName).Return(typeName);
|
||||
// return returnType;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Subject(typeof(MSpecTestFramework))]
|
||||
// public class When_checking_if_is_a_test_class : MSpecTestFrameworkFieldsConcern
|
||||
// {
|
||||
// static IClass classWithoutSpecificationMembers;
|
||||
// static IClass classWithSpecificationMembers;
|
||||
// static IClass classWithBehavior;
|
||||
// static IClass classWithSpecificationMembersAndBehaviorAttribute;
|
||||
//
|
||||
// static bool resultForClassWithBehaviorAttribute;
|
||||
// static bool resultForClassWithSpecifications;
|
||||
// static bool resultForClassWithBehavior;
|
||||
// static bool resultForClassWithoutSpecifications;
|
||||
//
|
||||
// Establish ctx = () =>
|
||||
// {
|
||||
// classWithoutSpecificationMembers = SetupClass(false, new IField[0], new IAttribute[0]);
|
||||
// classWithSpecificationMembers = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[0]);
|
||||
// classWithBehavior = SetupClass(false, new IField[] { SetupField(MSpecBehavesTypeName) }, new IAttribute[0]);
|
||||
// classWithSpecificationMembersAndBehaviorAttribute = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[] { SetupBehaviorAttribute() });
|
||||
// };
|
||||
//
|
||||
// Because of = () =>
|
||||
// {
|
||||
// resultForClassWithoutSpecifications = sut.IsTestClass(classWithoutSpecificationMembers);
|
||||
// resultForClassWithSpecifications = sut.IsTestClass(classWithSpecificationMembers);
|
||||
// resultForClassWithBehavior = sut.IsTestClass(classWithBehavior);
|
||||
// resultForClassWithBehaviorAttribute = sut.IsTestClass(classWithSpecificationMembersAndBehaviorAttribute);
|
||||
// };
|
||||
//
|
||||
// It should_return_false_for_class_without_specification_members = () =>
|
||||
// resultForClassWithoutSpecifications.ShouldBeFalse();
|
||||
//
|
||||
// It should_return_true_for_class_with_specification_members = () =>
|
||||
// resultForClassWithSpecifications.ShouldBeTrue();
|
||||
//
|
||||
// It should_return_true_for_class_with_behavior = () =>
|
||||
// resultForClassWithBehavior.ShouldBeTrue();
|
||||
//
|
||||
// It should_return_false_for_class_with_behavior_attribute = () =>
|
||||
// resultForClassWithBehaviorAttribute.ShouldBeFalse();
|
||||
// }
|
||||
//
|
||||
// public class When_enumerating_test_members : MSpecTestFrameworkFieldsConcern
|
||||
// {
|
||||
// static IClass behaviorClass;
|
||||
// static IField testSpecificationInBehavior;
|
||||
//
|
||||
// static IClass testClass;
|
||||
// static IField testSpecification;
|
||||
// static IField otherField;
|
||||
// static IField behavesLikeField;
|
||||
//
|
||||
// static IEnumerable<TestMember> result;
|
||||
//
|
||||
// const string BehaviorClassName = "Test.Behavior";
|
||||
//
|
||||
// Establish ctx = () =>
|
||||
// {
|
||||
// var itReturnType = SetupReturnType(MSpecItTypeName);
|
||||
//
|
||||
// behaviorClass = new DefaultClass(CompilationUnit, "BehaviorClass");
|
||||
// testSpecificationInBehavior = new DefaultField(itReturnType, "testSpecificationInBehavior", ModifierEnum.None, DomRegion.Empty, behaviorClass);
|
||||
// behaviorClass.Fields.Add(testSpecificationInBehavior);
|
||||
//
|
||||
// testClass = new DefaultClass(CompilationUnit, "TestClass");
|
||||
// testSpecification = new DefaultField(itReturnType, "testSpecification", ModifierEnum.None, DomRegion.Empty, testClass);
|
||||
// testClass.Fields.Add(testSpecification);
|
||||
// otherField = new DefaultField(fake.an<IReturnType>(), "OtherField", ModifierEnum.None, DomRegion.Empty, testClass);
|
||||
// testClass.Fields.Add(otherField);
|
||||
//
|
||||
// var behavesLikeReturnType = new ConstructedReturnType(SetupReturnType(MSpecBehavesTypeName), new List<IReturnType>{new DefaultReturnType(behaviorClass)});
|
||||
// behavesLikeField = new DefaultField(behavesLikeReturnType, "behavesLikeField", ModifierEnum.None, new DomRegion(), testClass);
|
||||
// testClass.Fields.Add(behavesLikeField);
|
||||
// };
|
||||
//
|
||||
// Because of = () => result = sut.GetTestMembersFor(testClass);
|
||||
//
|
||||
// It should_contain_field_with_it_return_type = () =>
|
||||
// result.Select(m => m.Member).ShouldContain(testSpecification);
|
||||
//
|
||||
// It should_not_contain_field_with_arbitrary_return_type = () =>
|
||||
// result.Select(m => m.Member).ShouldNotContain(otherField);
|
||||
//
|
||||
// It should_contain_imported_field_from_behavior = () =>
|
||||
// result.Select(m => m.Member).ShouldContain(member => member.FullyQualifiedName == "TestClass.testSpecificationInBehavior");
|
||||
// }
|
||||
//}
|
||||
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Widgets; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.MachineSpecifications |
||||
{ |
||||
public class MSpecTestClass : TestBase |
||||
{ |
||||
MSpecTestProject parentProject; |
||||
FullTypeName fullTypeName; |
||||
|
||||
public MSpecTestClass(MSpecTestProject parentProject, FullTypeName fullTypeName) |
||||
{ |
||||
this.parentProject = parentProject; |
||||
this.fullTypeName = fullTypeName; |
||||
BindResultToCompositeResultOfNestedTests(); |
||||
} |
||||
|
||||
public override ITestProject ParentProject { |
||||
get { return parentProject; } |
||||
} |
||||
|
||||
public override string DisplayName { |
||||
get { return fullTypeName.Name; } |
||||
} |
||||
|
||||
protected override void OnNestedTestsInitialized() |
||||
{ |
||||
ITypeDefinition typeDefinition = Resolve(); |
||||
if (typeDefinition != null) { |
||||
Update(typeDefinition); |
||||
} |
||||
base.OnNestedTestsInitialized(); |
||||
} |
||||
|
||||
public void Update(ITypeDefinition typeDefinition) |
||||
{ |
||||
if (!NestedTestsInitialized) |
||||
return; |
||||
|
||||
var newOrUpdatedTests = new HashSet<ITest>(); |
||||
foreach (ITest test in parentProject.GetTestMembersFor(typeDefinition)) { |
||||
MSpecTestMember existingTest = FindTestMember(test); |
||||
if (existingTest == null) { |
||||
NestedTestCollection.Add(test); |
||||
newOrUpdatedTests.Add(test); |
||||
} else { |
||||
newOrUpdatedTests.Add(existingTest); |
||||
} |
||||
} |
||||
|
||||
NestedTestCollection.RemoveAll(t => !newOrUpdatedTests.Contains(t)); |
||||
} |
||||
|
||||
MSpecTestMember FindTestMember(ITest test) |
||||
{ |
||||
var testMember = test as MSpecTestMember; |
||||
return FindTestMember(testMember.DisplayName); |
||||
} |
||||
|
||||
public MSpecTestMember FindTestMember(string name) |
||||
{ |
||||
return NestedTestCollection |
||||
.OfType<MSpecTestMember>() |
||||
.LastOrDefault(member => member.DisplayName == name); |
||||
} |
||||
|
||||
public override System.Windows.Input.ICommand GoToDefinition { |
||||
get { |
||||
return new RelayCommand( |
||||
delegate { |
||||
ITypeDefinition typeDefinition = Resolve(); |
||||
if (typeDefinition != null) |
||||
NavigationService.NavigateTo(typeDefinition); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
public ITypeDefinition Resolve() |
||||
{ |
||||
ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project); |
||||
IType type = compilation.MainAssembly.GetTypeDefinition(fullTypeName); |
||||
return type.GetDefinition(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.MachineSpecifications |
||||
{ |
||||
public class MSpecTestMember : TestBase |
||||
{ |
||||
MSpecTestProject parentProject; |
||||
string displayName; |
||||
|
||||
public MSpecTestMember(MSpecTestProject parentProject, string displayName) |
||||
{ |
||||
this.parentProject = parentProject; |
||||
this.displayName = displayName; |
||||
} |
||||
|
||||
public MSpecTestMember( |
||||
MSpecTestProject parentProject, |
||||
IMember member) |
||||
: this(parentProject, member.DeclaringType.Name + "." + member.Name) |
||||
{ |
||||
} |
||||
|
||||
public override ITestProject ParentProject { |
||||
get { return parentProject; } |
||||
} |
||||
|
||||
public override string DisplayName { |
||||
get { return displayName; } |
||||
} |
||||
|
||||
public void UpdateTestResult(TestResult result) |
||||
{ |
||||
this.Result = result.ResultType; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.MachineSpecifications |
||||
{ |
||||
public class MSpecTestProcessRunnerContext : TestProcessRunnerBaseContext |
||||
{ |
||||
public MSpecTestProcessRunnerContext(TestExecutionOptions options) |
||||
: base( |
||||
options, |
||||
new UnitTestProcessRunner(), |
||||
new MSpecUnitTestMonitor(), |
||||
new UnitTestFileService(), |
||||
SD.MessageService) |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.MachineSpecifications |
||||
{ |
||||
public class MSpecTestProject : TestProjectBase |
||||
{ |
||||
public const string MSpecAssemblyName = "Machine.Specifications"; |
||||
|
||||
const string MSpecItFQName = MSpecAssemblyName + ".It"; |
||||
const string MSpecBehavesLikeFQName = MSpecAssemblyName + ".Behaves_like"; |
||||
const string MSpecBehaviorsAttributeFQName = MSpecAssemblyName + ".BehaviorsAttribute"; |
||||
|
||||
public MSpecTestProject(ITestSolution parentSolution, IProject project) |
||||
: base(project) |
||||
{ |
||||
} |
||||
|
||||
public override void UpdateTestResult(TestResult result) |
||||
{ |
||||
// Code duplication - taken from NUnitTestProject
|
||||
int lastDot = result.Name.LastIndexOf('.'); |
||||
if (lastDot < 0) |
||||
return; |
||||
|
||||
string fixtureName = result.Name.Substring(0, lastDot); |
||||
string memberName = result.Name.Substring(lastDot + 1); |
||||
|
||||
var testClass = GetMSpecTestClass(new FullTypeName(fixtureName)) as MSpecTestClass; |
||||
MSpecTestMember test = testClass.FindTestMember(memberName); |
||||
if (test != null) |
||||
test.UpdateTestResult(result); |
||||
} |
||||
|
||||
MSpecTestClass GetMSpecTestClass(FullTypeName fullTypeName) |
||||
{ |
||||
return GetTestClass(fullTypeName.TopLevelTypeName) as MSpecTestClass; |
||||
} |
||||
|
||||
protected override void UpdateTestClass(ITest test, ITypeDefinition typeDefinition) |
||||
{ |
||||
var mspecTest = test as MSpecTestClass; |
||||
mspecTest.Update(typeDefinition); |
||||
} |
||||
|
||||
protected override bool IsTestClass(ITypeDefinition typeDefinition) |
||||
{ |
||||
return HasSpecificationMembers(typeDefinition) && !HasBehaviorAttribute(typeDefinition); |
||||
} |
||||
|
||||
public override IEnumerable<ITest> GetTestsForEntity(IEntity entity) |
||||
{ |
||||
return new ITest[0]; |
||||
} |
||||
|
||||
public override ITestRunner CreateTestRunner(TestExecutionOptions options) |
||||
{ |
||||
if (options.UseDebugger) |
||||
return new MSpecTestDebugger(); |
||||
|
||||
return new MSpecTestRunner(options); |
||||
} |
||||
|
||||
protected override ITest CreateTestClass(ITypeDefinition typeDefinition) |
||||
{ |
||||
if (IsTestClass(typeDefinition)) |
||||
return new MSpecTestClass(this, typeDefinition.FullTypeName); |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public bool IsTestMember(IMember member) |
||||
{ |
||||
return member is IField && HasItReturnType(member as IField); |
||||
} |
||||
|
||||
public IEnumerable<ITest> GetTestMembersFor(ITypeDefinition typeDefinition) |
||||
{ |
||||
return GetTestMembers(typeDefinition, typeDefinition.Fields); |
||||
} |
||||
|
||||
IEnumerable<ITest> GetTestMembers(ITypeDefinition testClass, IEnumerable<IField> fields) |
||||
{ |
||||
var result = fields.Where(HasItReturnType).Select(field => new MSpecTestMember(this, field.Name)).ToList(); |
||||
foreach (var field in fields) { |
||||
if (HasBehavesLikeReturnType(field)) { |
||||
var behaviorFields = ResolveBehaviorFieldsOf(field); |
||||
var behaviorMembers = behaviorFields.Where(HasItReturnType); |
||||
var testMembersFromBehavior = behaviorMembers.Select(testField => |
||||
new BehaviorImportedTestMember(this, testField)); |
||||
result.AddRange(testMembersFromBehavior); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
IEnumerable<IField> ResolveBehaviorFieldsOf(IField field) |
||||
{ |
||||
var fieldReturnType = field.ReturnType; |
||||
if (fieldReturnType == null) return new List<IField>(); |
||||
if (fieldReturnType.TypeArguments.Count != 1) |
||||
LoggingService.Error(string.Format("Expected behavior specification {0} to have one type argument but {1} found.", field.FullName, fieldReturnType.TypeArguments.Count)); |
||||
var behaviorClassType = fieldReturnType.TypeArguments.FirstOrDefault(); |
||||
|
||||
return behaviorClassType != null ? behaviorClassType.GetFields() : new List<IField>(); |
||||
} |
||||
|
||||
private bool HasSpecificationMembers(ITypeDefinition typeDefinition) |
||||
{ |
||||
return !typeDefinition.IsAbstract |
||||
&& typeDefinition.Fields.Any(f => HasItReturnType(f) || HasBehavesLikeReturnType(f)); |
||||
} |
||||
|
||||
private bool HasBehavesLikeReturnType(IField field) |
||||
{ |
||||
return MSpecBehavesLikeFQName.Equals(field.ReturnType.FullName); |
||||
} |
||||
|
||||
private bool HasItReturnType(IField field) |
||||
{ |
||||
return MSpecItFQName.Equals(field.ReturnType.FullName); |
||||
} |
||||
|
||||
private bool HasBehaviorAttribute(ITypeDefinition typeDefinition) |
||||
{ |
||||
return typeDefinition.Attributes.Any( |
||||
attribute => MSpecBehaviorsAttributeFQName.Equals(attribute.AttributeType.FullName)); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue