public void TestEnumToSmallInt() { var e = new ClassWithEnum() { Value = MyEnum.One, NullableValue = MyEnum.Two }; try { _connection.ExecuteSql("CREATE TYPE EnumTestType AS (Value smallint, NullableValue smallint, NullValue smallint)"); _connection.ExecuteSql(@" CREATE OR REPLACE FUNCTION PostgresSQLSmallInt (Value smallint, NullableValue smallint, NullValue smallint) RETURNS SETOF EnumTestType AS $$ BEGIN RETURN QUERY SELECT Value as Value, NullableValue as NullableValue, NullValue as NullValue; END; $$ LANGUAGE plpgsql;" ); var result = _connection.Query <ClassWithEnum>("PostgresSQLSmallInt", e); Assert.AreEqual(MyEnum.One, result.First().Value); Assert.AreEqual(MyEnum.Two, result.First().NullableValue); Assert.AreEqual(null, result.First().NullValue); } finally { try { _connection.ExecuteSql("DROP FUNCTION PostgresSQLSmallInt (i smallint, NullableValue smallint, NullValue smallint)"); } catch { } try { _connection.ExecuteSql("DROP TYPE EnumTestType"); } catch { } } }
public void CanHandleEnums() { var value = new ClassWithEnum(ConsoleColor.DarkCyan); var read = _reader.Read(value); Assert.Equal(1, read.Properties.Count); Assert.Equal(0, read.Properties[0].Properties.Count); }
public void HandlesEnums() { var model = new ClassWithEnum { Nom = Enomnomnom.Yuck }; var result = model.ToParametersDictionary(); Assert.Equal(1, result.Count); Assert.Equal("yuck", result["nom"]); }
public When_created_based_on_object_with_enum_property() { source = new ClassWithEnum { EnumProperty = Custom.Value2, }; dynamicObject = new DynamicObject(source); }
static void Main(string[] args) { var configuration = new DependenciesConfiguration(); configuration.Register <EnumInterface, ClassWithEnum>(false); var provider = new DependencyProvider(configuration); ClassWithEnum obj = (ClassWithEnum)provider.Resolve <EnumInterface>(); }
public void TreatsFirstEnumMemberAsDefault() { var model = new ClassWithEnum(); var result = model.ToParametersDictionary(); Assert.Equal(1, result.Count); Assert.Equal("bland", result["nom"]); }
public void TreatsFirstEnumMemberAsDefault() { var model = new ClassWithEnum(); var result = model.ToParametersDictionary(); Assert.Equal(1, result.Count); Assert.Equal("bland", result["nom"]); }
public void HandlesEnumsWithSpecifiedValue() { var model = new ClassWithEnum { Nom = Enomnomnom.NomNomNom }; var result = model.ToParametersDictionary(); Assert.Equal(1, result.Count); Assert.Equal("noms", result["nom"]); }
public When_created_based_on_object_with_enum_property() { source = new ClassWithEnum { EnumProperty = CustomEnum.Value2 }; dynamicObject = new DynamicObject(source); }
public void SerializeToXml_EnumTest() { var orig = new ClassWithEnum { testEnum = ClassWithEnum.TestEnum.ValueB }; var copy = SerializeDeserialize <ClassWithEnum>(orig); Assert.AreEqual(orig.testEnum, copy.testEnum); }
public void HandlesEnums() { var model = new ClassWithEnum { Nom = Enomnomnom.Yuck }; var result = model.ToParametersDictionary(); Assert.Equal(1, result.Count); Assert.Equal("yuck", result["nom"]); }
public void HandlesEnumsWithSpecifiedValue() { var model = new ClassWithEnum { Nom = Enomnomnom.NomNomNom }; var result = model.ToParametersDictionary(); Assert.Equal(1, result.Count); Assert.Equal("noms", result["nom"]); }
public void ShouldGenerateWithIEnumerable() { var configuration = new DependenciesConfiguration(); configuration.Register <IRepository, RepositoryImpl>(false); configuration.Register <EnumInterface, ClassWithEnum>(false); var provider = new DependencyProvider(configuration); ClassWithEnum obj = (ClassWithEnum)provider.Resolve <EnumInterface>(); Assert.IsNotNull(obj.dEnum); Assert.AreEqual(1, obj.dEnum.Count()); }
public virtual void TestEnum1() { string baseName = GetBaseName(); ODB odb = Open(baseName); ClassWithEnum e = new ClassWithEnum("enum1", ObjectType.Medium); odb.Store(e); odb.Close(); odb = Open(baseName); Objects <ClassWithEnum> objects = odb.GetObjects <ClassWithEnum>(); odb.Close(); AssertEquals(1, objects.Count); }
public void Can_serialize_Enum() { var enumClass = new ClassWithEnum { Color = Color.Red }; var xml = new XmlSerializer(); var doc = xml.Serialize(enumClass); var expected = new XDocument(); var root = new XElement("ClassWithEnum"); root.Add(new XElement("Color", "Red")); expected.Add(root); Assert.AreEqual(expected.ToString(), doc); }
public void PrimitiveInClasses_CanBeSerializedAndDeserialized() { // Arrange var age = 23; var obj = new ClassWithEnum { Age = age }; // act var deserialized = TestHelper.SerializeAndDeserialize(obj); // assert deserialized.Should().NotBeNull(); deserialized.Age.Should().Be(age); }
public void StringBasedEnumTest() { var machine = GetSerializer <ClassWithEnum>(); var source = new ClassWithEnum { EnumValue = MyEnum.First }; string packed = machine.Serialize(source); Debug.Print(packed); var unpacked = machine.Deserialize(packed); unpacked.Should().NotBeNull(); unpacked.EnumValue.Should().Be(MyEnum.First); }
public void EnumInClasses_CanBeSerializedAndDeserialized() { // Arrange var gender = Gender.Male; var obj = new ClassWithEnum { Gender = gender }; // act var deserialized = TestHelper.SerializeAndDeserialize(obj); // assert deserialized.Should().NotBeNull(); deserialized.Gender.Should().Be(gender); }
public void Component_EnumProperty_ResultIsTheSameAsInput() { //Arrange ClassWithEnum toSerialize = _fixture.Create <ClassWithEnum>(); //Act var result = AvroConvert.Serialize(toSerialize); var deserialized = AvroConvert.Deserialize <ClassWithEnum>(result); //Assert Assert.NotNull(result); Assert.NotNull(deserialized); Assert.Equal(toSerialize.EnumProp, deserialized.EnumProp); Assert.Equal(toSerialize, deserialized); }
public void BuiltinEnumConverter_CanBeOverriddenForConcreteEnumType() { var machine = new ShapeshifterSerializer <ClassWithEnum>(new[] { typeof(MyEnumConverter) }, new[] { Assembly.GetExecutingAssembly() }); var source = new ClassWithEnum { EnumValue = MyEnum.First }; string packed = machine.Serialize(source); Debug.Print(packed); var jobj = JObject.Parse(packed).GetValue("EnumValue"); jobj[Constants.TypeNameKey].Value <string>().Should().Be("MyEnumPackname"); jobj[Constants.VersionKey].Value <uint>().Should().Be(1); jobj["MyKey"].Value <int>().Should().Be((int)MyEnum.First); var unpacked = machine.Deserialize(packed); unpacked.Should().NotBeNull(); unpacked.EnumValue.Should().Be(MyEnum.First); }
public virtual void TestEnumUpdate() { string baseName = GetBaseName(); ODB odb = Open(baseName); ClassWithEnum e = new ClassWithEnum("enum1", ObjectType.Medium); odb.Store(e); odb.Close(); odb = Open(baseName); Objects <ClassWithEnum> objects = odb.GetObjects <ClassWithEnum>(); ClassWithEnum cwe = objects.GetFirst(); cwe.SetObjectType(ObjectType.Small); odb.Store(cwe); odb.Close(); odb = Open(baseName); objects = odb.GetObjects <ClassWithEnum>(); AssertEquals(1, objects.Count); cwe = objects.GetFirst(); odb.Close(); AssertEquals(ObjectType.Small, cwe.GetObjectType()); }