Browse Source

Added reference to Rhino.Mocks in test project.

Missing changes in unit tests.
pull/23/head
Tomasz Tretkowski 15 years ago
parent
commit
4ce6985a7c
  1. 1
      packages/repositories.config
  2. 4
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj
  3. 60
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/ClassFilterBuilder.cs
  4. 64
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs
  5. 1
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.csproj
  6. 35
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/ClassFilterBuilder.cs
  7. 18
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecApplication.cs

1
packages/repositories.config

@ -2,4 +2,5 @@
<repositories> <repositories>
<repository path="C:\Users\trecio\Documents\SharpDevelop Projects\MachineSpecifications\MachineSpecifications\packages.config" /> <repository path="C:\Users\trecio\Documents\SharpDevelop Projects\MachineSpecifications\MachineSpecifications\packages.config" />
<repository path="C:\Users\trecio\Documents\SharpDevelop Projects\MachineSpecifications.Tests\packages.config" /> <repository path="C:\Users\trecio\Documents\SharpDevelop Projects\MachineSpecifications.Tests\packages.config" />
<repository path="..\src\AddIns\Analysis\MachineSpecifications\MachineSpecifications.Tests\packages.config" />
</repositories> </repositories>

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

@ -44,6 +44,9 @@
<Reference Include="Machine.Specifications"> <Reference Include="Machine.Specifications">
<HintPath>..\..\..\..\..\packages\Machine.Specifications.0.4.13.0\lib\Machine.Specifications.dll</HintPath> <HintPath>..\..\..\..\..\packages\Machine.Specifications.0.4.13.0\lib\Machine.Specifications.dll</HintPath>
</Reference> </Reference>
<Reference Include="Rhino.Mocks">
<HintPath>..\..\..\..\..\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -55,6 +58,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Src\ClassFilterBuilder.cs" />
<Compile Include="Src\MSpecTestFrameworkTests.cs" /> <Compile Include="Src\MSpecTestFrameworkTests.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />

60
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/ClassFilterBuilder.cs

