Exemplo n.º 1
0
        private InMemoryTable ChartDataToTable(ChartData data)
        {
            var ts = new TableStructure();

            ts.AddColumn(Texts.Get("s_label"), new DbTypeString());
            foreach (var item in data.ValueDefs)
            {
                ts.AddColumn(item.Label, new DbTypeFloat {
                    Bytes = 8
                });
            }
            var res = new InMemoryTable(ts);

            foreach (var item in data.Items)
            {
                var rec = new ArrayDataRecord(ts);
                rec.SeekValue(0);
                rec.SetString(item.Label);
                for (int i = 0; i < data.ValueDefs.Length; i++)
                {
                    rec.SeekValue(i + 1);
                    rec.SetDouble(item.Values[i]);
                }
                res.Rows.Add(rec);
            }
            return(res);
        }
Exemplo n.º 2
0
 public void InsertWithSameKeyThrows() {
     var table = new InMemoryTable<ThingWithStringPrimaryKey, string>(new TestConfiguration());
     var thing = new ThingWithStringPrimaryKey() { Id = "Foo", Name = "Bar" };
     var dupeThing = new ThingWithStringPrimaryKey() { Id = "Foo", Name = "Car" };
     table.Insert(thing);
     Assert.Throws<Exception>(() => table.Insert(dupeThing));
 }
Exemplo n.º 3
0
        public void InsertNonAutoGeneratedWorks()
        {
            var table = new InMemoryTable <ThingWithStringPrimaryKey, string>(new TestConfiguration());
            var thing = new ThingWithStringPrimaryKey()
            {
                Id = "Foo", Name = "Bar"
            };

            Assert.Equal(1, table.Insert(thing));
        }
Exemplo n.º 4
0
        public void InsertReturns1()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post  = new Post()
            {
                Title = "Foo"
            };

            Assert.Equal(1, table.Insert(post));
        }
Exemplo n.º 5
0
        public void DeleteReturns0ForNonExistant()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post1 = new Post()
            {
                Title = "Foo"
            };

            Assert.Equal(0, table.Delete(post1));
        }
Exemplo n.º 6
0
 public void GetReturnsClone() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post = new Post { Title = "Foo" };
     table.Insert(post);
     var returnedPost = table.Get(1);
     Assert.NotNull(returnedPost);
     Assert.Equal("Foo", returnedPost.Title);
     Assert.False(post == returnedPost);
     Assert.True(post.Equals(returnedPost));
 }
Exemplo n.º 7
0
        public void InsertWithLongWorks() {
            var table = new InMemoryTable<ThingWithLongPrimaryKey, long>(new TestConfiguration());
            var thing = new ThingWithLongPrimaryKey { Name = "Foo" };
            var pk = table.Insert(thing);
            Assert.Equal(1, thing.Id);

            var secondThing = new ThingWithLongPrimaryKey { Name = "Bar" };
            var pk2 = table.Insert(secondThing);
            Assert.Equal(2, secondThing.Id);
        }
Exemplo n.º 8
0
        public void SaveFixedData(IDataQueue queue)
        {
            InMemoryTable tbl = InMemoryTable.FromEnumerable(queue.GetRowFormat, queue.EnumRows());

            if (tbl.Rows.Count == 0)
            {
                tbl = null;
            }
            SaveFixedData(tbl);
        }
Exemplo n.º 9
0
        public void InsertReturnsPrimaryKey()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post  = new Post()
            {
                Title = "Foo"
            };

            table.Insert(post);
            Assert.Equal(1, post.PostId);
        }
Exemplo n.º 10
0
 public void QueryWorks() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post1 = new Post() { Title = "Foo" };
     var post2 = new Post() { Title = "Bar" };
     table.Insert(post1);
     table.Insert(post2);
     var posts = table.Query().ToArray();
     Assert.Equal(2, posts.Length);
     Assert.True(post1.Equals(posts[0]));
     Assert.True(post2.Equals(posts[1]));
 }
Exemplo n.º 11
0
 public void UpdateWorks() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post1 = new Post() { Title = "Foo" };
     table.Insert(post1);
     post1.Title = "Bar";
     table.Update(post1);
     var updatedPost = table.Get(1);
     Assert.False(post1 == updatedPost);
     Assert.True(post1.Equals(updatedPost));
     Assert.Equal("Bar", updatedPost.Title);
 }
