Tanoda
MultiTypedReferenceTests.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using NUnit.Framework;
10
11namespace Leap.Unity.Tests {
12
14
15 public class BaseClass { }
16 public class A : BaseClass { }
17 public class B : BaseClass { }
18 public class C : BaseClass { }
19 public class D : BaseClass { }
20
21 public class InvalidClass : BaseClass { }
22
23 private class ReferenceClass : MultiTypedReference<BaseClass, A, B, C, D> { }
24
25 private ReferenceClass _ref;
26
27 [SetUp]
28 public void Setup() {
29 _ref = new ReferenceClass();
30 }
31
32 [TearDown]
33 public void Teardown() {
34 _ref.Clear();
35 _ref = null;
36 }
37
38 [Test]
39 public void SetTest() {
40 _ref.Value = new A();
41 Assert.That(_ref.Value, Is.TypeOf<A>());
42 }
43
44 [Test]
45 public void SetNullTest() {
46 _ref.Value = new A();
47 Assert.That(_ref.Value, Is.TypeOf<A>());
48 _ref.Value = null;
49 Assert.That(_ref.Value, Is.Null);
50 }
51
52 [Test]
53 public void SwitchTypeTest() {
54 _ref.Value = new A();
55 Assert.That(_ref.Value, Is.TypeOf<A>());
56 _ref.Value = new B();
57 Assert.That(_ref.Value, Is.TypeOf<B>());
58 }
59
60 [Test]
61 public void ClearTest() {
62 _ref.Value = new A();
63 Assert.That(_ref.Value, Is.TypeOf<A>());
64 _ref.Clear();
65 Assert.That(_ref.Value, Is.Null);
66 }
67
68 [Test]
69 public void AddInvalidTest() {
70 Assert.That(() => {
71 _ref.Value = new InvalidClass();
72 }, Throws.ArgumentException);
73 }
74
75 [Test]
76 public void CanAddAllTest() {
77 _ref.Value = new A();
78 Assert.That(_ref.Value, Is.TypeOf<A>());
79 _ref.Value = new B();
80 Assert.That(_ref.Value, Is.TypeOf<B>());
81 _ref.Value = new C();
82 Assert.That(_ref.Value, Is.TypeOf<C>());
83 _ref.Value = new D();
84 Assert.That(_ref.Value, Is.TypeOf<D>());
85 }
86 }
87}
Represents a single reference to a value of type BaseType.