public void IntegerAttribute_SetsErrorMessage() { attribute = new IntegerAttribute(); String expected = String.Format(Validations.Integer, "Test"); String actual = attribute.FormatErrorMessage("Test"); Assert.Equal(expected, actual); }
public void ValidateAttributeTest() { IntegerAttribute attr = new IntegerAttribute { Value = 1 }; IntegerAttributeType uut = new IntegerAttributeType { Key = "Some Asset", MaxValue = null, MinValue = null, Required = false }; // Having min and max not specified should not result in an exception. { Assert.DoesNotThrow(() => uut.ValidateAttribute(attr)); Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr)); } // Still within range, should not blow up. { uut.MinValue = attr.Value; uut.MaxValue = attr.Value; Assert.DoesNotThrow(() => uut.ValidateAttribute(attr)); Assert.DoesNotThrow(() => uut.ValidateAttribute((IAttribute)attr)); } // Below min should result in an exception. { uut.MinValue = attr.Value + 1; uut.MaxValue = null; 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()); } // Above max should result in an exception. { uut.MinValue = null; uut.MaxValue = attr.Value - 1; 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()); } }
public void GetClientValidationRules_ReturnsIntegerValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "Integer"); IntegerAdapter adapter = new IntegerAdapter(metadata, new ControllerContext(), new IntegerAttribute()); String expectedMessage = new IntegerAttribute().FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("integer", actual.ValidationType); Assert.Empty(actual.ValidationParameters); }
public void ErrorMessageTest() { var attribute = new IntegerAttribute(); attribute.ErrorMessage = "SampleErrorMessage"; const string invalidValue = "a"; var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null)); Assert.AreEqual("SampleErrorMessage", result.ErrorMessage); }
public override Panel CreateControl(BaseConfigurationAttribute attr, PropertyInfo prop, object configuration_instance) { var panel = base.CreateControl(attr, prop, configuration_instance); IntegerAttribute iattr = attr as IntegerAttribute; var slider = panel.Children[1] as Slider; slider.Maximum = iattr.MaxValue; slider.Minimum = iattr.MinValue; return(panel); }
public void ErrorResourcesTest() { var attribute = new IntegerAttribute(); attribute.ErrorMessageResourceName = "ErrorMessage"; attribute.ErrorMessageResourceType = typeof(ErrorResources); const string invalidValue = "a"; var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null)); Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage); }
public void GetClientValidationRules_ReturnsIntegerValidationRule() { IServiceProvider services = Substitute.For <IServiceProvider>(); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); IntegerAdapter adapter = new IntegerAdapter(new IntegerAttribute()); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "Integer"); ClientModelValidationContext context = new ClientModelValidationContext(metadata, provider, services); ModelClientValidationRule actual = adapter.GetClientValidationRules(context).Single(); String expectedMessage = new IntegerAttribute().FormatErrorMessage("Integer"); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("integer", actual.ValidationType); Assert.Empty(actual.ValidationParameters); }
public void GlobalizedErrorResourcesTest() { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX"); var attribute = new IntegerAttribute(); attribute.ErrorMessageResourceName = "ErrorMessage"; attribute.ErrorMessageResourceType = typeof(ErrorResources); const string invalidValue = "a"; var result = attribute.GetValidationResult(invalidValue, new ValidationContext(0, null, null)); Assert.AreEqual("mensaje de error", result.ErrorMessage); }
public void SetValue_SetsIntegerAttribute() { NewElement element = InitializeEmptyNewElement(); int id = 15; var att = new IntegerAttribute() { Id = id }; element.IntegerAttributes.Add(att); int value = 150; element.SetValue(id, value); Assert.Equal(value, att.Value); }
public void IsValidTests() { var attribute = new IntegerAttribute(); Assert.IsTrue(attribute.IsValid(null)); // Don't check for required Assert.IsTrue(attribute.IsValid("1234")); Assert.IsTrue(attribute.IsValid("12345")); Assert.IsTrue(attribute.IsValid(14)); Assert.IsTrue(attribute.IsValid(-10)); //Allows negative numbers Assert.IsTrue(attribute.IsValid("-50")); Assert.IsFalse(attribute.IsValid(14.50)); Assert.IsFalse(attribute.IsValid("12.90")); Assert.IsFalse(attribute.IsValid("1234.5")); Assert.IsFalse(attribute.IsValid("$3.50")); Assert.IsFalse(attribute.IsValid("12abc")); Assert.IsFalse(attribute.IsValid(DateTime.Now)); Assert.IsFalse(attribute.IsValid("fourteen")); }
/// <summary> /// Vytvori html parametre z atributy /// </summary> /// <param name="attribute">Atribut z ktoreho chceme ziskat data</param> /// <param name="htmlAttributes">Html atributy</param> /// <returns>Dictionary</returns> public static IDictionary <string, object> InternalCustomAttributeFor(IntegerAttribute attribute, IDictionary <string, object> htmlAttributes) { if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } htmlAttributes.Add("data-required", attribute.Required.ToString().ToLower()); if (attribute.Required) { htmlAttributes.Add("data-maxvalue", attribute.MaxValue); htmlAttributes.Add("data-minvalue", attribute.MinValue); htmlAttributes.Add("maxlength", attribute.MaxValue.ToString().Length); htmlAttributes.Add("data-validation", StringAttribute.StringTypes.Numeric.ToString().ToLower()); if (!String.IsNullOrWhiteSpace(attribute.ClientValidationHandler)) { htmlAttributes.Add("data-validationhandler", attribute.ClientValidationHandler.ToLower()); } } return(htmlAttributes); }
public IntegerAttributeTests() { attribute = new IntegerAttribute(); }
public void CheckValidation(string value, bool expected) { var attribute = new IntegerAttribute(); Assert.Equal(expected, attribute.IsValid(value)); }
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); }
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); } }