Skip to content

Commit 5730a81

Browse files
committed
Added tests to cover object/array
1 parent 7371e3e commit 5730a81

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Copyright 2018 Rustici Software
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
namespace TinCanTests
17+
{
18+
using System.Collections.Generic;
19+
using NUnit.Framework;
20+
using TinCan;
21+
using TinCan.Json;
22+
23+
[TestFixture]
24+
class ContextActivitiesTest
25+
{
26+
private Activity sampleActivity1 = new Activity
27+
{
28+
id = "http://0.bar/"
29+
};
30+
31+
private Activity sampleActivity2 = new Activity
32+
{
33+
id = "http://1.bar/"
34+
};
35+
36+
[Test]
37+
public void ConstructorWithObject()
38+
{
39+
var json = "{" +
40+
"\"parent\": " + sampleActivity1.ToJSON() + "," +
41+
"\"grouping\": " + sampleActivity1.ToJSON() + "," +
42+
"\"category\": " + sampleActivity1.ToJSON() + "," +
43+
"\"other\": " + sampleActivity1.ToJSON() +
44+
"}";
45+
46+
ContextActivities contextActivities = new ContextActivities(new StringOfJSON(json));
47+
48+
ValidateActivityList(contextActivities.parent, 1);
49+
ValidateActivityList(contextActivities.grouping, 1);
50+
ValidateActivityList(contextActivities.category, 1);
51+
ValidateActivityList(contextActivities.other, 1);
52+
}
53+
54+
[Test]
55+
public void ConstructorWithArray()
56+
{
57+
var json = "{" +
58+
"\"parent\": [" + sampleActivity1.ToJSON() + ", " + sampleActivity2.ToJSON() + "]," +
59+
"\"grouping\": [" + sampleActivity1.ToJSON() + ", " + sampleActivity2.ToJSON() + "]," +
60+
"\"category\": [" + sampleActivity1.ToJSON() + ", " + sampleActivity2.ToJSON() + "]," +
61+
"\"other\": [" + sampleActivity1.ToJSON() + ", " + sampleActivity2.ToJSON() + "]" +
62+
"}";
63+
64+
ContextActivities contextActivities = new ContextActivities(new StringOfJSON(json));
65+
66+
ValidateActivityList(contextActivities.parent, 2);
67+
ValidateActivityList(contextActivities.grouping, 2);
68+
ValidateActivityList(contextActivities.category, 2);
69+
ValidateActivityList(contextActivities.other, 2);
70+
}
71+
72+
private void ValidateActivityList(List<Activity> list, int expectedLength)
73+
{
74+
Assert.IsTrue(list.Count == expectedLength);
75+
76+
for (int i = 0; i < list.Count; i++)
77+
{
78+
Assert.IsTrue(list[i].id == "http://" + i + ".bar/");
79+
}
80+
}
81+
}
82+
}

TinCanTests/TinCanTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<ItemGroup>
8989
<Compile Include="ActivityTest.cs" />
9090
<Compile Include="AgentTest.cs" />
91+
<Compile Include="ContextActivitiesTest.cs" />
9192
<Compile Include="ContextTest.cs" />
9293
<Compile Include="ResultTest.cs" />
9394
<Compile Include="Support.cs" />

0 commit comments

Comments
 (0)