Exemplo n.º 12
0
        public void DeleteWorks()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post1 = new Post()
            {
                Title = "Foo"
            };

            table.Insert(post1);
            table.Delete(post1);
            Assert.Empty(table.Query());
        }
Exemplo n.º 13
0
        public void GetReturnsClone()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post  = new Post {
                Title = "Foo"
            };

            table.Insert(post);
            var returnedPost = table.Get(1);

            Assert.NotNull(returnedPost);
            Assert.Equal("Foo", returnedPost.Title);
            Assert.False(post == returnedPost);
            Assert.True(post.Equals(returnedPost));
        }
Exemplo n.º 14
0
        public InMemoryTable BatchTransformation(string[][] batch)
        {
            InMemoryTable table = new InMemoryTable();

            table.HasIdentityColumn = true;
            table.Columns.Add(new InMemoryColumn(col1));
            table.Columns.Add(new InMemoryColumn(col2));
            table.Columns.Add(new InMemoryColumn(col3));

            foreach (string[] row in batch)
            {
                table.Rows.Add(row);
            }
            return(table);
        }
Exemplo n.º 15
0
        public void InsertWithSameKeyThrows()
        {
            var table = new InMemoryTable <ThingWithStringPrimaryKey, string>(new TestConfiguration());
            var thing = new ThingWithStringPrimaryKey()
            {
                Id = "Foo", Name = "Bar"
            };
            var dupeThing = new ThingWithStringPrimaryKey()
            {
                Id = "Foo", Name = "Car"
            };

            table.Insert(thing);
            Assert.Throws <Exception>(() => table.Insert(dupeThing));
        }
Exemplo n.º 16
0
        public virtual int ExecuteTransaction(IEnumerable <InternalEntityEntry> entries)
        {
            Check.NotNull(entries, nameof(entries));

            var rowsAffected = 0;

            _tables.ExchangeValue(ts =>
            {
                rowsAffected = 0;

                foreach (var entry in entries)
                {
                    var entityType = entry.EntityType;

                    Debug.Assert(!entityType.IsAbstract);

                    InMemoryTable table;
                    if (!ts.TryGetValue(entityType, out table))
                    {
                        ts = ts.Add(entityType, table = new InMemoryTable(entityType));
                    }

                    switch (entry.EntityState)
                    {
                    case EntityState.Added:
                        table.Create(entry);
                        break;

                    case EntityState.Deleted:
                        table.Delete(entry);
                        break;

                    case EntityState.Modified:
                        table.Update(entry);
                        break;
                    }

                    rowsAffected++;
                }

                return(ts);
            });

            _logger.LogInformation(rowsAffected, ra => Strings.LogSavedChanges(ra));

            return(rowsAffected);
        }
Exemplo n.º 17
0
        public void UpdateWorks()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post1 = new Post()
            {
                Title = "Foo"
            };

            table.Insert(post1);
            post1.Title = "Bar";
            table.Update(post1);
            var updatedPost = table.Get(1);

            Assert.False(post1 == updatedPost);
            Assert.True(post1.Equals(updatedPost));
            Assert.Equal("Bar", updatedPost.Title);
        }
Exemplo n.º 18
0
        public void InsertWithLongWorks()
        {
            var table = new InMemoryTable <ThingWithLongPrimaryKey, long>(new TestConfiguration());
            var thing = new ThingWithLongPrimaryKey {
                Name = "Foo"
            };
            var pk = table.Insert(thing);

            Assert.Equal(1, thing.Id);

            var secondThing = new ThingWithLongPrimaryKey {
                Name = "Bar"
            };
            var pk2 = table.Insert(secondThing);

            Assert.Equal(2, secondThing.Id);
        }
Exemplo n.º 19
0
        public InMemoryTable GetTable(bool wantdata)
        {
            List <DataRecord> records = new List <DataRecord>();

            foreach (string row in EnumRows())
            {
                records.Add(FieldAnalyser.AnalyseRecord(row));
            }
            var ts = new TableStructure();
            Dictionary <string, int> colindexes = new Dictionary <string, int>();

            // get column collection
            foreach (var rec in records)
            {
                foreach (var fld in rec.Fields)
                {
                    if (colindexes.ContainsKey(fld.Name))
                    {
                        continue;
                    }
                    var col = new ColumnStructure();
                    col.ColumnName       = fld.Name;
                    col.DataType         = new DbTypeString();
                    colindexes[fld.Name] = ts._Columns.Count;
                    ts._Columns.Add(col);
                }
            }
            if (!wantdata)
            {
                return(new InMemoryTable(ts));
            }
            var recs = new List <ArrayDataRecord>();

            foreach (var rec in records)
            {
                var row = new ArrayDataRecord(ts);
                foreach (var fld in rec.Fields)
                {
                    row.SeekValue(colindexes[fld.Name]);
                    row.SetString(fld.Value);
                }
                recs.Add(row);
            }
            return(InMemoryTable.FromEnumerable(ts, recs));
        }
