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
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the connection string:");
            var connStr = Console.ReadLine();
            CloudStorageAccount storageAccount = null;

            try
            {
                storageAccount = CloudStorageAccount.Parse(connStr);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Invalid connection string : " + connStr + ex.Message);
                return;
            }

            Console.WriteLine("Enter the table name:");
            var tableName = Console.ReadLine();

            TableStorageWriter tableWriter = new TableStorageWriter(connStr, tableName);

            var entities = tableWriter.GetAllEntities();

            foreach (var entity in entities)
            {
                tableWriter.Delete(entity);
            }
            tableWriter.Execute();

            Console.WriteLine("The azure table {0} has been cleared.", tableName)
        }
Ejemplo n.º 3
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.º 4
0
        public async Task Initialize()
        {
            var table = Substitute.For<ITableStorage>();
            table.CreateIfNotExists().Returns(Task.FromResult(true));

            var writer = new TableStorageWriter(table);
            var result = await writer.Initialize();

            Assert.IsTrue(result);
            table.Received().CreateIfNotExists();
        }
Ejemplo n.º 5
0
        public async Task Initialize()
        {
            var table = Substitute.For <ITableStorage>();

            table.CreateIfNotExists().Returns(Task.FromResult(true));

            var writer = new TableStorageWriter(table);
            var result = await writer.Initialize();

            Assert.IsTrue(result);
            table.Received().CreateIfNotExists();
        }
Ejemplo n.º 6
0
        public async Task StoreMultiplePks()
        {
            var pks = new List <string>();

            pks.Add(Guid.NewGuid().ToString());
            pks.Add(Guid.NewGuid().ToString());

            var rows = new List <IDictionary <string, object> >();
            var row  = new Dictionary <string, object>();

            row.Add(pks.ElementAt(0), Guid.NewGuid());
            row.Add(pks.ElementAt(1), Guid.NewGuid());
            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]);
            var pk     = string.Format("{0}_{1}", row.Values.ElementAt(0), row.Values.ElementAt(1));
            var rowKey = row[TableStorage.RowKey];

            Assert.AreEqual(pk, rowKey);

            table.Received().InsertOrReplace(row);
        }
Ejemplo n.º 7
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);
        }