-
Notifications
You must be signed in to change notification settings - Fork 6
/
LayoutAttributeTests.cs
79 lines (68 loc) · 2.85 KB
/
LayoutAttributeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using NSubstitute;
using NSubstitute.ReturnsExtensions;
using NUnit.Framework;
using UIComponents.Internal;
using UIComponents.Testing;
using UIComponents.Tests.Utilities;
using UnityEngine.TestTools;
using UnityEngine.UIElements;
namespace UIComponents.Tests
{
[TestFixture]
public partial class LayoutAttributeTests
{
[Layout("Assets/MyAsset.uxml")]
private partial class UIComponentWithLayout : UIComponent {}
private partial class InheritedComponentWithoutAttribute : UIComponentWithLayout {}
[Layout("Assets/MyOtherAsset.uxml")]
private partial class InheritedComponentWithAttribute : UIComponentWithLayout {}
[Layout("Assets/MissingAsset.uxml")]
private partial class UIComponentWithNullLayout : UIComponent {}
private IAssetResolver _mockResolver;
[SetUp]
public void SetUp()
{
_mockResolver = MockUtilities.CreateMockResolver();
_mockResolver.LoadAsset<VisualTreeAsset>("Assets/MissingAsset.uxml")
.ReturnsNull();
}
[TearDown]
public void TearDown()
{
_mockResolver.ClearReceivedCalls();
}
[UnityTest]
public IEnumerator Given_Layout_Is_Loaded()
{
var testBed = new TestBed<UIComponentWithLayout>().WithSingleton(_mockResolver);
var component = testBed.CreateComponent();
yield return component.Initialize().AsEnumerator();
_mockResolver.Received().LoadAsset<VisualTreeAsset>("Assets/MyAsset.uxml");
}
[UnityTest]
public IEnumerator Superclass_Layout_Is_Loaded_If_It_Is_Not_Overridden()
{
var testBed = new TestBed<InheritedComponentWithoutAttribute>().WithSingleton(_mockResolver);
var component = testBed.CreateComponent();
yield return component.Initialize().AsEnumerator();
_mockResolver.Received().LoadAsset<VisualTreeAsset>("Assets/MyAsset.uxml");
}
[UnityTest]
public IEnumerator Superclass_Layout_Is_Not_Loaded_If_Overridden()
{
var testBed = new TestBed<InheritedComponentWithAttribute>().WithSingleton(_mockResolver);
var component = testBed.CreateComponent();
yield return component.Initialize().AsEnumerator();
_mockResolver.Received().LoadAsset<VisualTreeAsset>("Assets/MyOtherAsset.uxml");
_mockResolver.DidNotReceive().LoadAsset<VisualTreeAsset>("Assets/MyAsset.uxml");
}
[UnityTest]
public IEnumerator Null_Layout_Is_Handled()
{
var testBed = new TestBed<UIComponentWithNullLayout>().WithSingleton(_mockResolver);
var component = testBed.CreateComponent();
yield return component.Initialize().AsEnumerator();
}
}
}