Beispiel #1
0
        public void Should_Set_And_Get_Primitive_Values()
        {
            var entity = new MyEntity();

            entity.SetData("Name", "John");
            entity.GetData <string>("Name").ShouldBe("John");

            entity.SetData("Length", 42424242);
            entity.GetData <int>("Length").ShouldBe(42424242);

            entity.SetData("Age", 42);
            Assert.Equal(42, entity.GetData <byte>("Age"));

            entity.SetData("BirthDate", new DateTime(2015, 05, 25, 13, 24, 00, DateTimeKind.Utc));
            Assert.Equal(new DateTime(2015, 05, 25, 13, 24, 00, DateTimeKind.Utc), entity.GetData <DateTime>("BirthDate"));

            entity.GetData <string>("NonExistingValue").ShouldBe(null);
        }
Beispiel #2
0
        public void Should_Support_Inheritance_Of_Complex_Objects()
        {
            var entity = new MyEntity();

            entity.SetData <IAnimal>("MyCat", new Tiger(), true);
            var tiger = entity.GetData <IAnimal>("MyCat", true) as Tiger;

            tiger.ShouldNotBeNull();
        }
Beispiel #3
0
        public void Should_Get_Default_If_Not_Present()
        {
            var entity = new MyEntity();

            entity.GetData <string>("Name").ShouldBe(null);
            entity.GetData <int>("Length").ShouldBe(0);
            entity.GetData <int?>("Length").ShouldBe(null);
            entity.GetData <DateTime>("BirthDate").ShouldBe(new DateTime());
            entity.GetData <DateTime?>("BirthDate").ShouldBe(null);
            Assert.AreEqual(0, entity.GetData <byte>("Age"));
            Assert.AreEqual(null, entity.GetData <byte?>("Age"));
            entity.GetData <MyComplexType>("ComplexData").ShouldBe(null);
        }
Beispiel #4
0
        public void Should_Support_Inheritance_Of_Complex_Objects_Inside_Array()
        {
            var entity = new MyEntity();

            var animals = new AnimalBase[]
            {
                new Cat {
                    Friend = new Lion()
                },
                new Lion(),
                new Tiger()
            };

            entity.SetData("MyAnimals", animals, true);
            var animals2 = entity.GetData <AnimalBase[]>("MyAnimals", true);

            animals2.Length.ShouldBe(3);
            animals2[0].ShouldBeOfType <Cat>();
            animals2[0].As <Cat>().Friend.ShouldBeOfType <Lion>();
            animals2[1].ShouldBeOfType <Lion>();
            animals2[2].ShouldBeOfType <Tiger>();
        }