Exemplo n.º 1
0
        public async Task TestInsertOrIgnoreAllAsync()
        {
            const string originalFirstName = "foo";
            const string originalLastName  = "bar";

            // create a bunch of customers...
            var customers = new List <Customer2> ();

            for (int index = 0; index < 100; index++)
            {
                var customer = new Customer2();
                customer.Id        = index;
                customer.FirstName = originalFirstName;
                customer.LastName  = originalLastName;
                customer.Email     = Guid.NewGuid().ToString();
                customers.Add(customer);
            }

            // connect...
            SQLiteAsyncConnection conn = GetAsyncConnection();
            await conn.CreateTableAsync <Customer2> ();

            // insert them all...
            await conn.InsertOrIgnoreAllAsync(customers);

            // change the existing ones...
            foreach (var customer in customers)
            {
                customer.FirstName = "baz";
                customer.LastName  = "biz";
            }

            // ... and add a few more
            for (int index = 100; index < 200; index++)
            {
                var customer = new Customer2();
                customer.Id        = index;
                customer.FirstName = originalFirstName;
                customer.LastName  = originalLastName;
                customer.Email     = Guid.NewGuid().ToString();
                customers.Add(customer);
            }

            // insert them all, ignoring the already existing ones
            await conn.InsertOrIgnoreAllAsync(customers);

            // check...
            using (var check = GetSyncConnection()) {
                for (int index = 0; index < customers.Count; index++)
                {
                    // load it back and check...
                    var loaded = check.Get <Customer2> (customers [index].Id);
                    Assert.AreEqual(loaded.FirstName, originalFirstName);
                    Assert.AreEqual(loaded.LastName, originalLastName);
                    Assert.AreEqual(loaded.Email, customers [index].Email);
                }
            }
        }
Exemplo n.º 2
0
        public async Task TestInsertOrIgnoreAsync()
        {
            const string originalFirstName = "foo";
            const string originalLastName  = "bar";

            // create...
            var customer = new Customer2();

            customer.Id        = 42;
            customer.FirstName = originalFirstName;
            customer.LastName  = originalLastName;
            customer.Email     = Guid.NewGuid().ToString();

            // connect...
            SQLiteAsyncConnection conn = GetAsyncConnection();
            await conn.CreateTableAsync <Customer2> ();

            // run...
            await conn.InsertOrIgnoreAsync(customer);

            // check...
            using (var check = GetSyncConnection()) {
                // load it back...
                var loaded = check.Get <Customer2> (customer.Id);
                Assert.AreEqual(loaded.Id, customer.Id);
                Assert.AreEqual(loaded.FirstName, originalFirstName);
                Assert.AreEqual(loaded.LastName, originalLastName);
                Assert.AreEqual(loaded.Email, customer.Email);
            }

            // change ...
            customer.FirstName = "baz";
            customer.LastName  = "biz";

            // insert or ignore...
            await conn.InsertOrIgnoreAsync(customer);

            // check...
            using (var check = GetSyncConnection()) {
                // load it back...
                var loaded = check.Get <Customer2> (customer.Id);
                Assert.AreEqual(loaded.Id, customer.Id);
                Assert.AreEqual(loaded.FirstName, originalFirstName);
                Assert.AreEqual(loaded.LastName, originalLastName);
                Assert.AreEqual(loaded.Email, customer.Email);
            }
        }
Exemplo n.º 3
0
        public async Task TestInsertOrIgnoreAsync ()
        {
            const string originalFirstName = "foo";
            const string originalLastName = "bar";

            // create...
            var customer = new Customer2 ();
            customer.Id = 42;
            customer.FirstName = originalFirstName;
            customer.LastName = originalLastName;
            customer.Email = Guid.NewGuid ().ToString ();

            // connect...
            SQLiteAsyncConnection conn = GetAsyncConnection ();
            await conn.CreateTableAsync<Customer2> ();

            // run...
            await conn.InsertOrIgnoreAsync (customer);

            // check...
            using (var check = GetSyncConnection()) {
                // load it back...
                var loaded = check.Get<Customer2> (customer.Id);
                Assert.AreEqual (loaded.Id, customer.Id);
                Assert.AreEqual (loaded.FirstName, originalFirstName);
                Assert.AreEqual (loaded.LastName, originalLastName);
                Assert.AreEqual (loaded.Email, customer.Email);
            }

            // change ...
            customer.FirstName = "baz";
            customer.LastName = "biz";

            // insert or ignore...
            await conn.InsertOrIgnoreAsync (customer);

            // check...
            using (var check = GetSyncConnection()) {
                // load it back...
                var loaded = check.Get<Customer2> (customer.Id);
                Assert.AreEqual (loaded.Id, customer.Id);
                Assert.AreEqual (loaded.FirstName, originalFirstName);
                Assert.AreEqual (loaded.LastName, originalLastName);
                Assert.AreEqual (loaded.Email, customer.Email);
            }
        }
Exemplo n.º 4
0
        public async Task TestInsertOrIgnoreAllAsync ()
        {
            const string originalFirstName = "foo";
            const string originalLastName = "bar";
            
            // create a bunch of customers...
            var customers = new List<Customer2> ();
            for (int index = 0; index < 100; index++) {
                var customer = new Customer2 ();
                customer.Id = index;
                customer.FirstName = originalFirstName;
                customer.LastName = originalLastName;
                customer.Email = Guid.NewGuid ().ToString ();
                customers.Add (customer);
            }

            // connect...
            SQLiteAsyncConnection conn = GetAsyncConnection ();
            await conn.CreateTableAsync<Customer2> ();

            // insert them all...
            await conn.InsertOrIgnoreAllAsync (customers);

            // change the existing ones...
            foreach (var customer in customers) {
                customer.FirstName = "baz";
                customer.LastName = "biz";
            }

            // ... and add a few more
            for (int index = 100; index < 200; index++) {
                var customer = new Customer2 ();
                customer.Id = index;
                customer.FirstName = originalFirstName;
                customer.LastName = originalLastName;
                customer.Email = Guid.NewGuid ().ToString ();
                customers.Add (customer);
            }

            // insert them all, ignoring the already existing ones
            await conn.InsertOrIgnoreAllAsync (customers);

            // check...
            using (var check = GetSyncConnection()) {
                for (int index = 0; index < customers.Count; index++) {
                    // load it back and check...
                    var loaded = check.Get<Customer2> (customers [index].Id);
                    Assert.AreEqual (loaded.FirstName, originalFirstName);
                    Assert.AreEqual (loaded.LastName, originalLastName);
                    Assert.AreEqual (loaded.Email, customers [index].Email);
                }
            }

        }