diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj index 015bc3e142..36d064a4db 100644 --- a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj @@ -73,8 +73,10 @@ + + @@ -85,6 +87,10 @@ + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory + {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs index 1e26d5d855..65e786917d 100644 --- a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs @@ -1,182 +1,53 @@ -//// 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.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 -// { -// static IProject testProject; -// static IProject nonTestProject; -// -// static bool resultForTestProject; -// static bool resultForNonTestProject; -// -// const string MSpecAssemblyName = "Machine.Specifications"; -// -// Establish ctx = () => { -// testProject = fake.an(); -// var mspecReference = MockRepository.GenerateStub(testProject); -// mspecReference.setup(x => x.ShortName).Return(MSpecAssemblyName); -// testProject.setup(x => x.Items).Return(new ReadOnlyCollection(new[] { mspecReference })); -// -// nonTestProject = fake.an(); -// var otherReference = MockRepository.GenerateStub(nonTestProject); -// mspecReference.setup(x => x.ShortName).Return("System.Configuration"); -// nonTestProject.setup(x => x.Items).Return(new ReadOnlyCollection(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 -// { -// protected static ICompilationUnit CompilationUnit; -// -// Establish ctx = () => { -// var ProjectContent = fake.an(); -// 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 fields, IList attributes) -// { -// var c = fake.an(); -// 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(); -// field.ReturnType = SetupReturnType(returnTypeName); -// return field; -// } -// -// protected static IAttribute SetupBehaviorAttribute() -// { -// var attribute = fake.an(); -// attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName)); -// return attribute; -// } -// -// protected static IReturnType SetupReturnType(string typeName) -// { -// var returnType = fake.an(); -// 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 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(), "OtherField", ModifierEnum.None, DomRegion.Empty, testClass); -// testClass.Fields.Add(otherField); -// -// var behavesLikeReturnType = new ConstructedReturnType(SetupReturnType(MSpecBehavesTypeName), new List{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"); -// } -//} \ No newline at end of file +// 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.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 + { + static IProject testProject; + static IProject nonTestProject; + + static bool resultForTestProject; + static bool resultForNonTestProject; + + const string MSpecAssemblyName = "Machine.Specifications"; + + Establish ctx = () => { + testProject = fake.an(); + var mspecReference = MockRepository.GenerateStub(testProject); + mspecReference.setup(x => x.ShortName).Return(MSpecAssemblyName); + testProject.setup(x => x.Items).Return(new ImmutableModelCollection(new[] { mspecReference })); + + nonTestProject = fake.an(); + var otherReference = MockRepository.GenerateStub(nonTestProject); + mspecReference.setup(x => x.ShortName).Return("System.Configuration"); + nonTestProject.setup(x => x.Items).Return(new ImmutableModelCollection(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(); + } +} \ No newline at end of file diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestProjectTests.cs b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestProjectTests.cs new file mode 100644 index 0000000000..b327f5b882 --- /dev/null +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestProjectTests.cs @@ -0,0 +1,146 @@ +// 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 developwithpassion.specifications.extensions; +using developwithpassion.specifications.rhinomocks; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.UnitTesting; +using Machine.Specifications; +using Rhino.Mocks; + +namespace ICSharpCode.MachineSpecifications.Tests +{ + public abstract class MSpecTestProjectFieldsConcern : Observes + { + Establish ctx = () => { + }; + + protected const string MSpecItTypeName = "Machine.Specifications.It"; + protected const string MSpecBehavesTypeName = "Machine.Specifications.Behaves_like"; + protected const string MSpecBehaviorTypeName = "Machine.Specifications.BehaviorsAttribute"; + + protected static ITypeDefinition SetupClass(bool isAbstract, IList fields, IList attributes) + { + var c = fake.an(); + 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(); + field.setup(f => f.ReturnType).Return(SetupReturnType(returnTypeName)); + return field; + } + + protected static IAttribute SetupBehaviorAttribute() + { + var attribute = fake.an(); + attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName)); + return attribute; + } + + protected static IType SetupReturnType(string typeName) + { + var returnType = fake.an(); + returnType.Stub(x => x.FullName).Return(typeName); + return returnType; + } + } + + [Subject(typeof(MSpecTestProject))] + public class When_checking_if_is_a_test_class : MSpecTestProjectFieldsConcern + { + static ITypeDefinition classWithoutSpecificationMembers; + static ITypeDefinition classWithSpecificationMembers; + static ITypeDefinition classWithBehavior; + static ITypeDefinition 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.CallIsTestClass(classWithoutSpecificationMembers); + resultForClassWithSpecifications = sut.CallIsTestClass(classWithSpecificationMembers); + resultForClassWithBehavior = sut.CallIsTestClass(classWithBehavior); + resultForClassWithBehaviorAttribute = sut.CallIsTestClass(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 : MSpecTestProjectFieldsConcern + { + static ITypeDefinition behaviorClass; + static IField testSpecificationInBehavior; + + static ITypeDefinition testClass; + static IField testSpecification; + static IField otherField; + static IField behavesLikeField; + + static IEnumerable result; + + const string BehaviorClassName = "Test.Behavior"; + + Establish ctx = () => { + var itReturnType = SetupReturnType(MSpecItTypeName); + + testSpecificationInBehavior = fake.an(); + testSpecificationInBehavior.setup(x => x.ReturnType).Return(itReturnType); + var behaviorClassFields = new IField[] { testSpecificationInBehavior }; + behaviorClass = SetupClass(false, behaviorClassFields, new IAttribute[0]); + behaviorClass.Stub(b => b.GetFields()).Return(behaviorClassFields); + + testSpecification = fake.an(); + testSpecification.setup(f => f.FullName).Return("TestClass.testSpecificationInBehavior"); + testSpecification.setup(f => f.ReturnType).Return(itReturnType); + otherField = fake.an(); + otherField.setup(f => f.ReturnType).Return(fake.an()); + + var behavesLikeReturnType = SetupReturnType(MSpecBehavesTypeName); + + behavesLikeReturnType.setup(t => t.TypeArguments).Return(new List { behaviorClass }); + behavesLikeField = fake.an(); + behavesLikeField.setup(f => f.ReturnType).Return(behavesLikeReturnType); + + testClass = SetupClass(false, new IField[] { testSpecification, otherField, behavesLikeField }, new IAttribute[0]); + }; + + 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.FullName == "TestClass.testSpecificationInBehavior"); + } +} diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/TestableMSpecTestProject.cs b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/TestableMSpecTestProject.cs new file mode 100644 index 0000000000..5cdfc96fd0 --- /dev/null +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/TestableMSpecTestProject.cs @@ -0,0 +1,23 @@ +// 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.SharpDevelop.Project; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.MachineSpecifications.Tests +{ + public class TestableMSpecTestProject : MSpecTestProject + { + public TestableMSpecTestProject(ITestSolution parentSolution, IProject project) + : base(parentSolution, project) + { + } + + public bool CallIsTestClass(ITypeDefinition typeDefinition) + { + return base.IsTestClass(typeDefinition); + } + } +} diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs index c816c2c54e..49f6b30d3b 100644 --- a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs @@ -43,6 +43,10 @@ namespace ICSharpCode.MachineSpecifications this.Result = result.ResultType; } + public IMember Member { + get { return this.member; } + } + public IMember Resolve() { ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project); diff --git a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs index 9882a1d1a4..4d54434ecf 100644 --- a/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs +++ b/src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs @@ -83,12 +83,12 @@ namespace ICSharpCode.MachineSpecifications return member is IField && HasItReturnType(member as IField); } - public IEnumerable GetTestMembersFor(ITypeDefinition typeDefinition) + public IEnumerable GetTestMembersFor(ITypeDefinition typeDefinition) { return GetTestMembers(typeDefinition, typeDefinition.Fields); } - IEnumerable GetTestMembers(ITypeDefinition testClass, IEnumerable fields) + IEnumerable GetTestMembers(ITypeDefinition testClass, IEnumerable fields) { List result = fields.Where(HasItReturnType).Select(field => new MSpecTestMember(this, field)).ToList(); foreach (IField field in fields) {