| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using NUnit.Framework; |
| | 7 | | using System; |
| | 8 | | using System.Collections; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using Tests; |
| | 11 | | using UnityEngine; |
| | 12 | | using UnityEngine.TestTools; |
| | 13 | | using Environment = DCL.Environment; |
| | 14 | |
|
| | 15 | | public class BIWNftsShould : IntegrationTestSuite |
| | 16 | | { |
| | 17 | | private ParcelScene scene; |
| | 18 | | private const string ENTITY_ID = "1"; |
| | 19 | |
|
| | 20 | | protected override WorldRuntimeContext CreateRuntimeContext() |
| | 21 | | { |
| 2 | 22 | | return DCL.Tests.WorldRuntimeContextFactory.CreateWithCustomMocks |
| | 23 | | ( |
| | 24 | | sceneController: new SceneController(), |
| | 25 | | state: new WorldState(), |
| | 26 | | componentFactory: new RuntimeComponentFactory(), |
| | 27 | | sceneBoundsChecker: new SceneBoundsChecker() |
| | 28 | | ); |
| | 29 | | } |
| | 30 | |
|
| | 31 | | [UnitySetUp] |
| | 32 | | protected override IEnumerator SetUp() |
| | 33 | | { |
| 2 | 34 | | yield return base.SetUp(); |
| 2 | 35 | | scene = (ParcelScene) Environment.i.world.sceneController.CreateTestScene(); |
| 2 | 36 | | TestHelpers.CreateSceneEntity(scene, ENTITY_ID); |
| 2 | 37 | | BIWCatalogManager.Init(); |
| 2 | 38 | | BuilderInWorldTestHelper.CreateNFT(); |
| 2 | 39 | | } |
| | 40 | |
|
| | 41 | | [Test] |
| | 42 | | public void NftsUsage() |
| | 43 | | { |
| 1 | 44 | | string idToTest = BuilderInWorldNFTController.i.GetNfts()[0].assetContract.address; |
| | 45 | |
|
| 1 | 46 | | Assert.IsFalse(BuilderInWorldNFTController.i.IsNFTInUse(idToTest)); |
| | 47 | |
|
| 1 | 48 | | BuilderInWorldNFTController.i.UseNFT(idToTest); |
| 1 | 49 | | Assert.IsTrue(BuilderInWorldNFTController.i.IsNFTInUse(idToTest)); |
| | 50 | |
|
| 1 | 51 | | BuilderInWorldNFTController.i.StopUsingNFT(idToTest); |
| 1 | 52 | | Assert.IsFalse(BuilderInWorldNFTController.i.IsNFTInUse(idToTest)); |
| 1 | 53 | | } |
| | 54 | |
|
| | 55 | | [Test] |
| | 56 | | public void NftComponent() |
| | 57 | | { |
| 1 | 58 | | CatalogItem catalogItem = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0]; |
| | 59 | |
|
| | 60 | |
|
| 1 | 61 | | DCLBuilderInWorldEntity biwEntity = Utils.GetOrCreateComponent<DCLBuilderInWorldEntity>(scene.entities[ENTITY_ID |
| 1 | 62 | | biwEntity.Init(scene.entities[ENTITY_ID], null); |
| | 63 | |
|
| 1 | 64 | | NFTShape nftShape = (NFTShape) scene.SharedComponentCreate(catalogItem.id, Convert.ToInt32(CLASS_ID.NFT_SHAPE)); |
| 1 | 65 | | nftShape.model = new NFTShape.Model(); |
| 1 | 66 | | nftShape.model.color = new Color(0.6404918f, 0.611472f, 0.8584906f); |
| 1 | 67 | | nftShape.model.src = catalogItem.model; |
| 1 | 68 | | nftShape.model.assetId = catalogItem.id; |
| | 69 | |
|
| 1 | 70 | | scene.SharedComponentAttach(biwEntity.rootEntity.entityId, nftShape.id); |
| | 71 | |
|
| 1 | 72 | | Assert.IsTrue(biwEntity.IsEntityNFT()); |
| | 73 | |
|
| 1 | 74 | | CatalogItem associatedCatalogItem = biwEntity.GetCatalogItemAssociated(); |
| 1 | 75 | | Assert.IsTrue(associatedCatalogItem.IsNFT()); |
| 1 | 76 | | Assert.AreEqual(associatedCatalogItem, catalogItem); |
| 1 | 77 | | } |
| | 78 | |
|
| | 79 | | protected override IEnumerator TearDown() |
| | 80 | | { |
| 2 | 81 | | BIWCatalogManager.ClearCatalog(); |
| 2 | 82 | | BuilderInWorldNFTController.i.ClearNFTs(); |
| 2 | 83 | | yield return base.TearDown(); |
| 2 | 84 | | PoolManager.i.Cleanup(); |
| 2 | 85 | | } |
| | 86 | | } |