public async Task ConstructorSqlToTable() { var c = new ConfigValues() { StorageAccountConnection = "UseDevelopmentStorage=true;", SqlConnection = "Server=localhost;Database=King.BTrak.Data;Trusted_Connection=True;", SqlTableName = "TableData", StorageTableName = "sqlserverdata", Direction = Direction.SqlToTable, }; var id = Guid.NewGuid(); var data = Guid.NewGuid(); var statement = string.Format("INSERT INTO [dbo].[TestSqlToTable] ([Id], [Data]) VALUES ('{0}', '{1}');", id, data); var executor = new Executor(new SqlConnection(c.SqlConnection)); await executor.NonQuery(statement); var s = new Synchronizer(c); await s.Run(); await executor.NonQuery("TRUNCATE TABLE [dbo].[TestSqlToTable]"); var table = new TableStorage(c.StorageTableName, c.StorageAccountConnection); var e = await table.QueryByPartitionAndRow("[dbo].[TestSqlToTable]", id.ToString()); Assert.IsNotNull(e); Assert.AreEqual(data, e["Data"]); }
public async Task ConstructorTableToSql() { var c = new ConfigValues() { StorageAccountConnection = "UseDevelopmentStorage=true;", SqlConnection = "Server=localhost;Database=King.BTrak.Data;Trusted_Connection=True;", SqlTableName = "TableData", StorageTableName = "sqlserverdata", Direction = Direction.TableToSql, }; var tableName = "testsynctabletosql"; var table = new TableStorage(tableName, c.StorageAccountConnection); await table.CreateIfNotExists(); var entity = new TableEntity { PartitionKey = Guid.NewGuid().ToString(), RowKey = Guid.NewGuid().ToString(), }; await table.InsertOrReplace(entity); var s = new Synchronizer(c); await s.Run(); await table.Delete(); var statement = string.Format("SELECT 1 AS [Exists] FROM [dbo].[TableData] WHERE TableName='{0}' AND PartitionKey = '{1}' AND RowKey = '{2}';", tableName, entity.PartitionKey, entity.RowKey); var executor = new Executor(new SqlConnection(c.SqlConnection)); var ds = await executor.Query(statement); var r = ds.Model<DataRow>(); Assert.IsNotNull(r); Assert.IsTrue(r.Exists); }
/// <summary> /// Default Constructor /// </summary> /// <param name="config">Configuration Values</param> public Synchronizer(IConfigValues config) { if (null == config) { throw new ArgumentNullException("config"); } var sqlSchemaReader = new SchemaReader(config.SqlConnection); var executor = new Executor(new SqlConnection(config.SqlConnection)); this.direction = config.Direction; switch (config.Direction) { case Direction.TableToSql: this.tableReader = new TableStorageReader(new AzureStorageResources(config.StorageAccountConnection), config.StorageTableName); this.sqlWriter = new SqlDataWriter(sqlSchemaReader, executor, config.SqlTableName); break; case Direction.SqlToTable: this.sqlReader = new SqlDataReader(executor, sqlSchemaReader, new DynamicLoader(), config.SqlTableName); this.tableWriter = new TableStorageWriter(new TableStorage(config.StorageTableName, config.StorageAccountConnection)); break; default: throw new ArgumentException("Invalid Direction."); } }
public async Task InsertCommand() { var random = new Random(); var sproc = new dboSimulatedInsertStatement() { TestInt = random.Next(), }; using (var con = new SqlConnection(connectionString)) { var executor = new Executor(con); var results = await executor.NonQuery(sproc.Build(con)); Assert.AreEqual(1, results); } }
public async Task InsertConnectitonHandedOff() { var random = new Random(); var executor = new Executor(new SqlConnection(connectionString)); for (var i = 0; i < random.Next(1000, 2000); i++) { var sproc = new dboSimulatedInsertStatement() { TestInt = random.Next(), }; var results = await executor.NonQuery(sproc); Assert.AreEqual(1, results); } }
public async Task DataReader() { var connection = new SqlConnection(); var e = new Executor(connection); await e.DataReader(null); }
public async Task QueryStatementNull() { var connection = new SqlConnection(); var e = new Executor(connection); await e.Query((string)null); }
public async Task QueryCommandNull() { var connection = new SqlConnection(); var e = new Executor(connection); await e.Query((SqlCommand)null); }
public async Task QuerySprocNull() { var connection = new SqlConnection(); var e = new Executor(connection); await e.Query((IStoredProcedure)null); }
public async Task InsertStatement() { var random = new Random(); var statement = string.Format("EXECUTE [dbo].[SimulatedInsertStatement] @TestInt={0};", random.Next()); using (var con = new SqlConnection(connectionString)) { var executor = new Executor(con); var results = await executor.NonQuery(statement); Assert.AreEqual(1, results); } }
public async Task DataReader() { var sproc = SimulatedSelectStatement.Create(); using (var con = new SqlConnection(connectionString)) { var executor = new Executor(con); var reader = await executor.DataReader(sproc); Assert.IsNotNull(reader); Assert.IsTrue(reader.Read()); var obj = reader.Model<SelectData>(); Assert.IsNotNull(obj); Assert.AreEqual(sproc.TestInt, obj.Identifier); Assert.AreEqual(sproc.TestBigInt, obj.BigInt); Assert.AreEqual(sproc.TestBit, obj.Bit); Assert.AreEqual(sproc.TestDate.Value.Date, obj.Date.Date); Assert.AreEqual(sproc.TestDateTime.Value.Date, obj.DateTime.Date); Assert.AreEqual(sproc.TestDateTime2.Value.Date, obj.DateTime2.Date); Assert.AreEqual(sproc.TestDecimal, obj.Decimal); Assert.AreEqual(sproc.TestFloat, obj.Float); Assert.AreEqual(Math.Round((decimal)sproc.TestMoney, 4), obj.Money); Assert.AreEqual(sproc.TestNChar, obj.NChar.ToString()); Assert.AreEqual(sproc.TestNText, obj.NText); Assert.AreEqual(sproc.TestText, obj.Text); CollectionAssert.AreEqual(sproc.TestBinary, obj.Binary); CollectionAssert.AreEqual(sproc.TestImage, obj.Image); Assert.AreEqual(sproc.TestGuid, obj.Unique); } }
public async Task SelectStatement() { var random = new Random(); var id = random.Next(); var unique = Guid.NewGuid(); var statement = string.Format("SELECT {0} AS [Identifier];", id, unique); using (var con = new SqlConnection(connectionString)) { var executor = new Executor(con); var data = await executor.Query(statement); Assert.IsNotNull(data); var obj = data.Model<SelectData>(); Assert.IsNotNull(obj); Assert.AreEqual(id, obj.Identifier); } }