Browse Source

Update MSpec addin unit tests.

Excluding class filter unit tests.
pull/32/merge
Matt Ward 13 years ago
parent
commit
dd3e59a964
  1. 6
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj
  2. 235
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs
  3. 146
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestProjectTests.cs
  4. 23
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/TestableMSpecTestProject.cs
  5. 4
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs
  6. 4
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs

6
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj

@ -73,8 +73,10 @@
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Src\ClassFilterBuilderTests.cs" /> <Compile Include="Src\ClassFilterBuilderTests.cs" />
<Compile Include="Src\MSpecTestProjectTests.cs" />
<Compile Include="Src\MSpecTestFrameworkTests.cs" /> <Compile Include="Src\MSpecTestFrameworkTests.cs" />
<Compile Include="Src\MSpecUnitTestMonitorTests.cs" /> <Compile Include="Src\MSpecUnitTestMonitorTests.cs" />
<Compile Include="Src\TestableMSpecTestProject.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Data\MSpecUnitTestMonitorTestsSampleData.xml"> <Content Include="Data\MSpecUnitTestMonitorTestsSampleData.xml">
@ -85,6 +87,10 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> <ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> <Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name> <Name>ICSharpCode.SharpDevelop</Name>

235
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) // 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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//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 ImmutableModelCollection<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 ImmutableModelCollection<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>
// {
// 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");
// }
//}

146
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<TestableMSpecTestProject>
{
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<IField> fields, IList<IAttribute> attributes)
{
var c = fake.an<ITypeDefinition>();
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.setup(f => f.ReturnType).Return(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 IType SetupReturnType(string typeName)
{
var returnType = fake.an<IType>();
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<MSpecTestMember> result;
const string BehaviorClassName = "Test.Behavior";
Establish ctx = () => {
var itReturnType = SetupReturnType(MSpecItTypeName);
testSpecificationInBehavior = fake.an<IField>();
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<IField>();
testSpecification.setup(f => f.FullName).Return("TestClass.testSpecificationInBehavior");
testSpecification.setup(f => f.ReturnType).Return(itReturnType);
otherField = fake.an<IField>();
otherField.setup(f => f.ReturnType).Return(fake.an<IType>());
var behavesLikeReturnType = SetupReturnType(MSpecBehavesTypeName);
behavesLikeReturnType.setup(t => t.TypeArguments).Return(new List<IType> { behaviorClass });
behavesLikeField = fake.an<IField>();
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");
}
}

23
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);
}
}
}

4
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs

@ -43,6 +43,10 @@ namespace ICSharpCode.MachineSpecifications
this.Result = result.ResultType; this.Result = result.ResultType;
} }
public IMember Member {
get { return this.member; }
}
public IMember Resolve() public IMember Resolve()
{ {
ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project); ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project);

4
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs

@ -83,12 +83,12 @@ namespace ICSharpCode.MachineSpecifications
return member is IField && HasItReturnType(member as IField); return member is IField && HasItReturnType(member as IField);
} }
public IEnumerable<ITest> GetTestMembersFor(ITypeDefinition typeDefinition) public IEnumerable<MSpecTestMember> GetTestMembersFor(ITypeDefinition typeDefinition)
{ {
return GetTestMembers(typeDefinition, typeDefinition.Fields); return GetTestMembers(typeDefinition, typeDefinition.Fields);
} }
IEnumerable<ITest> GetTestMembers(ITypeDefinition testClass, IEnumerable<IField> fields) IEnumerable<MSpecTestMember> GetTestMembers(ITypeDefinition testClass, IEnumerable<IField> fields)
{ {
List<MSpecTestMember> result = fields.Where(HasItReturnType).Select(field => new MSpecTestMember(this, field)).ToList(); List<MSpecTestMember> result = fields.Where(HasItReturnType).Select(field => new MSpecTestMember(this, field)).ToList();
foreach (IField field in fields) { foreach (IField field in fields) {

Loading…
Cancel
Save