19 changed files with 770 additions and 445 deletions
@ -1,70 +1,70 @@ |
|||||||
/* |
///*
|
||||||
* Created by SharpDevelop. |
// * Created by SharpDevelop.
|
||||||
* User: trecio |
// * User: trecio
|
||||||
* Date: 2011-09-23 |
// * Date: 2011-09-23
|
||||||
* Time: 19:53 |
// * Time: 19:53
|
||||||
* |
// *
|
||||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
// * To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||||
*/ |
// */
|
||||||
using System; |
//using System;
|
||||||
using System.Collections.Generic; |
//using System.Collections.Generic;
|
||||||
using developwithpassion.specifications.extensions; |
//using developwithpassion.specifications.extensions;
|
||||||
using developwithpassion.specifications.rhinomocks; |
//using developwithpassion.specifications.rhinomocks;
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
//using ICSharpCode.SharpDevelop.Dom;
|
||||||
using ICSharpCode.SharpDevelop.Project; |
//using ICSharpCode.SharpDevelop.Project;
|
||||||
using ICSharpCode.UnitTesting; |
//using ICSharpCode.UnitTesting;
|
||||||
using Machine.Specifications; |
//using Machine.Specifications;
|
||||||
using Machine.Fakes.Adapters.Rhinomocks; |
//using Machine.Fakes.Adapters.Rhinomocks;
|
||||||
|
//
|
||||||
namespace ICSharpCode.MachineSpecifications.Tests |
//namespace ICSharpCode.MachineSpecifications.Tests
|
||||||
{ |
//{
|
||||||
[Subject(typeof(ClassFilterBuilder))] |
// [Subject(typeof(ClassFilterBuilder))]
|
||||||
public class When_building_class_filter_from_test_selection : Observes<ClassFilterBuilder> |
// public class When_building_class_filter_from_test_selection : Observes<ClassFilterBuilder>
|
||||||
{ |
// {
|
||||||
const string NAMESPACE_FILTER = "Namespace"; |
// const string NAMESPACE_FILTER = "Namespace";
|
||||||
static DefaultClass classAddedExplicitly, classInNamespace, classOutsideNamespace, classNestedInAddedExplicitly, classNestedInClassInNamespace; |
// static DefaultClass classAddedExplicitly, classInNamespace, classOutsideNamespace, classNestedInAddedExplicitly, classNestedInClassInNamespace;
|
||||||
static SelectedTests selectedTests; |
// static SelectedTests selectedTests;
|
||||||
static IProjectContent projectContent; |
// static IProjectContent projectContent;
|
||||||
static IList<string> result; |
// static IList<string> result;
|
||||||
|
//
|
||||||
Establish ctx = () => { |
// Establish ctx = () => {
|
||||||
projectContent = fake.an<IProjectContent>(); |
// projectContent = fake.an<IProjectContent>();
|
||||||
projectContent.setup(x => x.SystemTypes).Return(new SystemTypes(projectContent)); |
// projectContent.setup(x => x.SystemTypes).Return(new SystemTypes(projectContent));
|
||||||
var compilationUnit = new DefaultCompilationUnit(projectContent); |
// var compilationUnit = new DefaultCompilationUnit(projectContent);
|
||||||
|
//
|
||||||
classAddedExplicitly = new DefaultClass(compilationUnit, "ClassAddedExplicitly"); |
// classAddedExplicitly = new DefaultClass(compilationUnit, "ClassAddedExplicitly");
|
||||||
classNestedInAddedExplicitly = new DefaultClass(compilationUnit, classAddedExplicitly); |
// classNestedInAddedExplicitly = new DefaultClass(compilationUnit, classAddedExplicitly);
|
||||||
classNestedInAddedExplicitly.FullyQualifiedName = "ClassAddedExplicitly.InnerClass"; |
// classNestedInAddedExplicitly.FullyQualifiedName = "ClassAddedExplicitly.InnerClass";
|
||||||
classAddedExplicitly.InnerClasses.Add(classNestedInAddedExplicitly); |
// classAddedExplicitly.InnerClasses.Add(classNestedInAddedExplicitly);
|
||||||
|
//
|
||||||
classInNamespace = new DefaultClass(compilationUnit, "Namespace.OtherNamespace.ClassInNamespace"); |
// classInNamespace = new DefaultClass(compilationUnit, "Namespace.OtherNamespace.ClassInNamespace");
|
||||||
classNestedInClassInNamespace = new DefaultClass(compilationUnit, classInNamespace); |
// classNestedInClassInNamespace = new DefaultClass(compilationUnit, classInNamespace);
|
||||||
classNestedInClassInNamespace.FullyQualifiedName = "Namespace.OtherNamespace.ClassInNamespace.InnerClass"; |
// classNestedInClassInNamespace.FullyQualifiedName = "Namespace.OtherNamespace.ClassInNamespace.InnerClass";
|
||||||
classInNamespace.InnerClasses.Add(classNestedInClassInNamespace); |
// classInNamespace.InnerClasses.Add(classNestedInClassInNamespace);
|
||||||
classOutsideNamespace = new DefaultClass(compilationUnit, "Namespace2.ClassOutsideNamespac"); |
// classOutsideNamespace = new DefaultClass(compilationUnit, "Namespace2.ClassOutsideNamespac");
|
||||||
|
//
|
||||||
var project = fake.an<IProject>(); |
// var project = fake.an<IProject>();
|
||||||
projectContent.setup(x => x.Classes).Return(new[]{classInNamespace, classOutsideNamespace}); |
// projectContent.setup(x => x.Classes).Return(new[]{classInNamespace, classOutsideNamespace});
|
||||||
|
//
|
||||||
selectedTests = new SelectedTests(project, NAMESPACE_FILTER, classAddedExplicitly, null); |
// selectedTests = new SelectedTests(project, NAMESPACE_FILTER, classAddedExplicitly, null);
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
Because of = () => |
// Because of = () =>
|
||||||
result = sut.BuildFilterFor(selectedTests, projectContent); |
// result = sut.BuildFilterFor(selectedTests, projectContent);
|
||||||
|
//
|
||||||
It should_add_dotnet_name_of_selected_test_class = () => |
// It should_add_dotnet_name_of_selected_test_class = () =>
|
||||||
result.ShouldContain(classAddedExplicitly.DotNetName); |
// result.ShouldContain(classAddedExplicitly.DotNetName);
|
||||||
|
//
|
||||||
It should_add_class_included_in_selected_namespace = () => |
// It should_add_class_included_in_selected_namespace = () =>
|
||||||
result.ShouldContain(classInNamespace.DotNetName); |
// result.ShouldContain(classInNamespace.DotNetName);
|
||||||
|
//
|
||||||
It should_not_include_class_not_included_in_namespace = () => |
// It should_not_include_class_not_included_in_namespace = () =>
|
||||||
result.ShouldNotContain(classOutsideNamespace.DotNetName); |
// result.ShouldNotContain(classOutsideNamespace.DotNetName);
|
||||||
|
//
|
||||||
It should_not_include_class_nested_in_selected_test_class = () => |
// It should_not_include_class_nested_in_selected_test_class = () =>
|
||||||
result.ShouldNotContain(classNestedInAddedExplicitly.DotNetName); |
// result.ShouldNotContain(classNestedInAddedExplicitly.DotNetName);
|
||||||
|
//
|
||||||
It should_include_class_nested_in_class_from_selected_namespace = () => |
// It should_include_class_nested_in_class_from_selected_namespace = () =>
|
||||||
result.ShouldContain(classNestedInClassInNamespace.DotNetName); |
// result.ShouldContain(classNestedInClassInNamespace.DotNetName);
|
||||||
} |
// }
|
||||||
} |
//}
|
||||||
|
|||||||
@ -1,193 +1,193 @@ |
|||||||
/* |
///*
|
||||||
* Created by SharpDevelop. |
// * Created by SharpDevelop.
|
||||||
* User: trecio |
// * User: trecio
|
||||||
* Date: 2011-06-18 |
// * Date: 2011-06-18
|
||||||
* Time: 15:12 |
// * Time: 15:12
|
||||||
* |
// *
|
||||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
// * To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||||
*/ |
// */
|
||||||
using System; |
//using System;
|
||||||
using System.Collections.Generic; |
//using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel; |
//using System.Collections.ObjectModel;
|
||||||
using System.Linq; |
//using System.Linq;
|
||||||
using developwithpassion.specifications.extensions; |
//using developwithpassion.specifications.extensions;
|
||||||
using developwithpassion.specifications.dsl; |
//using developwithpassion.specifications.dsl;
|
||||||
using developwithpassion.specifications.rhinomocks; |
//using developwithpassion.specifications.rhinomocks;
|
||||||
using ICSharpCode.SharpDevelop.Project; |
//using ICSharpCode.SharpDevelop.Project;
|
||||||
using Machine.Specifications; |
//using Machine.Specifications;
|
||||||
using ICSharpCode.UnitTesting; |
//using ICSharpCode.UnitTesting;
|
||||||
using ICSharpCode.SharpDevelop.Dom; |
//using ICSharpCode.SharpDevelop.Dom;
|
||||||
using Rhino.Mocks; |
//using Rhino.Mocks;
|
||||||
|
//
|
||||||
namespace ICSharpCode.MachineSpecifications.Tests |
//namespace ICSharpCode.MachineSpecifications.Tests
|
||||||
{ |
//{
|
||||||
[Subject(typeof(MSpecTestFramework))] |
// [Subject(typeof(MSpecTestFramework))]
|
||||||
public class When_checking_if_is_a_test_project : Observes<MSpecTestFramework> |
// public class When_checking_if_is_a_test_project : Observes<MSpecTestFramework>
|
||||||
{ |
// {
|
||||||
static IProject testProject; |
// static IProject testProject;
|
||||||
static IProject nonTestProject; |
// static IProject nonTestProject;
|
||||||
|
//
|
||||||
static bool resultForTestProject; |
// static bool resultForTestProject;
|
||||||
static bool resultForNonTestProject; |
// static bool resultForNonTestProject;
|
||||||
|
//
|
||||||
const string MSpecAssemblyName = "Machine.Specifications"; |
// const string MSpecAssemblyName = "Machine.Specifications";
|
||||||
|
//
|
||||||
Establish ctx = () => |
// Establish ctx = () =>
|
||||||
{ |
// {
|
||||||
testProject = fake.an<IProject>(); |
// testProject = fake.an<IProject>();
|
||||||
var mspecReference = MockRepository.GenerateStub<ReferenceProjectItem>(testProject); |
// var mspecReference = MockRepository.GenerateStub<ReferenceProjectItem>(testProject);
|
||||||
mspecReference.setup(x => x.ShortName).Return(MSpecAssemblyName); |
// mspecReference.setup(x => x.ShortName).Return(MSpecAssemblyName);
|
||||||
testProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { mspecReference })); |
// testProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { mspecReference }));
|
||||||
|
//
|
||||||
nonTestProject = fake.an<IProject>(); |
// nonTestProject = fake.an<IProject>();
|
||||||
var otherReference = MockRepository.GenerateStub<ReferenceProjectItem>(nonTestProject); |
// var otherReference = MockRepository.GenerateStub<ReferenceProjectItem>(nonTestProject);
|
||||||
mspecReference.setup(x => x.ShortName).Return("System.Configuration"); |
// mspecReference.setup(x => x.ShortName).Return("System.Configuration");
|
||||||
nonTestProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { otherReference })); |
// nonTestProject.setup(x => x.Items).Return(new ReadOnlyCollection<ProjectItem>(new[] { otherReference }));
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
Because of = () => |
// Because of = () =>
|
||||||
{ |
// {
|
||||||
resultForTestProject = sut.IsTestProject(testProject); |
// resultForTestProject = sut.IsTestProject(testProject);
|
||||||
resultForNonTestProject = sut.IsTestProject(nonTestProject); |
// resultForNonTestProject = sut.IsTestProject(nonTestProject);
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
It should_return_true_for_project_which_has_reference_to_test_framework = () => |
// It should_return_true_for_project_which_has_reference_to_test_framework = () =>
|
||||||
resultForTestProject.ShouldBeTrue(); |
// resultForTestProject.ShouldBeTrue();
|
||||||
|
//
|
||||||
It should_return_false_for_project_which_has_no_reference_to_test_framework = () => |
// It should_return_false_for_project_which_has_no_reference_to_test_framework = () =>
|
||||||
resultForNonTestProject.ShouldBeFalse(); |
// resultForNonTestProject.ShouldBeFalse();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
public abstract class MSpecTestFrameworkFieldsConcern : Observes<MSpecTestFramework> |
// public abstract class MSpecTestFrameworkFieldsConcern : Observes<MSpecTestFramework>
|
||||||
{ |
// {
|
||||||
protected static ICompilationUnit CompilationUnit; |
// protected static ICompilationUnit CompilationUnit;
|
||||||
|
//
|
||||||
Establish ctx = () => |
// Establish ctx = () =>
|
||||||
{ |
// {
|
||||||
var ProjectContent = fake.an<IProjectContent>(); |
// var ProjectContent = fake.an<IProjectContent>();
|
||||||
ProjectContent.setup(x => x.SystemTypes).Return(new SystemTypes(ProjectContent)); |
// ProjectContent.setup(x => x.SystemTypes).Return(new SystemTypes(ProjectContent));
|
||||||
CompilationUnit = new DefaultCompilationUnit(ProjectContent); |
// CompilationUnit = new DefaultCompilationUnit(ProjectContent);
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
protected const string MSpecItTypeName = "Machine.Specifications.It"; |
// protected const string MSpecItTypeName = "Machine.Specifications.It";
|
||||||
protected const string MSpecBehavesTypeName = "Machine.Specifications.Behaves_like"; |
// protected const string MSpecBehavesTypeName = "Machine.Specifications.Behaves_like";
|
||||||
protected const string MSpecBehaviorTypeName = "Machine.Specifications.BehaviorsAttribute"; |
// protected const string MSpecBehaviorTypeName = "Machine.Specifications.BehaviorsAttribute";
|
||||||
|
//
|
||||||
protected static IClass SetupClass(bool isAbstract, IList<IField> fields, IList<IAttribute> attributes) |
// protected static IClass SetupClass(bool isAbstract, IList<IField> fields, IList<IAttribute> attributes)
|
||||||
{ |
// {
|
||||||
var c = fake.an<IClass>(); |
// var c = fake.an<IClass>();
|
||||||
c.setup(x => x.IsAbstract).Return(isAbstract); |
// c.setup(x => x.IsAbstract).Return(isAbstract);
|
||||||
c.setup(x => x.Fields).Return(fields); |
// c.setup(x => x.Fields).Return(fields);
|
||||||
c.setup(x => x.Attributes).Return(attributes); |
// c.setup(x => x.Attributes).Return(attributes);
|
||||||
return c; |
// return c;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
protected static IField SetupField(string returnTypeName) |
// protected static IField SetupField(string returnTypeName)
|
||||||
{ |
// {
|
||||||
var field = fake.an<IField>(); |
// var field = fake.an<IField>();
|
||||||
field.ReturnType = SetupReturnType(returnTypeName); |
// field.ReturnType = SetupReturnType(returnTypeName);
|
||||||
return field; |
// return field;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
protected static IAttribute SetupBehaviorAttribute() |
// protected static IAttribute SetupBehaviorAttribute()
|
||||||
{ |
// {
|
||||||
var attribute = fake.an<IAttribute>(); |
// var attribute = fake.an<IAttribute>();
|
||||||
attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName)); |
// attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName));
|
||||||
return attribute; |
// return attribute;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
protected static IReturnType SetupReturnType(string typeName) |
// protected static IReturnType SetupReturnType(string typeName)
|
||||||
{ |
// {
|
||||||
var returnType = fake.an<IReturnType>(); |
// var returnType = fake.an<IReturnType>();
|
||||||
returnType.Stub(x => x.FullyQualifiedName).Return(typeName); |
// returnType.Stub(x => x.FullyQualifiedName).Return(typeName);
|
||||||
return returnType; |
// return returnType;
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
[Subject(typeof(MSpecTestFramework))] |
// [Subject(typeof(MSpecTestFramework))]
|
||||||
public class When_checking_if_is_a_test_class : MSpecTestFrameworkFieldsConcern |
// public class When_checking_if_is_a_test_class : MSpecTestFrameworkFieldsConcern
|
||||||
{ |
// {
|
||||||
static IClass classWithoutSpecificationMembers; |
// static IClass classWithoutSpecificationMembers;
|
||||||
static IClass classWithSpecificationMembers; |
// static IClass classWithSpecificationMembers;
|
||||||
static IClass classWithBehavior; |
// static IClass classWithBehavior;
|
||||||
static IClass classWithSpecificationMembersAndBehaviorAttribute; |
// static IClass classWithSpecificationMembersAndBehaviorAttribute;
|
||||||
|
//
|
||||||
static bool resultForClassWithBehaviorAttribute; |
// static bool resultForClassWithBehaviorAttribute;
|
||||||
static bool resultForClassWithSpecifications; |
// static bool resultForClassWithSpecifications;
|
||||||
static bool resultForClassWithBehavior; |
// static bool resultForClassWithBehavior;
|
||||||
static bool resultForClassWithoutSpecifications; |
// static bool resultForClassWithoutSpecifications;
|
||||||
|
//
|
||||||
Establish ctx = () => |
// Establish ctx = () =>
|
||||||
{ |
// {
|
||||||
classWithoutSpecificationMembers = SetupClass(false, new IField[0], new IAttribute[0]); |
// classWithoutSpecificationMembers = SetupClass(false, new IField[0], new IAttribute[0]);
|
||||||
classWithSpecificationMembers = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[0]); |
// classWithSpecificationMembers = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[0]);
|
||||||
classWithBehavior = SetupClass(false, new IField[] { SetupField(MSpecBehavesTypeName) }, new IAttribute[0]); |
// classWithBehavior = SetupClass(false, new IField[] { SetupField(MSpecBehavesTypeName) }, new IAttribute[0]);
|
||||||
classWithSpecificationMembersAndBehaviorAttribute = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[] { SetupBehaviorAttribute() }); |
// classWithSpecificationMembersAndBehaviorAttribute = SetupClass(false, new IField[] { SetupField(MSpecItTypeName) }, new IAttribute[] { SetupBehaviorAttribute() });
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
Because of = () => |
// Because of = () =>
|
||||||
{ |
// {
|
||||||
resultForClassWithoutSpecifications = sut.IsTestClass(classWithoutSpecificationMembers); |
// resultForClassWithoutSpecifications = sut.IsTestClass(classWithoutSpecificationMembers);
|
||||||
resultForClassWithSpecifications = sut.IsTestClass(classWithSpecificationMembers); |
// resultForClassWithSpecifications = sut.IsTestClass(classWithSpecificationMembers);
|
||||||
resultForClassWithBehavior = sut.IsTestClass(classWithBehavior); |
// resultForClassWithBehavior = sut.IsTestClass(classWithBehavior);
|
||||||
resultForClassWithBehaviorAttribute = sut.IsTestClass(classWithSpecificationMembersAndBehaviorAttribute); |
// resultForClassWithBehaviorAttribute = sut.IsTestClass(classWithSpecificationMembersAndBehaviorAttribute);
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
It should_return_false_for_class_without_specification_members = () => |
// It should_return_false_for_class_without_specification_members = () =>
|
||||||
resultForClassWithoutSpecifications.ShouldBeFalse(); |
// resultForClassWithoutSpecifications.ShouldBeFalse();
|
||||||
|
//
|
||||||
It should_return_true_for_class_with_specification_members = () => |
// It should_return_true_for_class_with_specification_members = () =>
|
||||||
resultForClassWithSpecifications.ShouldBeTrue(); |
// resultForClassWithSpecifications.ShouldBeTrue();
|
||||||
|
//
|
||||||
It should_return_true_for_class_with_behavior = () => |
// It should_return_true_for_class_with_behavior = () =>
|
||||||
resultForClassWithBehavior.ShouldBeTrue(); |
// resultForClassWithBehavior.ShouldBeTrue();
|
||||||
|
//
|
||||||
It should_return_false_for_class_with_behavior_attribute = () => |
// It should_return_false_for_class_with_behavior_attribute = () =>
|
||||||
resultForClassWithBehaviorAttribute.ShouldBeFalse(); |
// resultForClassWithBehaviorAttribute.ShouldBeFalse();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
public class When_enumerating_test_members : MSpecTestFrameworkFieldsConcern |
// public class When_enumerating_test_members : MSpecTestFrameworkFieldsConcern
|
||||||
{ |
// {
|
||||||
static IClass behaviorClass; |
// static IClass behaviorClass;
|
||||||
static IField testSpecificationInBehavior; |
// static IField testSpecificationInBehavior;
|
||||||
|
//
|
||||||
static IClass testClass; |
// static IClass testClass;
|
||||||
static IField testSpecification; |
// static IField testSpecification;
|
||||||
static IField otherField; |
// static IField otherField;
|
||||||
static IField behavesLikeField; |
// static IField behavesLikeField;
|
||||||
|
//
|
||||||
static IEnumerable<TestMember> result; |
// static IEnumerable<TestMember> result;
|
||||||
|
//
|
||||||
const string BehaviorClassName = "Test.Behavior"; |
// const string BehaviorClassName = "Test.Behavior";
|
||||||
|
//
|
||||||
Establish ctx = () => |
// Establish ctx = () =>
|
||||||
{ |
// {
|
||||||
var itReturnType = SetupReturnType(MSpecItTypeName); |
// var itReturnType = SetupReturnType(MSpecItTypeName);
|
||||||
|
//
|
||||||
behaviorClass = new DefaultClass(CompilationUnit, "BehaviorClass"); |
// behaviorClass = new DefaultClass(CompilationUnit, "BehaviorClass");
|
||||||
testSpecificationInBehavior = new DefaultField(itReturnType, "testSpecificationInBehavior", ModifierEnum.None, DomRegion.Empty, behaviorClass); |
// testSpecificationInBehavior = new DefaultField(itReturnType, "testSpecificationInBehavior", ModifierEnum.None, DomRegion.Empty, behaviorClass);
|
||||||
behaviorClass.Fields.Add(testSpecificationInBehavior); |
// behaviorClass.Fields.Add(testSpecificationInBehavior);
|
||||||
|
//
|
||||||
testClass = new DefaultClass(CompilationUnit, "TestClass"); |
// testClass = new DefaultClass(CompilationUnit, "TestClass");
|
||||||
testSpecification = new DefaultField(itReturnType, "testSpecification", ModifierEnum.None, DomRegion.Empty, testClass); |
// testSpecification = new DefaultField(itReturnType, "testSpecification", ModifierEnum.None, DomRegion.Empty, testClass);
|
||||||
testClass.Fields.Add(testSpecification); |
// testClass.Fields.Add(testSpecification);
|
||||||
otherField = new DefaultField(fake.an<IReturnType>(), "OtherField", ModifierEnum.None, DomRegion.Empty, testClass); |
// otherField = new DefaultField(fake.an<IReturnType>(), "OtherField", ModifierEnum.None, DomRegion.Empty, testClass);
|
||||||
testClass.Fields.Add(otherField); |
// testClass.Fields.Add(otherField);
|
||||||
|
//
|
||||||
var behavesLikeReturnType = new ConstructedReturnType(SetupReturnType(MSpecBehavesTypeName), new List<IReturnType>{new DefaultReturnType(behaviorClass)}); |
// var behavesLikeReturnType = new ConstructedReturnType(SetupReturnType(MSpecBehavesTypeName), new List<IReturnType>{new DefaultReturnType(behaviorClass)});
|
||||||
behavesLikeField = new DefaultField(behavesLikeReturnType, "behavesLikeField", ModifierEnum.None, new DomRegion(), testClass); |
// behavesLikeField = new DefaultField(behavesLikeReturnType, "behavesLikeField", ModifierEnum.None, new DomRegion(), testClass);
|
||||||
testClass.Fields.Add(behavesLikeField); |
// testClass.Fields.Add(behavesLikeField);
|
||||||
}; |
// };
|
||||||
|
//
|
||||||
Because of = () => result = sut.GetTestMembersFor(testClass); |
// Because of = () => result = sut.GetTestMembersFor(testClass);
|
||||||
|
//
|
||||||
It should_contain_field_with_it_return_type = () => |
// It should_contain_field_with_it_return_type = () =>
|
||||||
result.Select(m => m.Member).ShouldContain(testSpecification); |
// result.Select(m => m.Member).ShouldContain(testSpecification);
|
||||||
|
//
|
||||||
It should_not_contain_field_with_arbitrary_return_type = () => |
// It should_not_contain_field_with_arbitrary_return_type = () =>
|
||||||
result.Select(m => m.Member).ShouldNotContain(otherField); |
// result.Select(m => m.Member).ShouldNotContain(otherField);
|
||||||
|
//
|
||||||
It should_contain_imported_field_from_behavior = () => |
// It should_contain_imported_field_from_behavior = () =>
|
||||||
result.Select(m => m.Member).ShouldContain(member => member.FullyQualifiedName == "TestClass.testSpecificationInBehavior"); |
// result.Select(m => m.Member).ShouldContain(member => member.FullyQualifiedName == "TestClass.testSpecificationInBehavior");
|
||||||
} |
// }
|
||||||
} |
//}
|
||||||
@ -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 @@ |
|||||||
|
// 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 @@ |
|||||||
|
// 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 @@ |
|||||||
|
// 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