1+ using System ;
2+ using Adnc . AnimatorHelpers . Editors . Testing . Utilities ;
3+ using Adnc . AnimatorHelpers . HasParameters ;
4+ using Adnc . Utility . Testing ;
5+ using NUnit . Framework ;
6+ using UnityEngine ;
7+ using Object = UnityEngine . Object ;
8+
9+ namespace Adnc . AnimatorHelpers . Editors . Testing . HasParameters {
10+ [ TestFixture ( Category = "HasParameter" ) ]
11+ public class TestAnimatorParametersCollection : TestBase {
12+ private AnimatorParametersCollection _animParCol ;
13+ private AnimatorStub _stub ;
14+
15+ [ SetUp ]
16+ public void Setup ( ) {
17+ _animParCol = new AnimatorParametersCollection ( ) ;
18+ _stub = new AnimatorStub ( ) ;
19+
20+ _stub . AnimatorCtrl . AddParameter ( new AnimatorControllerParameter {
21+ defaultBool = true ,
22+ name = "a" ,
23+ type = AnimatorControllerParameterType . Bool
24+ } ) ;
25+ }
26+
27+ [ TearDown ]
28+ public void Teardown ( ) {
29+ Object . DestroyImmediate ( _stub . Animator . gameObject ) ;
30+ _stub = null ;
31+ }
32+
33+ [ Test ]
34+ public void SetParameterReturnsAnimatorParameters ( ) {
35+ _stub . InjectCtrl ( ) ;
36+ var ps = _animParCol . SetParameters ( "a" , _stub . Animator ) ;
37+
38+ Assert . IsNotNull ( ps ) ;
39+ }
40+
41+ [ Test ]
42+ public void SetParameterStoresCachedAnimator ( ) {
43+ _stub . InjectCtrl ( ) ;
44+ var ps = _animParCol . SetParameters ( "a" , _stub . Animator ) ;
45+ var psCache = _animParCol . GetParameters ( "a" ) ;
46+
47+ Assert . AreSame ( ps , psCache ) ;
48+ }
49+
50+ [ Test ]
51+ public void SetAnimatorEmptyStringErrors ( ) {
52+ Assert . Throws < ArgumentNullException > ( ( ) => {
53+ _animParCol . SetParameters ( "" , _stub . Animator ) ;
54+ } ) ;
55+ }
56+
57+ [ Test ]
58+ public void SetAnimatorNullStringErrors ( ) {
59+ Assert . Throws < ArgumentNullException > ( ( ) => {
60+ _animParCol . SetParameters ( null , _stub . Animator ) ;
61+ } ) ;
62+ }
63+
64+ [ Test ]
65+ public void SetAnimatorNullAnimatorErrors ( ) {
66+ Assert . Throws < ArgumentNullException > ( ( ) => {
67+ _animParCol . SetParameters ( "a" , null ) ;
68+ } ) ;
69+ }
70+
71+ [ Test ]
72+ public void GetMissingAnimatorParametersReturnsNull ( ) {
73+ Assert . IsNull ( _animParCol . GetParameters ( "a" ) ) ;
74+ }
75+
76+ [ Test ]
77+ public void GetParametersNullReturnsError ( ) {
78+ Assert . Throws < ArgumentNullException > ( ( ) => {
79+ _animParCol . GetParameters ( null ) ;
80+ } ) ;
81+ }
82+
83+ [ Test ]
84+ public void GetParametersEmptyStringReturnsError ( ) {
85+ Assert . Throws < ArgumentNullException > ( ( ) => {
86+ _animParCol . GetParameters ( "" ) ;
87+ } ) ;
88+ }
89+
90+ [ Test ]
91+ public void GetParametersAutoGeneratesCacheIfItDoesNotExist ( ) {
92+ _stub . InjectCtrl ( ) ;
93+ var psCache = _animParCol . GetParameters ( "a" , _stub . Animator ) ;
94+
95+ Assert . IsNotNull ( psCache ) ;
96+ Assert . IsTrue ( _animParCol . HasParameters ( "a" ) ) ;
97+ }
98+
99+ [ Test ]
100+ public void GetParametersDoesNotAutoGenerateCacheIfItExists ( ) {
101+ _stub . InjectCtrl ( ) ;
102+ var ps = _animParCol . SetParameters ( "a" , _stub . Animator ) ;
103+
104+ Assert . AreSame ( ps , _animParCol . GetParameters ( "a" , _stub . Animator ) ) ;
105+ }
106+
107+ [ Test ]
108+ public void HasParametersReturnsTrueIfParameters ( ) {
109+ _stub . InjectCtrl ( ) ;
110+ var ps = _animParCol . SetParameters ( "a" , _stub . Animator ) ;
111+
112+ Assert . IsTrue ( _animParCol . HasParameters ( "a" ) ) ;
113+ }
114+
115+ [ Test ]
116+ public void HasParametersReturnsFalseIfNoParameters ( ) {
117+ Assert . IsFalse ( _animParCol . HasParameters ( "a" ) ) ;
118+ }
119+ }
120+ }
0 commit comments