Ejemplo n.º 1
0
        public void DbItem_As_Media_Test()
        {
            var created = new DateTime(2012, 01, 01, 0, 0, 0, DateTimeKind.Utc);

            var item = new AttributeCollection {
                { "Transformation", "resize:500x500.jpeg" },
                { "Duration", 30000 },
                { "Created", new DateTimeOffset(created).ToUnixTimeSeconds() }
            };

            item.Add("Hash", new DbValue("FHX8PLDaGoI2hSlwjI1yFvqWTcQ=", DbValueType.B));

            var media = item.As <Media>();

            Assert.Equal("resize:500x500.jpeg", media.Transformation);
            Assert.Equal(TimeSpan.FromSeconds(30), media.Duration);
            Assert.Equal(Convert.FromBase64String("FHX8PLDaGoI2hSlwjI1yFvqWTcQ="), media.Hash);
            Assert.Equal(created, media.Created);

            var attributes = AttributeCollection.FromObject(media);

            Assert.Equal("resize:500x500.jpeg", attributes["Transformation"].Value.ToString());
            Assert.Equal(DbValueType.N, attributes["Duration"].Kind);
            Assert.Equal(DbValueType.N, attributes["Created"].Kind);
        }
Ejemplo n.º 2
0
        public void DbItem_Enum_Test()
        {
            var item = new AttributeCollection {
                { "Type", 1 }
            };

            var record = item.As <Record>();

            Assert.Equal(RecordType.One, record.Type);
        }
Ejemplo n.º 3
0
        public void DbItem_As_Person_Test()
        {
            var item = new AttributeCollection {
                { "Name", "Val" },
                { "Age", 100 }
            };

            var person = item.As <Person>();

            Assert.Equal("Val", person.Name);
            Assert.Equal(100, person.Age);
        }
Ejemplo n.º 4
0
        public void CanSetReadOnlyProperties()
        {
            var item = new AttributeCollection {
                { "id", 234 },
                { "type", "Three" }
            };

            var record = item.As <ReadOnlyRecord>();

            Assert.Equal(234, record.Id);

            Assert.Equal(RecordType.Three, record.Type);
        }