|
| 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 | +} |
0 commit comments