Table Data
Inheritance: TableData
Ejemplo n.º 1
0
        public async Task StoreNoPK()
        {
            var rows = new List<IDictionary<string, object>>();
            var row = new Dictionary<string, object>();
            rows.Add(row);
            var data = new TableSqlData()
            {
                PrimaryKeyColumns = null,
                Rows = rows,
                TableName = Guid.NewGuid().ToString(),
            };

            var tables = new List<TableSqlData>();
            tables.Add(data);

            var table = Substitute.For<ITableStorage>();
            table.InsertOrReplace(row);

            var writer = new TableStorageWriter(table);
            await writer.Store(tables);

            Assert.AreEqual(data.TableName, row[TableStorage.PartitionKey]);
            Assert.IsNotNull(row[TableStorage.RowKey]);
            Assert.AreNotEqual(Guid.Empty, Guid.Parse((string)row[TableStorage.RowKey]));

            table.Received().InsertOrReplace(row);
        }
Ejemplo n.º 2
0
        public void PrimaryKeyColumns()
        {
            var expected = new List<string>();
            var c = new TableSqlData
            {
                PrimaryKeyColumns = expected,
            };

            Assert.AreEqual(expected, c.PrimaryKeyColumns);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve Table Data
        /// </summary>
        /// <param name="schemas">Schemas</param>
        /// <returns>Table Data</returns>
        public virtual async Task<IEnumerable<TableSqlData>> Retrieve(IEnumerable<IDefinition> schemas)
        {
            var tables = new List<TableSqlData>();
            foreach (var schema in schemas)
            {
                var sql = string.Format(SqlStatements.SelectDataFormat, schema.Preface, schema.Name);

                Trace.TraceInformation("Loading data from [{0}].[{1}]", schema.Preface, schema.Name);

                var ds = await this.executor.Query(sql);

                var data = new TableSqlData
                {
                    Rows = this.loader.Dictionaries(ds),
                    TableName = string.Format("[{0}].[{1}]", schema.Preface, schema.Name),
                    PrimaryKeyColumns = from v in schema.Variables
                          where v.IsPrimaryKey
                          select v.ParameterName,
                };
                tables.Add(data);

                Trace.TraceInformation("Rows Read: {0}", data.Rows.Count());
            }

            return tables;
        }
Ejemplo n.º 4
0
        public async Task Store()
        {
            var pks = new List<string>();
            var pkName = Guid.NewGuid().ToString();
            pks.Add(pkName);
            var pk = Guid.NewGuid().ToString();

            var rows = new List<IDictionary<string, object>>();
            var row = new Dictionary<string, object>();
            row.Add(pkName, pk);
            rows.Add(row);
            var data = new TableSqlData()
            {
                PrimaryKeyColumns = pks,
                Rows = rows,
                TableName = Guid.NewGuid().ToString(),
            };

            var tables = new List<TableSqlData>();
            tables.Add(data);

            var table = Substitute.For<ITableStorage>();
            table.InsertOrReplace(row);

            var writer = new TableStorageWriter(table);
            await writer.Store(tables);

            Assert.AreEqual(data.TableName, row[TableStorage.PartitionKey]);
            Assert.AreEqual(pk, row[TableStorage.RowKey]);

            table.Received().InsertOrReplace(row);
        }