| | 1 | | using System.Collections; |
| | 2 | | using DCL; |
| | 3 | | using NSubstitute; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.TestTools; |
| | 7 | | using WaitUntil = DCL.WaitUntil; |
| | 8 | |
|
| | 9 | | namespace AvatarShape_Tests |
| | 10 | | { |
| | 11 | | public class FacialFeatureControllerShould : IntegrationTestSuite_Legacy |
| | 12 | | { |
| | 13 | | private const string EYES_ID = "urn:decentraland:off-chain:base-avatars:f_eyes_01"; |
| | 14 | | private const string DRACULA_MOUTH_ID = "urn:decentraland:off-chain:base-avatars:dracula_mouth"; |
| | 15 | | private BaseDictionary<string, WearableItem> catalog; |
| | 16 | | private IBodyShapeController bodyShapeController; |
| | 17 | |
|
| | 18 | | [UnitySetUp] |
| | 19 | | protected override IEnumerator SetUp() |
| | 20 | | { |
| 4 | 21 | | yield return base.SetUp(); |
| 4 | 22 | | bodyShapeController = Substitute.For<IBodyShapeController>(); |
| 4 | 23 | | bodyShapeController.bodyShapeId.Returns(WearableLiterals.BodyShapes.FEMALE); |
| | 24 | |
|
| 4 | 25 | | catalog = AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 4 | 26 | | } |
| | 27 | |
|
| | 28 | | [UnityTest] |
| | 29 | | public IEnumerator LoadProperly() |
| | 30 | | { |
| | 31 | | //Arrange |
| 1 | 32 | | catalog.TryGetValue(EYES_ID, out WearableItem wereableItem); |
| 1 | 33 | | FacialFeatureController controller = new FacialFeatureController(wereableItem, new Material(Shader.Find("DCL |
| | 34 | |
|
| | 35 | | //Act |
| 1 | 36 | | controller.Load(bodyShapeController, Color.red); |
| 4 | 37 | | yield return new WaitUntil(() => controller.isReady); |
| | 38 | |
|
| | 39 | | //Assert |
| 1 | 40 | | Assert.NotNull(controller.mainTexture); |
| 1 | 41 | | Assert.NotNull(controller.maskTexture); |
| 1 | 42 | | } |
| | 43 | |
|
| | 44 | | [UnityTest] |
| | 45 | | public IEnumerator FailsGracefully_BadURL() |
| | 46 | | { |
| | 47 | | //Arrange |
| 1 | 48 | | WearableItem fakeWearable = new WearableItem |
| | 49 | | { |
| | 50 | | baseUrl = "http://nothing_here.nope", |
| | 51 | | data = new WearableItem.Data() |
| | 52 | | { |
| | 53 | | category = WearableLiterals.Categories.EYES, |
| | 54 | | representations = new [] |
| | 55 | | { |
| | 56 | | new WearableItem.Representation() |
| | 57 | | { |
| | 58 | | bodyShapes = new [] { WearableLiterals.BodyShapes.FEMALE }, |
| | 59 | | contents = new [] |
| | 60 | | { |
| | 61 | | new WearableItem.MappingPair { key = "fake.png", hash = "nope" }, |
| | 62 | | new WearableItem.MappingPair { key = "fake_mask.png", hash = "nope2" } |
| | 63 | | }, |
| | 64 | | } |
| | 65 | | } |
| | 66 | | } |
| | 67 | | }; |
| 1 | 68 | | FacialFeatureController controller = new FacialFeatureController(fakeWearable, new Material(Shader.Find("DCL |
| | 69 | |
|
| | 70 | | //Act |
| 1 | 71 | | controller.Load(bodyShapeController, Color.red); |
| 9 | 72 | | yield return new WaitUntil(() => controller.isReady); |
| | 73 | |
|
| | 74 | | //Assert |
| 1 | 75 | | Assert.Null(controller.mainTexture); |
| 1 | 76 | | Assert.Null(controller.maskTexture); |
| 1 | 77 | | } |
| | 78 | |
|
| | 79 | | [UnityTest] |
| | 80 | | public IEnumerator FailsGracefully_EmptyContent() |
| | 81 | | { |
| | 82 | | //Arrange |
| 1 | 83 | | WearableItem fakeWearable = new WearableItem |
| | 84 | | { |
| | 85 | | baseUrl = "http://nothing_here.nope", |
| | 86 | | data = new WearableItem.Data() |
| | 87 | | { |
| | 88 | | category = WearableLiterals.Categories.EYES, |
| | 89 | | representations = new [] |
| | 90 | | { |
| | 91 | | new WearableItem.Representation |
| | 92 | | { |
| | 93 | | bodyShapes = new [] { WearableLiterals.BodyShapes.FEMALE }, |
| | 94 | | contents = new WearableItem.MappingPair[0], |
| | 95 | | } |
| | 96 | | } |
| | 97 | | } |
| | 98 | | }; |
| 1 | 99 | | FacialFeatureController controller = new FacialFeatureController(fakeWearable, new Material(Shader.Find("DCL |
| | 100 | |
|
| | 101 | | //Act |
| 1 | 102 | | controller.Load(bodyShapeController, Color.red); |
| 4 | 103 | | yield return new WaitUntil(() => controller.isReady); |
| | 104 | |
|
| | 105 | | //Assert |
| 1 | 106 | | Assert.Null(controller.mainTexture); |
| 1 | 107 | | Assert.Null(controller.maskTexture); |
| 1 | 108 | | } |
| | 109 | |
|
| | 110 | | [UnityTest] |
| | 111 | | public IEnumerator LoadMouthWithMaskProperly() |
| | 112 | | { |
| | 113 | | //Arrange |
| 1 | 114 | | catalog.TryGetValue(DRACULA_MOUTH_ID, out WearableItem wereableItem); |
| | 115 | |
|
| 1 | 116 | | FacialFeatureController controller = new FacialFeatureController(wereableItem, new Material(Shader.Find("DCL |
| | 117 | |
|
| | 118 | | //Act |
| 1 | 119 | | controller.Load(bodyShapeController, Color.red); |
| 4 | 120 | | yield return new WaitUntil(() => controller.isReady); |
| | 121 | |
|
| | 122 | | //Assert |
| 1 | 123 | | Assert.NotNull(controller.mainTexture); |
| 1 | 124 | | Assert.NotNull(controller.maskTexture); |
| 1 | 125 | | } |
| | 126 | | } |
| | 127 | | } |