You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
5.4 KiB
193 lines
5.4 KiB
// 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 ICSharpCode.MSTest; |
|
using ICSharpCode.SharpDevelop.Dom; |
|
using ICSharpCode.SharpDevelop.Project; |
|
using ICSharpCode.UnitTesting; |
|
using NUnit.Framework; |
|
using Rhino.Mocks; |
|
|
|
namespace MSTest.SharpDevelop.Tests |
|
{ |
|
[TestFixture] |
|
public class MSTestFrameworkTests |
|
{ |
|
MSTestFramework testFramework; |
|
IProject fakeProject; |
|
|
|
[SetUp] |
|
public void Init() |
|
{ |
|
testFramework = new MSTestFramework(); |
|
|
|
fakeProject = MockRepository.GenerateStub<IProject>(); |
|
fakeProject.Stub(p => p.SyncRoot).Return(fakeProject); |
|
} |
|
|
|
void AddReferencesToProject(params string[] referenceNames) |
|
{ |
|
List<ProjectItem> projectItems = referenceNames |
|
.Select(name => new ReferenceProjectItem(fakeProject, name) as ProjectItem) |
|
.ToList(); |
|
|
|
AddItemsToProject(projectItems); |
|
} |
|
|
|
void AddItemsToProject(List<ProjectItem> projectItems) |
|
{ |
|
fakeProject |
|
.Stub(project => project.Items) |
|
.Return(new SimpleModelCollection<ProjectItem>(projectItems)); |
|
} |
|
|
|
void AddFileAndReferenceToProject(string fileName, string reference) |
|
{ |
|
var projectItems = new List<ProjectItem>(); |
|
projectItems.Add(new FileProjectItem(fakeProject, ItemType.Compile, fileName)); |
|
projectItems.Add(new ReferenceProjectItem(fakeProject, reference)); |
|
|
|
AddItemsToProject(projectItems); |
|
} |
|
|
|
void NoItemsInProject() |
|
{ |
|
AddReferencesToProject(); |
|
} |
|
|
|
// IClass CreateClassWithoutAnyAttributes() |
|
// { |
|
// IClass fakeClass = MockRepository.GenerateStub<IClass>(); |
|
// AddAttributesToClass(fakeClass, new List<IAttribute>()); |
|
// return fakeClass; |
|
// } |
|
// |
|
// void AddAttributesToClass(IClass fakeClass, List<IAttribute> attributes) |
|
// { |
|
// fakeClass.Stub(c => c.Attributes).Return(attributes); |
|
// } |
|
// |
|
// IClass CreateClassWithAttributes(params string[] attributeNames) |
|
// { |
|
// IClass fakeClass = MockRepository.GenerateStub<IClass>(); |
|
// |
|
// List<IAttribute> attributes = CreateAttributes(attributeNames); |
|
// |
|
// AddAttributesToClass(fakeClass, attributes); |
|
// |
|
// return fakeClass; |
|
// } |
|
// |
|
// List<IAttribute> CreateAttributes(params string[] attributeNames) |
|
// { |
|
// return attributeNames.Select(name => CreateAttribute(name)).ToList(); |
|
// } |
|
// |
|
// IAttribute CreateAttribute(string name) |
|
// { |
|
// IReturnType returnType = MockRepository.GenerateStub<IReturnType>(); |
|
// returnType.Stub(t => t.FullyQualifiedName).Return(name); |
|
// |
|
// IAttribute attribute = MockRepository.GenerateStub<IAttribute>(); |
|
// attribute.Stub(a => a.AttributeType).Return(returnType); |
|
// return attribute; |
|
// } |
|
// |
|
// void MakeClassAbstract(IClass fakeClass) |
|
// { |
|
// fakeClass.Stub(c => c.IsAbstract).Return(true); |
|
// } |
|
// |
|
// IMethod CreateMethodWithoutAnyAttributes() |
|
// { |
|
// IMethod fakeMethod = MockRepository.GenerateStub<IMethod>(); |
|
// AddAttributesToMethod(fakeMethod, new List<IAttribute>()); |
|
// return fakeMethod; |
|
// } |
|
// |
|
// IMethod CreateMethodWithAttributes(params string[] attributeNames) |
|
// { |
|
// IMethod fakeMethod = MockRepository.GenerateStub<IMethod>(); |
|
// List<IAttribute> attributes = CreateAttributes(attributeNames); |
|
// AddAttributesToMethod(fakeMethod, attributes); |
|
// return fakeMethod; |
|
// } |
|
// |
|
// void AddAttributesToMethod(IMethod method, List<IAttribute> attributes) |
|
// { |
|
// method.Stub(m => m.Attributes).Return(attributes); |
|
// } |
|
// |
|
// List<TestMember> GetTestMembersFor(IClass fakeClass) |
|
// { |
|
// return testFramework.GetTestMembersFor(fakeClass).ToList(); |
|
// } |
|
// |
|
// void AddMethodsToClass(IClass fakeClass, List<IMethod> methods) |
|
// { |
|
// fakeClass.Stub(c => c.Methods).Return(methods); |
|
// } |
|
|
|
[Test] |
|
public void IsTestProject_NullProject_ReturnsFalse() |
|
{ |
|
bool result = testFramework.IsTestProject(null); |
|
|
|
Assert.IsFalse(result); |
|
} |
|
|
|
[Test] |
|
public void IsTestProject_ProjectWithMSTestAssemblyReference_ReturnsTrue() |
|
{ |
|
AddReferencesToProject("System", "Microsoft.VisualStudio.QualityTools.UnitTestFramework"); |
|
|
|
bool result = testFramework.IsTestProject(fakeProject); |
|
|
|
Assert.IsTrue(result); |
|
} |
|
|
|
[Test] |
|
public void IsTestProject_ProjectWithoutMSTestAssemblyReference_ReturnsFalse() |
|
{ |
|
NoItemsInProject(); |
|
bool result = testFramework.IsTestProject(fakeProject); |
|
|
|
Assert.IsFalse(result); |
|
} |
|
|
|
[Test] |
|
public void IsTestProject_ProjectWithMSTestAssemblyReferenceInUpperCase_ReturnsTrue() |
|
{ |
|
AddReferencesToProject("MICROSOFT.VISUALSTUDIO.QUALITYTOOLS.UNITTESTFRAMEWORK"); |
|
|
|
bool result = testFramework.IsTestProject(fakeProject); |
|
|
|
Assert.IsTrue(result); |
|
} |
|
|
|
[Test] |
|
public void IsTestProject_ProjectWithMSTestAssemblyReferenceAndFileProjectItem_ReturnsTrue() |
|
{ |
|
AddFileAndReferenceToProject("test.cs", "Microsoft.VisualStudio.QualityTools.UnitTestFramework"); |
|
|
|
bool result = testFramework.IsTestProject(fakeProject); |
|
|
|
Assert.IsTrue(result); |
|
} |
|
|
|
[Test] |
|
public void IsTestProject_ProjectWithMSTestAssemblyReferenceUsingFullName_ReturnsTrue() |
|
{ |
|
AddReferencesToProject("Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=2.5.3.9345, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"); |
|
|
|
bool result = testFramework.IsTestProject(fakeProject); |
|
|
|
Assert.IsTrue(result); |
|
} |
|
} |
|
}
|
|
|