@ -0,0 +1,60 @@
/*
* 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 IClass classAddedExplicitly, classInNamespace, classOutsideNamespace;
static SelectedTests selectedTests;
static IProjectContent projectContent;
static IList<string> result;
Establish ctx = () => {
classAddedExplicitly = fake.an<IClass>();
classAddedExplicitly.setup(x => x.Namespace).Return("");
classAddedExplicitly.setup(x => x.FullyQualifiedName).Return("ClassAddedExplicitly");
classInNamespace = fake.an<IClass>();
classInNamespace.setup(x => x.Namespace).Return("Namespace.OtherNamespace");
classInNamespace.setup(x => x.FullyQualifiedName).Return("Namespace.OtherNamespace.ClassInNamespace");
classOutsideNamespace = fake.an<IClass>();
classOutsideNamespace.setup(x => x.Namespace).Return("Namespace2");
classOutsideNamespace.setup(x => x.FullyQualifiedName).Return("Namespace2.ClassOutsideNamespac");
var project = fake.an<IProject>();
projectContent = fake.an<IProjectContent>();
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_fully_qualified_name_of_selected_test_class = () =>
result.ShouldContain(classAddedExplicitly.FullyQualifiedName);
It should_add_class_included_in_selected_namespace = () =>
result.ShouldContain(classInNamespace.FullyQualifiedName);
It should_not_include_class_not_included_in_namespace = () =>
result.ShouldNotContain(classOutsideNamespace.FullyQualifiedName);
}
}

64
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/MSpecTestFrameworkTests.cs

@ -8,11 +8,16 @@
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using developwithpassion.specifications.extensions;
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;
namespace ICSharpCode.MachineSpecifications.Tests namespace ICSharpCode.MachineSpecifications.Tests
{ {
@ -25,7 +30,19 @@ namespace ICSharpCode.MachineSpecifications.Tests
static bool resultForTestProject; static bool resultForTestProject;
static bool resultForNonTestProject; static bool resultForNonTestProject;
Establish ctx; 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 = () => { Because of = () => {
resultForTestProject = sut.IsTestProject(testProject); resultForTestProject = sut.IsTestProject(testProject);
@ -42,20 +59,58 @@ namespace ICSharpCode.MachineSpecifications.Tests
[Subject(typeof(MSpecTestFramework))] [Subject(typeof(MSpecTestFramework))]
public class When_checking_if_is_a_test_class : Observes<MSpecTestFramework> public class When_checking_if_is_a_test_class : Observes<MSpecTestFramework>
{ {
static IClass classWithoutSpecificationMembers; const string MSpecItTypeName = "Machine.Specifications.It";
const string MSpecBehavesTypeName = "Machine.Specifications.Behaves_like";
const string MSpecBehaviorTypeName = "Machine.Specifications.BehaviorsAttribute";
static IClass classWithoutSpecificationMembers;
static IClass classWithSpecificationMembers; static IClass classWithSpecificationMembers;
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 resultForClassWithoutSpecifications; static bool resultForClassWithoutSpecifications;
Establish ctx; 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()});
};
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;
}
static IField SetupField(string returnTypeName) {
var field = fake.an<IField>();
field.ReturnType = SetupReturnType(returnTypeName);
return field;
}
static IAttribute SetupBehaviorAttribute() {
var attribute = fake.an<IAttribute>();
attribute.setup(x => x.AttributeType).Return(SetupReturnType(MSpecBehaviorTypeName));
return attribute;
}
static IReturnType SetupReturnType(string typeName) {
var returnType = fake.an<IReturnType>();
returnType.Stub(x => x.FullyQualifiedName).Return(typeName);
return returnType;
}
Because of = () => Because of = () =>
{ {
resultForClassWithoutSpecifications = sut.IsTestClass(classWithoutSpecificationMembers); resultForClassWithoutSpecifications = sut.IsTestClass(classWithoutSpecificationMembers);
resultForClassWithSpecifications = sut.IsTestClass(classWithSpecificationMembers); resultForClassWithSpecifications = sut.IsTestClass(classWithSpecificationMembers);
resultForClassWithBehavior = sut.IsTestClass(classWithBehavior);
resultForClassWithBehaviorAttribute = sut.IsTestClass(classWithSpecificationMembersAndBehaviorAttribute); resultForClassWithBehaviorAttribute = sut.IsTestClass(classWithSpecificationMembersAndBehaviorAttribute);
}; };
@ -65,6 +120,9 @@ namespace ICSharpCode.MachineSpecifications.Tests
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 = () =>
resultForClassWithBehavior.ShouldBeTrue();
It should_return_false_for_class_with_behavior_attribute = () => It should_return_false_for_class_with_behavior_attribute = () =>
resultForClassWithBehaviorAttribute.ShouldBeFalse(); resultForClassWithBehaviorAttribute.ShouldBeFalse();
} }

1
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.csproj

@ -58,6 +58,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="src\ClassFilterBuilder.cs" />
<Compile Include="src\MSpecApplication.cs" /> <Compile Include="src\MSpecApplication.cs" />
<Compile Include="src\MSpecTestDebugger.cs" /> <Compile Include="src\MSpecTestDebugger.cs" />
<Compile Include="src\MSpecTestFramework.cs" /> <Compile Include="src\MSpecTestFramework.cs" />

35
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/ClassFilterBuilder.cs

@ -0,0 +1,35 @@
/*
* Created by SharpDevelop.
* User: trecio
* Date: 2011-09-23
* Time: 19:40
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
namespace ICSharpCode.MachineSpecifications
{
/// <summary>
/// Creates class list filter for tests which should be run.
/// </summary>
public class ClassFilterBuilder
{
public IList<string> BuildFilterFor(SelectedTests tests, IProjectContent @using) {
var projectContent = @using;
var filter = new List<string>();
if (tests.Class != null)
filter.Add(tests.Class.FullyQualifiedName);
if (tests.NamespaceFilter != null)
foreach (var projectClass in projectContent.Classes)
if (projectClass.FullyQualifiedName.StartsWith(tests.NamespaceFilter + "."))
filter.Add(projectClass.FullyQualifiedName);
return filter;
}
}
}

18
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecApplication.cs

@ -73,25 +73,17 @@ namespace ICSharpCode.MachineSpecifications
string CreateFilterFile() string CreateFilterFile()
{ {
var filter = new List<IClass>(); var classFilterBuilder = new ClassFilterBuilder();
if (tests.Class != null) var projectContent = ParserService.GetProjectContent(project);
filter.Add(tests.Class); var filter = classFilterBuilder.BuildFilterFor(tests, @using: projectContent);
if (tests.NamespaceFilter != null)
{
var projectContent = ParserService.GetProjectContent(project);
foreach (var projectClass in projectContent.Classes)
if (projectClass.FullyQualifiedName.StartsWith(tests.NamespaceFilter + "."))
filter.Add(projectClass);
}
string path = null; string path = null;
if (filter.Count > 0) { if (filter.Count > 0) {
path = Path.GetTempFileName(); path = Path.GetTempFileName();
using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write)) using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write))
using (var writer = new StreamWriter(stream)) using (var writer = new StreamWriter(stream))
foreach (var testClass in filter) { foreach (var testClassName in filter) {
writer.WriteLine(testClass.FullyQualifiedName); writer.WriteLine(testClassName);
} }
} }
return path; return path;

Loading…
Cancel
Save