public void ValidateAttributeTest()
        {
            StringAttribute attr = new StringAttribute
            {
                Value = null
            };

            StringAttributeType uut = new StringAttributeType
            {
                Key      = "Some Asset",
                Required = true
            };

            // Null should throw an exception, if required is set to true.
            {
                uut.Required = true;
                ListedValidationException e;

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute(attr));
                Assert.AreEqual(1, e.Errors.Count());

                e = Assert.Throws <ListedValidationException>(() => uut.ValidateAttribute((IAttribute)attr));
                Assert.AreEqual(1, e.Errors.Count());
            }

            // Null should not throw an exception if required is set to false.
            {
                uut.Required = false;
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // No exceptions should be thrown if required is false and a value is set.
            {
                uut.Required = false;
                attr.Value   = "Some value";
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }

            // No exceptions should be thrown if required is true and a value is set.
            {
                uut.Required = true;
                attr.Value   = "Some value";
                Assert.DoesNotThrow(() => uut.ValidateAttribute(attr));
                Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr));
            }
        }
        public void SerializeDeserializeTest()
        {
            StringAttributeType originalObject = new StringAttributeType
            {
                Key          = "My Attribute",
                DefaultValue = "World",
                Required     = true
            };

            string serialObjected = originalObject.Serialize();

            StringAttributeType uut = new StringAttributeType();

            uut.Deserialize(serialObjected);

            Assert.AreEqual(originalObject.Key, uut.Key);
            Assert.AreEqual(originalObject.Required, uut.Required);
            Assert.AreEqual(originalObject.DefaultValue, uut.DefaultValue);
        }
        public void DeserializeTest1()
        {
            const string json =
                @"
{
    ""Key"": ""Test Attribute"",
    ""AttributeType"": 2,
    ""Required"": false,
    ""PossibleValues"": null,
    ""DefaultValue"": null
}
";
            StringAttributeType uut = new StringAttributeType();

            uut.Deserialize(json);

            Assert.AreEqual("Test Attribute", uut.Key);
            Assert.AreEqual(false, uut.Required);
            Assert.IsNull(uut.DefaultValue);
        }
        public void ValidateTest()
        {
            StringAttributeType uut = new StringAttributeType
            {
                Key          = "Some String",
                DefaultValue = null,
                Required     = false
            };

            Assert.DoesNotThrow(() => uut.Validate());

            // Having a default value should be okay.
            uut.DefaultValue = "Hello";
            Assert.DoesNotThrow(() => uut.Validate());

            // Not having a default value with a min/max should work okay.
            Assert.DoesNotThrow(() => uut.Validate());

            // Null key is not okay
            uut.Key = null;
            ListedValidationException e = Assert.Throws <ListedValidationException>(() => uut.Validate());

            Assert.AreEqual(1, e.Errors.Count());
        }
Esempio n. 5
0
        private static void AddTradingCards(IAssetManagerApi api)
        {
            if (File.Exists(@"C:\Users\xfore\Downloads\TradingCards.db"))
            {
                File.Delete(@"C:\Users\xfore\Downloads\TradingCards.db");
            }

            Guid databaseId = api.DataBase.DatabaseNames.First(n => n.Value == "TradingCards").Key;

            int pokemonCardTypeId = -1;
            {
                AssetTypeBuilder builder = new AssetTypeBuilder("Pokemon Card", databaseId);

                AssetNameAttributeType assetNameType = new AssetNameAttributeType
                {
                    Key      = "Card Name",
                    Required = true
                };
                builder.AttributeTypes.Add(assetNameType);

                IntegerAttributeType hpAttribute = new IntegerAttributeType
                {
                    Key          = "HP",
                    MinValue     = 10,
                    Required     = false,
                    DefaultValue = 50
                };

                builder.AttributeTypes.Add(hpAttribute);

                IntegerAttributeType retreatCostAttribute = new IntegerAttributeType
                {
                    Key      = "Retreat Cost",
                    MinValue = 0,
                    MaxValue = 4,
                    Required = false
                };
                builder.AttributeTypes.Add(retreatCostAttribute);

                StringAttributeType flavorText = new StringAttributeType
                {
                    Key      = "Flavor Text",
                    Required = true
                };
                builder.AttributeTypes.Add(flavorText);

                pokemonCardTypeId = api.DataBase.AddAssetType(builder);
            }

            int yugiohCardTypeId = -1;
            {
                AssetTypeBuilder builder = new AssetTypeBuilder("Yugioh! Card", databaseId);

                AssetNameAttributeType assetNameType = new AssetNameAttributeType
                {
                    Key      = "Card Name",
                    Required = true
                };
                builder.AttributeTypes.Add(assetNameType);

                IntegerAttributeType attackAttribute = new IntegerAttributeType
                {
                    Key      = "Attack",
                    MinValue = 0,
                    Required = true
                };
                builder.AttributeTypes.Add(attackAttribute);

                IntegerAttributeType defenseAttribute = new IntegerAttributeType
                {
                    Key      = "Defense",
                    MinValue = 0,
                    Required = true
                };
                builder.AttributeTypes.Add(defenseAttribute);

                yugiohCardTypeId = api.DataBase.AddAssetType(builder);
            }

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, pokemonCardTypeId);
                asset.SetAttribute("Card Name", new AssetNameAttribute("Politoed"));
                asset.SetAttribute("HP", new IntegerAttribute()
                {
                    Value = 100
                });
                asset.SetAttribute("Retreat Cost", new IntegerAttribute()
                {
                    Value = 3
                });
                asset.SetAttribute(
                    "Flavor Text",
                    new StringAttribute
                {
                    Value =
                        @"Whenever 3 or more of these get together,
they sing in an lound voice that sounds like bellowing."
                }
                    );

                api.DataBase.AddAsset(asset);
            }

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, yugiohCardTypeId);
                asset.SetAttribute("Card Name", new AssetNameAttribute("The 13th Grave"));

                IntegerAttribute attackAttr = asset.CloneAttributeAsType <IntegerAttribute>("Attack");
                attackAttr.Value = 1200;
                asset.SetAttribute("Attack", attackAttr);

                IntegerAttribute defenseAttr = asset.CloneAttributeAsType <IntegerAttribute>("Defense");
                defenseAttr.Value = 900;
                asset.SetAttribute("Defense", attackAttr);

                api.DataBase.AddAsset(asset);
            }

            {
                Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, yugiohCardTypeId);
                asset.SetAttribute("Card Name", new AssetNameAttribute("Overdrive"));
                asset.SetAttribute("Attack", new IntegerAttribute(1600));
                asset.SetAttribute("Defense", new IntegerAttribute(1500));

                api.DataBase.AddAsset(asset);
            }
        }