|
| 1 | +/* |
| 2 | + Copyright 2014 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; |
| 19 | + using System.Collections.Generic; |
| 20 | + using NUnit.Framework; |
| 21 | + using Newtonsoft.Json.Linq; |
| 22 | + using TinCan; |
| 23 | + using TinCan.Json; |
| 24 | + |
| 25 | + [TestFixture] |
| 26 | + class StatementTest |
| 27 | + { |
| 28 | + Agent agent; |
| 29 | + Verb verb; |
| 30 | + Activity activity; |
| 31 | + Activity parent; |
| 32 | + Context context; |
| 33 | + Result result; |
| 34 | + Score score; |
| 35 | + StatementRef statementRef; |
| 36 | + SubStatement subStatement; |
| 37 | + |
| 38 | + [SetUp] |
| 39 | + public void Init() |
| 40 | + { |
| 41 | + Console.WriteLine("Running " + TestContext.CurrentContext.Test.FullName); |
| 42 | + |
| 43 | + agent = new Agent(); |
| 44 | + agent.mbox = "mailto:tincancsharp@tincanapi.com"; |
| 45 | + |
| 46 | + verb = new Verb("http://adlnet.gov/expapi/verbs/experienced"); |
| 47 | + |
| 48 | + activity = new Activity(); |
| 49 | + activity.id = new Uri("http://tincanapi.com/TinCanCSharp/Test/Unit/0"); |
| 50 | + parent = new Activity(); |
| 51 | + parent.id = new Uri("http://tincanapi.com/TinCanCSharp/Test"); |
| 52 | + |
| 53 | + statementRef = new StatementRef(Guid.NewGuid()); |
| 54 | + |
| 55 | + context = new Context(); |
| 56 | + context.registration = Guid.NewGuid(); |
| 57 | + context.statement = statementRef; |
| 58 | + context.contextActivities = new ContextActivities(); |
| 59 | + context.contextActivities.parent = new List<Activity>(); |
| 60 | + context.contextActivities.parent.Add(parent); |
| 61 | + |
| 62 | + score = new Score(); |
| 63 | + score.raw = 97; |
| 64 | + score.scaled = 0.97; |
| 65 | + score.max = 100; |
| 66 | + score.min = 0; |
| 67 | + |
| 68 | + result = new Result(); |
| 69 | + result.score = score; |
| 70 | + result.success = true; |
| 71 | + result.completion = true; |
| 72 | + result.duration = new TimeSpan(1, 2, 16, 43); |
| 73 | + |
| 74 | + subStatement = new SubStatement(); |
| 75 | + subStatement.actor = agent; |
| 76 | + subStatement.verb = verb; |
| 77 | + subStatement.target = parent; |
| 78 | + } |
| 79 | + |
| 80 | + [Test] |
| 81 | + public void TestEmptyCtr() |
| 82 | + { |
| 83 | + Statement obj = new Statement(); |
| 84 | + Assert.IsInstanceOf<Statement>(obj); |
| 85 | + Assert.IsNull(obj.id); |
| 86 | + Assert.IsNull(obj.actor); |
| 87 | + Assert.IsNull(obj.verb); |
| 88 | + Assert.IsNull(obj.target); |
| 89 | + Assert.IsNull(obj.result); |
| 90 | + Assert.IsNull(obj.context); |
| 91 | + Assert.IsNull(obj.version); |
| 92 | + Assert.IsNull(obj.timestamp); |
| 93 | + Assert.IsNull(obj.stored); |
| 94 | + |
| 95 | + StringAssert.AreEqualIgnoringCase("{\"version\":\"1.0.1\"}", obj.ToJSON()); |
| 96 | + } |
| 97 | + |
| 98 | + [Test] |
| 99 | + public void TestJObjectCtrSubStatement() |
| 100 | + { |
| 101 | + JObject cfg = new JObject(); |
| 102 | + cfg.Add("actor", agent.ToJObject()); |
| 103 | + cfg.Add("verb", verb.ToJObject()); |
| 104 | + cfg.Add("object", subStatement.ToJObject()); |
| 105 | + |
| 106 | + Statement obj = new Statement(cfg); |
| 107 | + Assert.IsInstanceOf<Statement>(obj); |
| 108 | + Assert.IsNotNull(obj.target); |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments