public void Inserts_strings_and_timestamp()
 {
     var buffer = new AtsNamedValueBuffer(new Dictionary<string, EntityProperty>());
     var stamp = DateTime.UtcNow;
     buffer.Add("RowKey", "string data");
     buffer.Add("Timestamp", stamp);
     Assert.Equal("string data", buffer["RowKey"]);
     Assert.Equal(stamp, buffer["Timestamp"]);
 }
        public void Reader_uses_default_clr_for_unmapped_properties()
        {
            var entityType = new EntityType("TestType");
            entityType.AddProperty("BoolProp", typeof(bool));

            var buffer = new AtsNamedValueBuffer(new Dictionary<string, EntityProperty>());
            var reader = _factory.Create(entityType, buffer);

            Assert.False(reader.ReadValue<bool>(0));
            Assert.True(reader.IsNull(0));
        }
        public void Indexed_by_name()
        {
            var buffer = new AtsNamedValueBuffer(new Dictionary<string, EntityProperty>());

            Assert.Throws<KeyNotFoundException>(() => buffer["Key"]);
            Assert.Null(buffer.TryGet("Key"));

            Assert.DoesNotThrow(() => buffer.Add("Key", "value"));

            Assert.DoesNotThrow(() => buffer["Key"]);
            Assert.NotNull(buffer.TryGet("Key"));
        }
        public virtual IValueReader Create([NotNull] IEntityType type, [NotNull] AtsNamedValueBuffer source)
        {
            Check.NotNull(type, "type");
            Check.NotNull(source, "source");

            var valueBuffer = new object[type.Properties.Count];

            foreach (var property in type.Properties)
            {
                valueBuffer[property.Index] = source.TryGet(property.ColumnName());
            }
            return(new AtsObjectArrayValueReader(valueBuffer));
        }
        public void Reader_contains_nulls_for_unmatched_properties()
        {
            var entityType = new EntityType("TestType");
            entityType.AddProperty("Prop1", typeof(string));
            entityType.AddProperty("Prop2", typeof(int));
            var buffer = new AtsNamedValueBuffer(new Dictionary<string, EntityProperty>());
            var reader = _factory.Create(entityType, buffer);

            Assert.Equal(2, reader.Count);
            Assert.True(reader.IsNull(0));
            Assert.True(reader.IsNull(1));
            Assert.DoesNotThrow(() => reader.ReadValue<string>(0));
        }
 public void It_constructs_from_entity_dictionary()
 {
     var data = new Dictionary<string, EntityProperty>
         {
             { "string", new EntityProperty("string") },
             { "double", new EntityProperty(324.34d) },
             { "byte", new EntityProperty(new byte[] { 4, 8, 15, 16, 23, 42 }) },
             { "long", new EntityProperty(429496729623) }
         };
     var buffer = new AtsNamedValueBuffer(data);
     foreach (var property in data)
     {
         Assert.Equal(data[property.Key].PropertyAsObject, buffer[property.Key]);
     }
 }
        public void It_gets_value_by_storage_name()
        {
            var entityType = new EntityType("TestType");
            var property = entityType.AddProperty("ClrName", typeof(object));
            property.SetColumnName("StorageName");

            var data = new Dictionary<string, EntityProperty>
                {
                    { "StorageName", new EntityProperty(3987) },
                    { "ClrName", new EntityProperty(0) },
                };
            var buffer = new AtsNamedValueBuffer(data);

            var reader = _factory.Create(entityType, buffer);

            Assert.Equal(1, reader.Count);
            Assert.Equal(3987, reader.ReadValue<int>(0));
        }
        public void Reader_does_not_contain_ignored_properties()
        {
            var entityType = new EntityType("TestType");
            entityType.AddProperty("Prop1", typeof(string));
            entityType.AddProperty("Prop2", typeof(int));
            var data = new Dictionary<string, EntityProperty>
                {
                    { "Prop2", new EntityProperty(3) },
                    { "IgnoreA", new EntityProperty(1) },
                    { "IgnoreB", new EntityProperty(2) },
                    { "Prop1", new EntityProperty("0") },
                    { "IgnoreZ", new EntityProperty(4) },
                };
            var buffer = new AtsNamedValueBuffer(data);

            var reader = _factory.Create(entityType, buffer);

            Assert.Equal(2, reader.Count);
            Assert.Equal("0", reader.ReadValue<string>(0));
            Assert.Equal(3, reader.ReadValue<int>(1));
        }