public void ValidateAttributeTest() { AssetNameAttribute attr = new AssetNameAttribute { Value = null }; AssetNameAttributeType uut = new AssetNameAttributeType { Key = "Some Asset" }; // Null should throw an exception. 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()); attr.Value = "Name"; Assert.DoesNotThrow(() => uut.ValidateAttribute(attr)); Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr)); }
/// <summary> /// Adds the color attribute type. /// </summary> /// <returns>The type ID.</returns> private int AddColorAttributeType(IDatabaseApi uut, Guid databaseId) { AssetTypeBuilder typeBuilder = new AssetTypeBuilder(colorTypeName, databaseId); AssetNameAttributeType assetNameType = new AssetNameAttributeType { Key = nameKey, Required = true }; typeBuilder.AttributeTypes.Add(assetNameType); IntegerAttributeType redValue = new IntegerAttributeType { Key = redKey, Required = true, MinValue = 0, MaxValue = 255, DefaultValue = 0 }; typeBuilder.AttributeTypes.Add(redValue); IntegerAttributeType greenValue = new IntegerAttributeType { Key = greenKey, Required = true, MinValue = 0, MaxValue = 255, DefaultValue = 0 }; typeBuilder.AttributeTypes.Add(greenValue); IntegerAttributeType blueValue = new IntegerAttributeType { Key = blueKey, Required = true, MinValue = 0, MaxValue = 255, DefaultValue = 0 }; typeBuilder.AttributeTypes.Add(blueValue); int colorAssetTypeID = uut.AddAssetType(typeBuilder); return(colorAssetTypeID); }
public void SerializeDeserializeTest() { AssetNameAttributeType originalObject = new AssetNameAttributeType { Key = "Asset Name" }; string serialObjected = originalObject.Serialize(); AssetNameAttributeType uut = new AssetNameAttributeType(); uut.Deserialize(serialObjected); Assert.AreEqual(originalObject.Key, uut.Key); Assert.AreEqual(originalObject.Required, uut.Required); }
public void DeserializeTest1() { const string json = @" { ""Key"": ""Asset Name"", ""AttributeType"": 1, ""Required"": true, ""DefaultValue"": null, ""PossibleValues"": null } "; AssetNameAttributeType uut = new AssetNameAttributeType(); uut.Deserialize(json); Assert.AreEqual("Asset Name", uut.Key); Assert.AreEqual(true, uut.Required); }
private static void AddVideoGames(IAssetManagerApi api) { if (File.Exists(@"C:\Users\xfore\Downloads\VideoGames.db")) { File.Delete(@"C:\Users\xfore\Downloads\VideoGames.db"); } Guid databaseId = api.DataBase.DatabaseNames.First(n => n.Value == "VideoGames").Key; AssetTypeBuilder builder = new AssetTypeBuilder("PC Games", databaseId); AssetNameAttributeType assetNameType = new AssetNameAttributeType { Key = "Title", Required = true }; builder.AttributeTypes.Add(assetNameType); IntegerAttributeType releaseYear = new IntegerAttributeType { Key = "Release Year", Required = true }; builder.AttributeTypes.Add(releaseYear); int pcGameId = api.DataBase.AddAssetType(builder); { Asset asset = api.DataBase.GenerateEmptyAsset(databaseId, pcGameId); asset.SetAttribute("Title", new AssetNameAttribute("Command and Conquer")); asset.SetAttribute("Release Year", new IntegerAttribute { Value = 1995 }); api.DataBase.AddAsset(asset); } }
public void ValidateTest() { AssetNameAttributeType uut = new AssetNameAttributeType { Key = "Some Asset" }; Assert.DoesNotThrow(() => uut.Validate()); // Required set to false will cause a validation error, // this is ALWAYS required. uut.Required = false; ListedValidationException e = Assert.Throws <ListedValidationException>(() => uut.Validate()); Assert.AreEqual(1, e.Errors.Count()); uut.Required = true; // Null key will throw exceptions. uut.Key = null; e = Assert.Throws <ListedValidationException>(() => uut.Validate()); Assert.AreEqual(1, e.Errors.Count()); }
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); } }