4 changed files with 165 additions and 118 deletions
@ -0,0 +1,152 @@ |
|||||||
|
// 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 ICSharpCode.SharpDevelop.Dom; |
||||||
|
using ICSharpCode.SharpDevelop.Project; |
||||||
|
using ICSharpCode.UnitTesting; |
||||||
|
using NUnit.Framework; |
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using UnitTesting.Tests.Utils; |
||||||
|
|
||||||
|
namespace UnitTesting.Tests.Frameworks |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class NUnitTestFrameworkIsTestMemberTests |
||||||
|
{ |
||||||
|
NUnitTestFramework testFramework; |
||||||
|
|
||||||
|
void CreateTestFramework() |
||||||
|
{ |
||||||
|
testFramework = new NUnitTestFramework(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodHasNoAttributes_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodHasTestAttributeWithoutAttributePart_ReturnsTrue() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockAttribute testAttribute = new MockAttribute("Test"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsTrue(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodHasTestAttributeAttribute_ReturnsTrue() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockAttribute testAttribute = new MockAttribute("TestAttribute"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsTrue(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodHasFullyQualifiedNUnitTestAttribute_ReturnsTrue() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockAttribute testAttribute = new MockAttribute("NUnit.Framework.TestAttribute"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsTrue(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodIsNull_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
bool result = testFramework.IsTestMember(null); |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_ProjectContentLanguageHasNullNameComparer_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
mockClass.MockProjectContent.Language = new LanguageProperties(null); |
||||||
|
var mockMethod = new MockMethod(mockClass); |
||||||
|
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Even if the project is null the method should be
|
||||||
|
/// flagged as a TestMethod.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_ProjectIsNull_ReturnsTrue() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
var testAttribute = new MockAttribute("Test"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent; |
||||||
|
mockProjectContent.Project = null; |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsTrue(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodHasNullLanguage_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
mockClass.MockProjectContent.Language = null; |
||||||
|
var mockMethod = new MockMethod(mockClass); |
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_MethodHasParameters_ReturnsFalse() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
var testAttribute = new MockAttribute("Test"); |
||||||
|
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
||||||
|
var mockParameter = new MockParameter(); |
||||||
|
mockMethod.Parameters.Add(mockParameter); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(mockMethod); |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsTestMember_FieldHasOneAttribute_ReturnsFalseAndDoesNotThrowInvalidCastException() |
||||||
|
{ |
||||||
|
CreateTestFramework(); |
||||||
|
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
||||||
|
var field = new DefaultField(mockClass, "MyField"); |
||||||
|
var testAttribute = new MockAttribute("Test"); |
||||||
|
field.Attributes.Add(testAttribute); |
||||||
|
|
||||||
|
bool result = testFramework.IsTestMember(field); |
||||||
|
|
||||||
|
Assert.IsFalse(result); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,109 +0,0 @@ |
|||||||
// 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 ICSharpCode.SharpDevelop.Dom; |
|
||||||
using ICSharpCode.SharpDevelop.Project; |
|
||||||
using ICSharpCode.UnitTesting; |
|
||||||
using NUnit.Framework; |
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using UnitTesting.Tests.Utils; |
|
||||||
|
|
||||||
namespace UnitTesting.Tests.Frameworks |
|
||||||
{ |
|
||||||
[TestFixture] |
|
||||||
public class NUnitTestFrameworkIsTestMethodTests |
|
||||||
{ |
|
||||||
NUnitTestFramework testFramework; |
|
||||||
|
|
||||||
[SetUp] |
|
||||||
public void Init() |
|
||||||
{ |
|
||||||
testFramework = new NUnitTestFramework(); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsFalseWhenMethodHasNoAttributes() |
|
||||||
{ |
|
||||||
MockMethod mockMethod = MockMethod.CreateMockMethodWithoutAnyAttributes(); |
|
||||||
Assert.IsFalse(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeWithoutAttributePart() |
|
||||||
{ |
|
||||||
MockAttribute testAttribute = new MockAttribute("Test"); |
|
||||||
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
|
||||||
Assert.IsTrue(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeAttribute() |
|
||||||
{ |
|
||||||
MockAttribute testAttribute = new MockAttribute("TestAttribute"); |
|
||||||
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
|
||||||
Assert.IsTrue(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsTrueWhenMethodHasFullyQualifiedNUnitTestAttribute() |
|
||||||
{ |
|
||||||
MockAttribute testAttribute = new MockAttribute("NUnit.Framework.TestAttribute"); |
|
||||||
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
|
||||||
Assert.IsTrue(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsFalseWhenMethodIsNull() |
|
||||||
{ |
|
||||||
Assert.IsFalse(testFramework.IsTestMember(null)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsFalseWhenProjectContentLanguageHasNullNameComparer() |
|
||||||
{ |
|
||||||
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
|
||||||
mockClass.MockProjectContent.Language = new LanguageProperties(null); |
|
||||||
MockMethod mockMethod = new MockMethod(mockClass); |
|
||||||
mockMethod.Attributes.Add(new MockAttribute("Test")); |
|
||||||
|
|
||||||
Assert.IsFalse(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Even if the project is null the method should be
|
|
||||||
/// flagged as a TestMethod.
|
|
||||||
/// </summary>
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsTrueWhenProjectIsNull() |
|
||||||
{ |
|
||||||
MockAttribute testAttribute = new MockAttribute("Test"); |
|
||||||
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
|
||||||
MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent; |
|
||||||
mockProjectContent.Project = null; |
|
||||||
|
|
||||||
Assert.IsTrue(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsFalseWhenMethodHasNullLanguage() |
|
||||||
{ |
|
||||||
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes(); |
|
||||||
mockClass.MockProjectContent.Language = null; |
|
||||||
MockMethod mockMethod = new MockMethod(mockClass); |
|
||||||
|
|
||||||
Assert.IsFalse(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void IsTestMethodReturnsFalseWhenMethodHasHasParameters() |
|
||||||
{ |
|
||||||
MockAttribute testAttribute = new MockAttribute("Test"); |
|
||||||
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute); |
|
||||||
MockParameter mockParameter = new MockParameter(); |
|
||||||
mockMethod.Parameters.Add(mockParameter); |
|
||||||
|
|
||||||
Assert.IsFalse(testFramework.IsTestMember(mockMethod)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue