This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
/
NUnitConsoleExeSelectedTestFixture.cs
155 lines (133 loc) · 5.99 KB
/
NUnitConsoleExeSelectedTestFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
using ICSharpCode.UnitTesting;
using Rhino.Mocks;
using UnitTesting.Tests.Utils;
using ICSharpCode.SharpDevelop;
namespace UnitTesting.Tests.NUnit
{
/// <summary>
/// If the project explicitly targets 32 bit (x86) architecture then nunit-console-x86.exe should be
/// used. Otherwise the normal nunit-console.exe is used.
/// </summary>
[TestFixture]
public class NUnitConsoleExeSelectedTestFixture : SDTestFixtureBase
{
MockCSharpProject project;
NUnitTestProject testProject;
string oldRootPath;
public override void FixtureSetUp()
{
base.FixtureSetUp();
SD.Services.AddStrictMockService<IProjectService>();
SD.ProjectService.Stub(p => p.TargetFrameworks).Return(new[] { TargetFramework.Net20, TargetFramework.Net30, TargetFramework.Net35, TargetFramework.Net35Client, TargetFramework.Net40Client, TargetFramework.Net40 });
}
[TestFixtureSetUp]
public void SetUpFixture()
{
oldRootPath = FileUtility.ApplicationRootPath;
FileUtility.ApplicationRootPath = @"D:\SharpDevelop";
}
[TestFixtureTearDown]
public void TearDownFixture()
{
FileUtility.ApplicationRootPath = oldRootPath;
}
[SetUp]
public void SetUp()
{
project = new MockCSharpProject();
testProject = new NUnitTestProject(project);
}
[Test]
public void NothingSpecified()
{
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
public void TargetCpuAnyCPUDotnet2()
{
project.ActiveConfiguration = new ConfigurationAndPlatform("Debug", "AnyCPU");
project.SetProperty("PlatformTarget", "AnyCPU");
project.SetProperty("TargetFrameworkVersion", "v3.5");
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
// We use 32-bit NUnit to test AnyCPU projects because the debugger doesn't support 64-bit
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2-x86.exe", app.FileName);
}
[Test]
public void TargetCpuAnyCPUDotnet45()
{
project.ActiveConfiguration = new ConfigurationAndPlatform("Debug", "AnyCPU");
project.SetProperty("PlatformTarget", "AnyCPU");
project.SetProperty("TargetFrameworkVersion", "v4.5");
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
// We use 32-bit NUnit to test AnyCPU projects because the debugger doesn't support 64-bit
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
public void TargetCpuX64Dotnet2()
{
project.ActiveConfiguration = new ConfigurationAndPlatform("Debug", "AnyCPU");
project.SetProperty("PlatformTarget", "x64");
project.SetProperty("TargetFrameworkVersion", "v3.5");
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2.exe", app.FileName);
}
[Test]
public void TargetCpuX64Dotnet45()
{
project.ActiveConfiguration = new ConfigurationAndPlatform("Debug", "AnyCPU");
project.SetProperty("PlatformTarget", "x64");
project.SetProperty("TargetFrameworkVersion", "v4.5");
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
}
[Test]
public void NUnitConsole32BitUsedWhenTargetCpuIs32BitDotnet2()
{
project.ActiveConfiguration = new ConfigurationAndPlatform("Debug", "AnyCPU");
project.SetProperty("PlatformTarget", "x86");
project.SetProperty("TargetFrameworkVersion", "v3.5");
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2-x86.exe", app.FileName);
}
[Test]
public void NUnitConsole32BitUsedWhenTargetCpuIs32Bit()
{
project.ActiveConfiguration = new ConfigurationAndPlatform("Debug", "AnyCPU");
project.SetProperty("PlatformTarget", "x86");
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
public void NotMSBuildBasedProject()
{
ProjectLoadInformation info = new ProjectLoadInformation(MockSolution.Create(), FileName.Create(@"C:\Projects\Test.proj"), "Test");
MissingProject project = new MissingProject(info);
ITestProject testProject = new NUnitTestProject(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testProject });
Assert.AreEqual(project.GetType().BaseType, typeof(AbstractProject), "MissingProject should be derived from AbstractProject.");
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
}
}
}