Merge lp:~cvetomir-todorov/nunitv2/bug524474 into lp:nunitv2

Proposed by Cvetomir Todorov
Status: Merged
Approved by: Charlie Poole
Approved revision: 3202
Merge reported by: Charlie Poole
Merged at revision: not available
Proposed branch: lp:~cvetomir-todorov/nunitv2/bug524474
Merge into: lp:nunitv2
Diff against target: 110 lines (+56/-3)
4 files modified
src/ConsoleRunner/tests/nunit-console.tests.build (+1/-0)
src/GuiComponents/UiKit/TestTree.cs (+7/-3)
src/GuiComponents/tests/TestTreeTests.cs (+47/-0)
src/GuiComponents/tests/nunit.uikit.tests.csproj (+1/-0)
To merge this branch: bzr merge lp:~cvetomir-todorov/nunitv2/bug524474
Reviewer Review Type Date Requested Status
Charlie Poole Approve
Review via email: mp+34638@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Charlie Poole (charlie.poole) wrote :

The reflection is ugly of course, but it seems like a good way to get a test without having to do some
major redesign right now. We should do it more cleanly in 3.0 but right now this seems like a smart use of time.

Only one issue... this line...
              string[] expectedSelectedCategories = new[] { "Foo", "MockCategory" };
...requires C# 3.0 to compile.

If the entire test only works under C# 3.0, then it should be inside an #if CS_3_0.

In this case, we want the test to work under C# 2.0, so the initialization needs to
use the older syntax. However, it's so small, I'll just do it when I do the merge.

Approved! Thanks.

Charlie

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Merged with two additional changes:

1. A var declaration in the test
2. The new test file was added to nunit.uikit.tests.build

Charlie

Revision history for this message
Charlie Poole (charlie.poole) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ConsoleRunner/tests/nunit-console.tests.build'
2--- src/ConsoleRunner/tests/nunit-console.tests.build 2009-04-22 01:21:06 +0000
3+++ src/ConsoleRunner/tests/nunit-console.tests.build 2010-09-05 16:15:55 +0000
4@@ -24,6 +24,7 @@
5 <include name="${current.test.dir}/nunit.framework.tests.dll"/>
6 <include name="${current.test.dir}/test-assembly.dll"/>
7 <include name="${current.test.dir}/mock-assembly.dll"/>
8+ <include name="${current.test.dir}/nonamespace-assembly.dll"/>
9 </references>
10 </csc>
11 </target>
12
13=== modified file 'src/GuiComponents/UiKit/TestTree.cs'
14--- src/GuiComponents/UiKit/TestTree.cs 2009-04-18 02:24:12 +0000
15+++ src/GuiComponents/UiKit/TestTree.cs 2010-09-05 16:15:55 +0000
16@@ -6,6 +6,7 @@
17
18 using System;
19 using System.Collections;
20+using System.Collections.Generic;
21 using System.ComponentModel;
22 using System.Drawing;
23 using System.Data;
24@@ -26,7 +27,7 @@
25 // Contains all available categories, whether
26 // selected or not. Unselected members of this
27 // list are displayed in selectedList
28- private IList availableCategories;
29+ private IList availableCategories = new List<string>();
30
31 // Our test loader
32 private TestLoader loader;
33@@ -234,8 +235,11 @@
34 foreach( string category in categories )
35 {
36 if ( availableCategories.Contains( category ) )
37- {
38- selectedList.Items.Add( category );
39+ {
40+ if (!selectedList.Items.Contains(category))
41+ {
42+ selectedList.Items.Add(category);
43+ }
44 availableList.Items.Remove( category );
45
46 this.excludeCheckbox.Checked = exclude;
47
48=== added file 'src/GuiComponents/tests/TestTreeTests.cs'
49--- src/GuiComponents/tests/TestTreeTests.cs 1970-01-01 00:00:00 +0000
50+++ src/GuiComponents/tests/TestTreeTests.cs 2010-09-05 16:15:55 +0000
51@@ -0,0 +1,47 @@
52+// ****************************************************************
53+// Copyright 2010, Charlie Poole
54+// This is free software licensed under the NUnit license. You may
55+// obtain a copy of the license at http://nunit.org
56+// ****************************************************************
57+
58+using System;
59+using System.Collections;
60+using System.Reflection;
61+using NUnit.Framework;
62+
63+namespace NUnit.UiKit.Tests
64+{
65+ [TestFixture]
66+ public class TestTreeTests
67+ {
68+ [Test]
69+ public void SameCategoryShouldNotBeSelectedMoreThanOnce()
70+ {
71+ // arrange
72+ var target = new TestTree();
73+
74+ // we need to populate the available categories
75+ // this can be done via TestLoader but this way the test is isolated
76+ FieldInfo fieldInfo = typeof (TestTree).GetField("availableCategories", BindingFlags.NonPublic | BindingFlags.Instance);
77+ Assert.IsNotNull(fieldInfo, "The field 'availableCategories' should be found.");
78+ object fieldValue = fieldInfo.GetValue(target);
79+ Assert.IsNotNull(fieldValue, "The value of 'availableCategories' should not be null.");
80+ IList availableCategories = fieldValue as IList;
81+ Assert.IsNotNull(availableCategories, "'availableCategories' field should be of type IList.");
82+
83+ string[] expectedSelectedCategories = new[] { "Foo", "MockCategory" };
84+ foreach (string availableCategory in expectedSelectedCategories)
85+ {
86+ availableCategories.Add(availableCategory);
87+ }
88+
89+ // act
90+ target.SelectCategories(expectedSelectedCategories, true);
91+ target.SelectCategories(expectedSelectedCategories, true);
92+ string[] actualSelectedCategories = target.SelectedCategories;
93+
94+ // assert
95+ CollectionAssert.AreEquivalent(expectedSelectedCategories, actualSelectedCategories);
96+ }
97+ }
98+}
99
100=== modified file 'src/GuiComponents/tests/nunit.uikit.tests.csproj'
101--- src/GuiComponents/tests/nunit.uikit.tests.csproj 2010-08-06 18:37:35 +0000
102+++ src/GuiComponents/tests/nunit.uikit.tests.csproj 2010-09-05 16:15:55 +0000
103@@ -149,6 +149,7 @@
104 <Compile Include="StatusBarTests.cs" />
105 <Compile Include="TestSuiteTreeNodeTests.cs" />
106 <Compile Include="TestSuiteTreeViewFixture.cs" />
107+ <Compile Include="TestTreeTests.cs" />
108 <Compile Include="VisualStateTests.cs" />
109 </ItemGroup>
110 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

Subscribers

People subscribed via source and target branches

to status/vote changes: