Exemplo n.º 1
0
        public void DeleteByTableName([DataSources] string context)
        {
            var tableName = InsertTests.GetTableName(context, "1a");

            using (var db = GetDataContext(context))
                using (var table = db.CreateLocalTable <Person>(tableName))
                {
                    var iTable = (ITable <Person>)table;
                    Assert.AreEqual(tableName, iTable.TableName);
                    Assert.AreEqual(null, iTable.SchemaName);

                    var person = new Person()
                    {
                        FirstName = "Steven",
                        LastName  = "King",
                        Gender    = Gender.Male,
                    };

                    // insert a row into the table
                    db.Insert(person, tableName);
                    var newCount = table.Count();
                    Assert.AreEqual(1, newCount);

                    var personForDelete = table.Single();

                    db.Delete(personForDelete, tableName);

                    Assert.AreEqual(0, table.Count());
                }
        }
Exemplo n.º 2
0
        public async Task DeleteByTableNameAsync([DataSources] string context)
        {
            const string schemaName = null;
            var          tableName  = InsertTests.GetTableName(context, "30");

            using (var db = GetDataContext(context))
            {
                await db.DropTableAsync <Person>(tableName, schemaName : schemaName, throwExceptionIfNotExists : false);

                try
                {
                    var table = await db.CreateTableAsync <Person>(tableName, schemaName : schemaName);

                    Assert.AreEqual(tableName, table.TableName);
                    Assert.AreEqual(schemaName, table.SchemaName);

                    var person = new Person()
                    {
                        FirstName = "Steven",
                        LastName  = "King",
                        Gender    = Gender.Male,
                    };

                    // insert a row into the table
                    await db.InsertAsync(person, tableName : tableName, schemaName : schemaName);

                    var newCount = await table.CountAsync();

                    Assert.AreEqual(1, newCount);

                    var personForDelete = await table.SingleAsync();

                    await db.DeleteAsync(personForDelete, tableName : tableName, schemaName : schemaName);

                    Assert.AreEqual(0, await table.CountAsync());

                    await table.DropAsync();
                }
                catch
                {
                    await db.DropTableAsync <Person>(tableName, schemaName : schemaName);

                    throw;
                }
            }
        }
Exemplo n.º 3
0
        public async Task UpdateByTableNameAsync([DataSources] string context)
        {
            const string schemaName = null;
            var          tableName  = InsertTests.GetTableName(context, "33");

            using (var db = GetDataContext(context))
            {
                await db.DropTableAsync <Patient>(tableName, schemaName : schemaName, throwExceptionIfNotExists : false);
            }

            using (var db = GetDataContext(context))
            {
                var table = await db.CreateTableAsync <Person>(tableName, schemaName : schemaName);

                Assert.AreEqual(tableName, table.TableName);
                Assert.AreEqual(schemaName, table.SchemaName);

                var person = new Person()
                {
                    FirstName = "Steven",
                    LastName  = "King",
                    Gender    = Gender.Male,
                };

                // insert a row into the table
                await db.InsertAsync(person, tableName : tableName, schemaName : schemaName);

                var newCount = await table.CountAsync();

                Assert.AreEqual(1, newCount);

                var personForUpdate = await table.SingleAsync();

                // update that row
                personForUpdate.MiddleName = "None";
                await db.UpdateAsync(personForUpdate, tableName : tableName, schemaName : schemaName);

                var updatedPerson = await table.SingleAsync();

                Assert.AreEqual("None", updatedPerson.MiddleName);

                await table.DropAsync();
            }
        }