public void TestAddNullValueNoSchema() { IPropertySetCollection collection = GetCollection(); collection.Add("key", null); object value = collection.Get <object>("key"); Assert.IsNull(value); }
public void TestAddValueTypePropertyNoDefaultValueNotAllowNullWithValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", 100, new IntSchema()); int?value = collection.Get <int?>("key"); Assert.IsNotNull(value); Assert.AreEqual(100, value); }
public void TestContainsKvPair() { KeyValuePair <string, object> item = new KeyValuePair <string, object>("key", "value"); IPropertySetCollection collection = GetCollection(); collection.Add(item); Assert.IsTrue(collection.Contains(item)); collection["key"] = "1"; Assert.IsFalse(collection.Contains(item)); }
public void TestAddStringPropertyNoDefaultValueNotAllowNullWithValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value", new StringSchema()); string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("value", value); }
public void TestAddValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value"); object v = collection["key"]; Assert.IsNotNull(v); Assert.AreEqual("value", v); }
public void TestAddStringValueNoSchema() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "val"); string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("val", value); }
public void TestAddStringPropertyNoDefaultValueNotAllowNull() { IPropertySetCollection collection = GetCollection(); Assert.Throws <ArgumentException>(() => { collection.Add("key", new StringSchema { AllowNull = false }); }); }
public void TestAddValueTypePropertyNoDefaultValueAllowNull() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true }); int?value = collection.Get <int?>("key"); Assert.IsFalse(value.HasValue); }
public void TestAddKeyValuePair() { KeyValuePair <string, object> item = new KeyValuePair <string, object>("key", "value"); IPropertySetCollection collection = GetCollection(); collection.Add(item); string s = collection.Get <string>("key"); Assert.IsNotNull(s); Assert.AreEqual("value", s); }
public void TestAddStringPropertyNoDefaultValueAllowNull() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true }); string value = collection.Get <string>("key"); Assert.IsNull(value); }
public void TestValueTypeSchemaValidationFailMaxValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true, MaxValue = 10, MinValue = 5 }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", (int?)11); }); }
public void TestAddStringOutsideOfTheirAllowedValuesViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true, PossibleValues = new[] { "one", "two", "tree" } }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", "1"); }); }
public void TestAddValueTypeOutsideOfTheSetOfAllowedValuesViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true, PossibleValues = new int?[] { 2, 3, 4 } }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", (int?)1); }); }
public void TestStringSchemaValidationFailMaxValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true, MaxLength = 10, MinLength = 5 }); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", "123456789012345"); }); }
public void TestValueTypeSchemaValidationSuccess() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true, MaxValue = 10, MinValue = 5 }); collection.Set("key", (int?)6); int?value = collection.Get <int>("key"); Assert.IsNotNull(value); Assert.AreEqual(6, value); }
public void TestStringGetValueViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true }); collection.Set("key", "value"); object value = collection["key"]; Assert.IsNotNull(value); Assert.AreEqual("value", value); }
public void TestStringSchemaValidationSuccess() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true, MaxLength = 10, MinLength = 5 }); collection.Set("key", "123456"); string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("123456", value); }
public void TestSValueTypeGetValueViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true }); collection.Set("key", (int?)100); object value = collection["key"]; Assert.IsNotNull(value); Assert.AreEqual(100, value); }
public void TestTryGetValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value"); object v; Assert.IsTrue(collection.TryGetValue("key", out v)); Assert.IsNotNull(v); Assert.AreEqual("value", v); Assert.IsFalse(collection.TryGetValue("key1", out v)); Assert.IsNull(v); }
public void TestPropertyAddIntNoSchema() { IPropertySetCollection provider = GetValueProvider(); provider.Set("n", (int?)100); provider.Set("n", "hello"); provider.Add("val", 100, new IntSchema()); provider.Add("val1", "100", new StringSchema()); int?result = provider.Get <int?>("val"); Assert.IsNotNull(result); Assert.AreEqual(100, result.Value); provider["val"] = 300; object val = provider["val"]; Assert.IsNotNull(val); result = val as int?; Assert.IsNotNull(result); Assert.AreEqual(300, result.Value); }
public void TestAddObjectValueNoSchema() { IPropertySetCollection collection = GetCollection(); Person p = new Person { FirstName = "John", LastName = "Doe" }; collection.Add("key", p); Person pr = collection.Get <Person>("key"); Assert.IsNotNull(pr); Assert.AreEqual(p.FirstName, pr.FirstName); Assert.AreEqual(p.LastName, pr.LastName); }
public void TestStringSetValueViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true }); string value = collection.Get <string>("key"); Assert.IsNull(value); collection["key"] = "value"; value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("value", value); }
public void TestValueTypeSetValueViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true }); int?value = collection.Get <int?>("key"); Assert.IsFalse(value.HasValue); collection["key"] = 100; value = collection.Get <int>("key"); Assert.IsNotNull(value); Assert.AreEqual(100, value); }
public void TestAddValueTypePropertyWithDefaultValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { DefaultValue = 5 }); int?value = collection.Get <int?>("key"); Assert.IsNotNull(value); Assert.AreEqual(5, value); IValueSchema <object> s = collection.Schemas.GetSchema("key"); Assert.IsNotNull(s); Assert.AreEqual(typeof(int?), s.Type); }
public void TestAddStringPropertyWithDefaultValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { DefaultValue = "default" }); string value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("default", value); IValueSchema <object> s = collection.Schemas.GetSchema("key"); Assert.IsNotNull(s); Assert.AreEqual(typeof(string), s.Type); }
public void TestStringSetInvalidTypeViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new StringSchema { AllowNull = true }); string value = collection.Get <string>("key"); Assert.IsNull(value); collection["key"] = "value"; value = collection.Get <string>("key"); Assert.IsNotNull(value); Assert.AreEqual("value", value); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", (int?)200); }); }
public void TestValueTypeSetInvalidTypeViaDictionary() { IPropertySetCollection collection = GetCollection(); collection.Add("key", new IntSchema { AllowNull = true }); int?value = collection.Get <int?>("key"); Assert.IsFalse(value.HasValue); collection["key"] = 100; value = collection.Get <int>("key"); Assert.IsNotNull(value); Assert.AreEqual(100, value); Assert.Throws <PropertyValidationException>(() => { collection.Set("key", "hello"); }); }
public void TestPropertyAddIntWithSchemaDefaultVal() { IPropertySetCollection provider = GetValueProvider(); provider.Add("val1", new IntSchema { DefaultValue = 40 }); int?result = provider.Get <int?>("val1"); Assert.IsNotNull(result); Assert.AreEqual(40, result.Value); object val = provider["val1"]; Assert.IsNotNull(val); result = val as int?; Assert.IsNotNull(result); Assert.AreEqual(40, result.Value); }
public void TestRemoveValue() { IPropertySetCollection collection = GetCollection(); collection.Add("key", "value"); object v = collection["key"]; Assert.IsNotNull(v); Assert.AreEqual("value", v); Assert.IsTrue(collection.Remove("key")); try { v = collection["key"]; Assert.Fail("Exception must be thrown."); } catch (KeyNotFoundException) { } }
/// <summary> /// Setup Properties with Associated Schemas in Property Set Collection /// </summary> /// <param name="collection"><see cref="IPropertySetCollection"/></param> /// <param name="vd"><see cref="VariableDefinition"/></param> public static void SetupVariable(this VariableDefinition vd, IPropertySetCollection collection) { switch (vd.VariableType) { case VariableTypeEnum.Char: var charSchema = collection.Schemas.SchemaFactory.Create(typeof(char)); SetupConstraints <char?>(vd.Constraints, charSchema); collection.Add(vd.Name, charSchema); break; case VariableTypeEnum.Decimal: var doubleSchema = collection.Schemas.SchemaFactory.Create(typeof(double)); SetupConstraints <double?>(vd.Constraints, doubleSchema); collection.Add(vd.Name, doubleSchema); break; case VariableTypeEnum.Int: var intSchema = collection.Schemas.SchemaFactory.Create(typeof(int)); SetupConstraints <int?>(vd.Constraints, intSchema); collection.Add(vd.Name, intSchema); break; case VariableTypeEnum.GroupsList: var groupSchema = new GroupsSchema(); SetupConstraints <string>(vd.Constraints, groupSchema.Wrap()); collection.Add(vd.Name, groupSchema); break; case VariableTypeEnum.RolesList: var rolesSchema = new RolesSchema(); SetupConstraints <string>(vd.Constraints, rolesSchema.Wrap()); collection.Add(vd.Name, rolesSchema); break; case VariableTypeEnum.UsersList: var usersSchema = new UsersSchema(); SetupConstraints <string>(vd.Constraints, usersSchema.Wrap()); collection.Add(vd.Name, usersSchema); break; case VariableTypeEnum.String: var stringSchema = collection.Schemas.SchemaFactory.Create(typeof(string)); SetupConstraints <string>(vd.Constraints, stringSchema); collection.Add(vd.Name, stringSchema); break; case VariableTypeEnum.Object: var objectSchema = collection.Schemas.SchemaFactory.Create(typeof(object)); SetupConstraints <object>(vd.Constraints, objectSchema); collection.Add(vd.Name, objectSchema); break; case VariableTypeEnum.Json: var jsonSchema = collection.Schemas.SchemaFactory.Create(typeof(string)); SetupConstraints <string>(vd.Constraints, jsonSchema); collection.Add(vd.Name, jsonSchema); break; case VariableTypeEnum.Boolean: var boolSchema = collection.Schemas.SchemaFactory.Create(typeof(bool)); SetupConstraints <bool?>(vd.Constraints, boolSchema); collection.Add(vd.Name, boolSchema); break; case VariableTypeEnum.None: break; } }