| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using DCL.Models; |
| | 7 | | using NSubstitute; |
| | 8 | | using NSubstitute.ReceivedExtensions; |
| | 9 | | using Tests; |
| | 10 | | using UnityEngine; |
| | 11 | | using UnityEngine.TestTools; |
| | 12 | | using Assert = UnityEngine.Assertions.Assert; |
| | 13 | | using Object = UnityEngine.Object; |
| | 14 | |
|
| | 15 | | public class LoadWrapperShould : IntegrationTestSuite |
| | 16 | | { |
| 1 | 17 | | protected override PlatformContext CreatePlatformContext() { return DCL.Tests.PlatformContextFactory.CreateWithGener |
| | 18 | |
|
| | 19 | | [UnityTest] |
| | 20 | | public IEnumerator UnloadWhenEntityDestroyedBeforeFinishing() |
| | 21 | | { |
| 1 | 22 | | GameObject meshRootGameObject = new GameObject(); |
| | 23 | |
|
| 1 | 24 | | string url = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb"; |
| | 25 | |
|
| 1 | 26 | | IDCLEntity entity = Substitute.For<IDCLEntity>(); |
| 1 | 27 | | entity.meshRootGameObject.Returns(meshRootGameObject); |
| | 28 | |
|
| 1 | 29 | | LoadWrapper_GLTF wrapper = Substitute.ForPartsOf<LoadWrapper_GLTF>(); |
| 1 | 30 | | wrapper.entity = entity; |
| 1 | 31 | | wrapper.customContentProvider = new ContentProvider(); |
| | 32 | |
|
| 1 | 33 | | bool loaded = false; |
| 1 | 34 | | bool failed = false; |
| 1 | 35 | | bool unloaded = false; |
| | 36 | |
|
| 3 | 37 | | wrapper.WhenForAnyArgs(x => x.Unload()).Do((info) => unloaded = true); |
| | 38 | |
|
| 1 | 39 | | wrapper.Load(url, loadWrapper => loaded = true, loadWrapper => failed = true ); |
| | 40 | |
|
| 1 | 41 | | entity.OnCleanupEvent?.Invoke(entity); |
| | 42 | |
|
| 2 | 43 | | yield return new WaitUntil(() => loaded || failed || unloaded); |
| | 44 | |
|
| 1 | 45 | | Object.Destroy(meshRootGameObject); |
| | 46 | |
|
| 1 | 47 | | Assert.IsTrue(unloaded, "Unload should be called if entity is cleaned up while loading mesh"); |
| 1 | 48 | | } |
| | 49 | | } |