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); }
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)); }
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)); }
public void InsertReturns1() { var table = new InMemoryTable <Post, int>(new TestConfiguration()); var post = new Post() { Title = "Foo" }; Assert.Equal(1, table.Insert(post)); }
public void DeleteReturns0ForNonExistant() { var table = new InMemoryTable <Post, int>(new TestConfiguration()); var post1 = new Post() { Title = "Foo" }; Assert.Equal(0, table.Delete(post1)); }
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)); }
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); }
public void SaveFixedData(IDataQueue queue) { InMemoryTable tbl = InMemoryTable.FromEnumerable(queue.GetRowFormat, queue.EnumRows()); if (tbl.Rows.Count == 0) { tbl = null; } SaveFixedData(tbl); }
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); }
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])); }
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); }
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()); }
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)); }
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); }
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)); }
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); }
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); }
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); }
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)); }
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); }
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; }
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])); }
public void SaveFixedData(InMemoryTable data) { Reload(); m_table.FixedData = data; SaveToFile(); }
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()); }
public void DeleteReturns0ForNonExistant() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post1 = new Post() { Title = "Foo" }; Assert.Equal(0, table.Delete(post1)); }
public void GetReturnsNull() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); Assert.Null(table.Get(1)); }
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)); }
public void InsertReturns1() { var table = new InMemoryTable<Post, int>(new TestConfiguration()); var post = new Post() { Title = "Foo" }; Assert.Equal(1, table.Insert(post)); }
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); }
public void GetReturnsNull() { var table = new InMemoryTable <Post, int>(new TestConfiguration()); Assert.Null(table.Get(1)); }