コード例 #1
0
        public void AssetManipulations()
        {
            Asset     asset1         = new Asset("Bob", "Big");
            var       concreteAsset1 = asset1.Concrete();
            TextAsset textAsset1     = new TextAsset("Bob", "Big");

            Assert.AreEqual(asset1.Value, concreteAsset1.StringValue);
            Assert.AreEqual(asset1.Value, textAsset1.StringValue);

            Asset     asset2         = new Asset("Bob", true);
            var       concreteAsset2 = asset2.Concrete();
            BoolAsset boolAsset1     = new BoolAsset("Bob", true);

            Assert.AreEqual(asset2.Value.ToString(), concreteAsset2.StringValue);
            Assert.AreEqual(asset2.Value, boolAsset1.Value);

            Asset        asset3         = new Asset("Bob", 1993);
            var          concreteAsset3 = asset3.Concrete();
            IntegerAsset integerAsset   = new IntegerAsset("Bob", 1993);

            Assert.AreEqual(asset3.Value.ToString(), concreteAsset3.StringValue);
            Assert.AreEqual(asset3.Value, integerAsset.Value);

            Asset asset4 = new Asset("Tom", "Tam");

            Assert.AreEqual(asset4.ValueType, AssetValueType.Text);
            IntegerAsset integerAsset2  = new IntegerAsset("Tom", 1999);
            bool         canChangeValue = true;

            try
            {
                asset4.Value = integerAsset2.Value;
            }
            catch (Exception)
            {
                canChangeValue = false;
            }
            Assert.IsFalse(canChangeValue);
            Assert.AreEqual(asset4.ValueType, AssetValueType.Text);
            Assert.AreNotEqual(asset4.ValueType, AssetValueType.Integer);
            canChangeValue = true;
            try
            {
                asset4.Value = "Test2";
            }
            catch (Exception)
            {
                canChangeValue = false;
            }
            Assert.IsTrue(canChangeValue);
            Assert.AreEqual(asset4.StringValue, "Test2");
            Assert.AreEqual(asset4.ValueType, AssetValueType.Text);
        }
コード例 #2
0
        public void AssetTest()
        {
            string testAssetName1 = Guid.NewGuid().ToString();
            string testAssetName2 = Guid.NewGuid().ToString();
            int    testValue1     = 1993;
            int    testValue2     = 2020;

            try
            {
                Filter filter = new Filter("Name", testAssetName1);
                var    asset  = uiPath.AssetManager.GetCollection(filter).FirstOrDefault();
                Assert.IsNull(asset);

                IntegerAsset asset1 = new IntegerAsset(testAssetName1, testValue1);
                uiPath.AssetManager.CreateInstance(asset1);
                asset = uiPath.AssetManager.GetCollection(filter).FirstOrDefault();
                Assert.IsNotNull(asset);

                Assert.AreEqual(asset.Name, testAssetName1);
                asset.Name  = testAssetName2;
                asset.Value = testValue2;
                uiPath.AssetManager.ChangeInstance(asset);
                filter = new Filter("Name", testAssetName2);
                asset  = uiPath.AssetManager.GetCollection(filter).FirstOrDefault();
                Assert.IsNotNull(asset);
                Assert.AreEqual(asset.Name, testAssetName2);
                Assert.AreEqual(asset.Value, testValue2);

                uiPath.AssetManager.DeleteInstance(asset);
                asset = uiPath.AssetManager.GetCollection(filter).FirstOrDefault();
                Assert.IsNull(asset);
            }
            catch (Exception ex)
            {
                if (!string.IsNullOrEmpty(uiPath.LastErrorMessage))
                {
                    throw new Exception(uiPath.LastErrorMessage, ex);
                }
                throw ex;
            }
        }