public List<TempProject> GetActiveProjects()
{
foreach (Project project in _applicationObject.DTE.Solution.Projects)
{
if (project.FullName.EndsWith(".csproj"))
projects.Add(new TempProject(project));
}
return projects;
}
Asked
Active
Viewed 140 times
-3

Mark Seemann
- 225,310
- 48
- 427
- 736
-
5What are your specific problems with writing a test for this? – Rhys Bevilaqua Oct 29 '13 at 06:21
2 Answers
1
- Open Visual Studio
- Create a new library project (let's assume C#)
- Add appropriate references to a unit testing framework (from the tags, it would seem that you'd want NUnit - the easiest way to get it is to pull it from NuGet).
- Add a class to hold the unit tests for the code in the OP.
- Adorn the test class with the
[TestFixture]
attribute. - Add a new public method that returns
void
and takes no parameters. This will be your test method. - Adorn the test method with the
[Test]
attribute. - Write the unit test in the body of the test method.
- Repeat from 4. until you have enough unit tests.

Mark Seemann
- 225,310
- 48
- 427
- 736
0
- Provide mocked instance of
_applicationObject
to class you are testing. This will allow you to setup different projects set (google for dependency inversion, mocking, Moq). - Write test which verifies that empty list is returned when there is no projects in solution.
- Write test which verifies that empty list is returned if there is no C# projects in solution.
- Write test which verifies that all C# projects are added to result.
BTW consider to depend on solution object instead of application object, if you only need to get data from solution. That will allow you to easily mock projects set and avoid train wreck when getting projects:
foreach (Project project in _solution.Projects)

Sergey Berezovskiy
- 232,247
- 41
- 429
- 459