Esempio n. 1
0
 static IPromise Init(DatabaseApi api)
 {
     return(Promise.All(
                api.GetDynamicGlobalProperties().Then(AddInPromise),
                api.GetGlobalProperties().Then(AddInPromise),
                api.GetAsset().Then(AddInPromise)
                ));
 }
        public void AddRemoveUpdateAssetTest()
        {
            // First, create a simple asset type.  We'll do colors!
            SqliteDatabaseConfig databaseConfig = new SqliteDatabaseConfig
            {
                DatabaseLocation = this.db1Location
            };
            Guid databaseId = databaseConfig.DatabaseId;

            DatabaseApi uut = new DatabaseApi(new List <IDatabaseConfig> {
                databaseConfig
            });

            int typeId = this.AddColorAttributeType(uut, databaseId);

            Assert.Greater(typeId, 0);

            int redId = this.AddRedAsset(uut, databaseId, typeId);

            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));

            int greenId = this.AddGreenAsset(uut, databaseId, typeId);

            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));
            // Ensure red wasn't modified
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));

            int blueId = this.AddBlueAsset(uut, databaseId, typeId);

            this.VerifyBlueAsset(uut.GetAsset(databaseId, blueId));
            // Ensure red and green weren't modified.
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));
            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));

            // Add a duplicate color, blue 2.
            int blue2Id = this.AddBlueAsset(uut, databaseId, typeId);

            this.VerifyBlueAsset(uut.GetAsset(databaseId, blue2Id));
            // Ensure existing assets weren't modified.
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));
            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));
            this.VerifyBlueAsset(uut.GetAsset(databaseId, blueId));

            // Remove duplicate blue ID
            uut.DeleteAsset(databaseId, typeId, blue2Id);
            Assert.Throws <ArgumentException>(() => uut.GetAsset(databaseId, blue2Id));    // <- Should not exist.
            // Ensure existing assets weren't modified.
            this.VerifyRedAsset(uut.GetAsset(databaseId, redId));
            this.VerifyGreenAsset(uut.GetAsset(databaseId, greenId));
            this.VerifyBlueAsset(uut.GetAsset(databaseId, blueId));

            // Edit red to make it slightly less red.
            {
                Asset redAsset = uut.GetAsset(databaseId, redId);
                AssetNameAttribute nameAttr = redAsset.CloneAttributeAsType <AssetNameAttribute>(nameKey);
                nameAttr.Value = "New Red!";
                redAsset.SetAttribute(nameKey, nameAttr);

                IntegerAttribute redAttr = redAsset.CloneAttributeAsType <IntegerAttribute>(redKey);
                redAttr.Value = 254;
                redAsset.SetAttribute(redKey, redAttr);

                IntegerAttribute greenAttr = redAsset.CloneAttributeAsType <IntegerAttribute>(greenKey);
                greenAttr.Value = 1;
                redAsset.SetAttribute(greenKey, greenAttr);

                IntegerAttribute blueAttr = redAsset.CloneAttributeAsType <IntegerAttribute>(blueKey);
                blueAttr.Value = 5;
                redAsset.SetAttribute(blueKey, blueAttr);

                uut.UpdateAsset(redId, redAsset);
                this.VerifyAsset(
                    uut.GetAsset(databaseId, redId),
                    nameAttr.Value,
                    redAttr.Value,
                    greenAttr.Value,
                    blueAttr.Value
                    );
            }

            AssetListInfo assetList = uut.GetAssetsOfType(databaseId, typeId);

            Assert.AreEqual(3, assetList.AssetList.Count);
            Assert.AreEqual(typeId, assetList.AssetTypeId);
            Assert.AreEqual(colorTypeName, assetList.AssetTypeName);
            Assert.AreEqual(databaseId, assetList.DatabaseId);
        }