Exemplo n.º 20
0
        public virtual int ExecuteTransaction([NotNull] IEnumerable <StateEntry> stateEntries)
        {
            var rowsAffected = 0;

            _tables.ExchangeValue(ts =>
            {
                rowsAffected = 0;

                foreach (var stateEntry in stateEntries)
                {
                    InMemoryTable table;
                    if (!ts.TryGetValue(stateEntry.EntityType, out table))
                    {
                        ts = ts.Add(stateEntry.EntityType, table = new InMemoryTable());
                    }

                    switch (stateEntry.EntityState)
                    {
                    case EntityState.Added:
                        table.Create(stateEntry);
                        break;

                    case EntityState.Deleted:
                        table.Delete(stateEntry);
                        break;

                    case EntityState.Modified:
                        table.Update(stateEntry);
                        break;
                    }

                    rowsAffected++;
                }

                return(ts);
            });

            _logger.WriteInformation(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "Saved {0} entities to in-memory database.",
                    rowsAffected));

            return(rowsAffected);
        }
Exemplo n.º 21
0
        public override void FillTable(ITableStructure table, IDataQueue queue, TableCopyOptions opts)
        {
            TableStructure dst = null;

            try
            {
                dst = (TableStructure)m_db.Tables[table.FullName];
            }
            catch
            {
                throw new InternalError("DAE-00064 Table not found in target structure:" + table.FullName.ToString());
            }
            InMemoryTable tbl = InMemoryTable.FromEnumerable(queue.GetRowFormat, queue.EnumRows());

            if (tbl.Rows.Count == 0)
            {
                tbl = null;
            }
            dst.FixedData = tbl;
        }
Exemplo n.º 22
0
        public void QueryWorks()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());
            var post1 = new Post()
            {
                Title = "Foo"
            };
            var post2 = new Post()
            {
                Title = "Bar"
            };

            table.Insert(post1);
            table.Insert(post2);
            var posts = table.Query().ToArray();

            Assert.Equal(2, posts.Length);
            Assert.True(post1.Equals(posts[0]));
            Assert.True(post2.Equals(posts[1]));
        }
Exemplo n.º 23
0
 public void SaveFixedData(InMemoryTable data)
 {
     Reload();
     m_table.FixedData = data;
     SaveToFile();
 }
Exemplo n.º 24
0
 public void DeleteWorks() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post1 = new Post() { Title = "Foo" };
     table.Insert(post1);
     table.Delete(post1);
     Assert.Empty(table.Query());
 }
Exemplo n.º 25
0
 public void DeleteReturns0ForNonExistant() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post1 = new Post() { Title = "Foo" };
     Assert.Equal(0, table.Delete(post1));
 }
Exemplo n.º 26
0
 public void GetReturnsNull() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     Assert.Null(table.Get(1));
 }
Exemplo n.º 27
0
 public void InsertNonAutoGeneratedWorks() {
     var table = new InMemoryTable<ThingWithStringPrimaryKey, string>(new TestConfiguration());
     var thing = new ThingWithStringPrimaryKey() { Id = "Foo", Name = "Bar" };
     Assert.Equal(1, table.Insert(thing));
 }
Exemplo n.º 28
0
 public void InsertReturns1() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post = new Post() { Title = "Foo" };
    Assert.Equal(1, table.Insert(post));
 }
Exemplo n.º 29
0
 public void InsertReturnsPrimaryKey() {
     var table = new InMemoryTable<Post, int>(new TestConfiguration());
     var post = new Post() { Title = "Foo" };
     table.Insert(post);
     Assert.Equal(1, post.PostId);
 }
Exemplo n.º 30
0
        public void GetReturnsNull()
        {
            var table = new InMemoryTable <Post, int>(new TestConfiguration());

            Assert.Null(table.Get(1));
        }