|
| 1 | +/* |
| 2 | + Copyright 2015 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 NUnit.Framework; |
| 20 | + using Newtonsoft.Json.Linq; |
| 21 | + using TinCan; |
| 22 | + using TinCan.Json; |
| 23 | + |
| 24 | + [TestFixture] |
| 25 | + class ResultTest |
| 26 | + { |
| 27 | + [Test] |
| 28 | + public void TestEmptyCtr() |
| 29 | + { |
| 30 | + var obj = new Result(); |
| 31 | + Assert.IsInstanceOf<Result>(obj); |
| 32 | + Assert.IsNull(obj.completion); |
| 33 | + Assert.IsNull(obj.success); |
| 34 | + Assert.IsNull(obj.response); |
| 35 | + Assert.IsNull(obj.duration); |
| 36 | + Assert.IsNull(obj.score); |
| 37 | + Assert.IsNull(obj.extensions); |
| 38 | + |
| 39 | + StringAssert.AreEqualIgnoringCase("{}", obj.ToJSON()); |
| 40 | + } |
| 41 | + |
| 42 | + [Test] |
| 43 | + public void TestJObjectCtr() |
| 44 | + { |
| 45 | + var cfg = new JObject(); |
| 46 | + cfg.Add("completion", true); |
| 47 | + cfg.Add("success", true); |
| 48 | + cfg.Add("response", "Yes"); |
| 49 | + |
| 50 | + var obj = new Result(cfg); |
| 51 | + Assert.IsInstanceOf<Result>(obj); |
| 52 | + Assert.That(obj.completion, Is.EqualTo(true)); |
| 53 | + Assert.That(obj.success, Is.EqualTo(true)); |
| 54 | + Assert.That(obj.response, Is.EqualTo("Yes")); |
| 55 | + } |
| 56 | + |
| 57 | + [Test] |
| 58 | + public void TestStringOfJSONCtr() |
| 59 | + { |
| 60 | + var json = "{\"success\": true, \"completion\": true, \"response\": \"Yes\"}"; |
| 61 | + var strOfJson = new StringOfJSON(json); |
| 62 | + |
| 63 | + var obj = new Result(strOfJson); |
| 64 | + Assert.IsInstanceOf<Result>(obj); |
| 65 | + Assert.That(obj.success, Is.EqualTo(true)); |
| 66 | + Assert.That(obj.completion, Is.EqualTo(true)); |
| 67 | + Assert.That(obj.response, Is.EqualTo("Yes")); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments