Beispiel #1
0
        public async Task InsertGetUpdateDeleteWithExplicitKeyAsync()
        {
            using (var connection = GetOpenConnection())
            {
                var guid = Guid.NewGuid().ToString();
                var o1   = new ObjectX {
                    ObjectXId = guid, Name = "Foo"
                };
                var originalxCount = (await connection.QueryAsync <int>("Select Count(*) From ObjectX").ConfigureAwait(false)).First();
                await connection.InsertAsync(o1).ConfigureAwait(false);

                var list1 = (await connection.QueryAsync <ObjectX>("select * from ObjectX").ConfigureAwait(false)).ToList();
                list1.Count.IsEqualTo(originalxCount + 1);
                o1 = await connection.GetAsync <ObjectX>(guid).ConfigureAwait(false);

                o1.ObjectXId.IsEqualTo(guid);
                o1.Name = "Bar";
                await connection.UpdateAsync(o1).ConfigureAwait(false);

                o1 = await connection.GetAsync <ObjectX>(guid).ConfigureAwait(false);

                o1.Name.IsEqualTo("Bar");
                await connection.DeleteAsync(o1).ConfigureAwait(false);

                o1 = await connection.GetAsync <ObjectX>(guid).ConfigureAwait(false);

                o1.IsNull();

                const int id = 42;
                var       o2 = new ObjectY {
                    ObjectYId = id, Name = "Foo"
                };
                var originalyCount = connection.Query <int>("Select Count(*) From ObjectY").First();
                await connection.InsertAsync(o2).ConfigureAwait(false);

                var list2 = (await connection.QueryAsync <ObjectY>("select * from ObjectY").ConfigureAwait(false)).ToList();
                list2.Count.IsEqualTo(originalyCount + 1);
                o2 = await connection.GetAsync <ObjectY>(id).ConfigureAwait(false);

                o2.ObjectYId.IsEqualTo(id);
                o2.Name = "Bar";
                await connection.UpdateAsync(o2).ConfigureAwait(false);

                o2 = await connection.GetAsync <ObjectY>(id).ConfigureAwait(false);

                o2.Name.IsEqualTo("Bar");
                await connection.DeleteAsync(o2).ConfigureAwait(false);

                o2 = await connection.GetAsync <ObjectY>(id).ConfigureAwait(false);

                o2.IsNull();
            }
        }
Beispiel #2
0
        public void InsertGetUpdateDeleteWithExplicitKey()
        {
            using (var connection = GetOpenConnection())
            {
                var guid = Guid.NewGuid().ToString();
                var o1   = new ObjectX {
                    ObjectXId = guid, Name = "Foo"
                };
                var originalxCount = connection.Query <int>("Select Count(*) From ObjectX").First();
                connection.Insert(o1);
                var list1 = connection.Query <ObjectX>("select * from ObjectX").ToList();
                list1.Count.IsEqualTo(originalxCount + 1);
                o1 = connection.Get <ObjectX>(guid);
                o1.ObjectXId.IsEqualTo(guid);
                o1.Name = "Bar";
                connection.Update(o1);
                o1 = connection.Get <ObjectX>(guid);
                o1.Name.IsEqualTo("Bar");
                connection.Delete(o1);
                o1 = connection.Get <ObjectX>(guid);
                o1.IsNull();

                const int id = 42;
                var       o2 = new ObjectY {
                    ObjectYId = id, Name = "Foo"
                };
                var originalyCount = connection.Query <int>("Select Count(*) From ObjectY").First();
                connection.Insert(o2);
                var list2 = connection.Query <ObjectY>("select * from ObjectY").ToList();
                list2.Count.IsEqualTo(originalyCount + 1);
                o2 = connection.Get <ObjectY>(id);
                o2.ObjectYId.IsEqualTo(id);
                o2.Name = "Bar";
                connection.Update(o2);
                o2 = connection.Get <ObjectY>(id);
                o2.Name.IsEqualTo("Bar");
                connection.Delete(o2);
                o2 = connection.Get <ObjectY>(id);
                o2.IsNull();
            }
        }
        public async Task InsertGetUpdateDeleteWithExplicitKeyAsync()
        {
            using (var connection = GetOpenConnection())
            {
                var guid = Guid.NewGuid().ToString();
                var o1 = new ObjectX { ObjectXId = guid, Name = "Foo" };
                var originalxCount = (await connection.QueryAsync<int>("Select Count(*) From objectx")).First();
                await connection.InsertAsync(o1);
                var list1 = (await connection.QueryAsync<ObjectX>("select * from objectx")).ToList();
                list1.Count.IsEqualTo(originalxCount + 1);
                o1 = await connection.GetAsync<ObjectX>(guid);
                o1.ObjectXId.IsEqualTo(guid);
                o1.Name = "Bar";
                await connection.UpdateAsync(o1);
                o1 = await connection.GetAsync<ObjectX>(guid);
                o1.Name.IsEqualTo("Bar");
                await connection.DeleteAsync(o1);
                o1 = await connection.GetAsync<ObjectX>(guid);
                o1.IsNull();

                const int id = 42;
                var o2 = new ObjectY { ObjectYId = id, Name = "Foo" };
                var originalyCount = connection.Query<int>("Select Count(*) From objecty").First();
                await connection.InsertAsync(o2);
                var list2 = (await connection.QueryAsync<ObjectY>("select * from objecty")).ToList();
                list2.Count.IsEqualTo(originalyCount+1);
                o2 = await connection.GetAsync<ObjectY>(id);
                o2.ObjectYId.IsEqualTo(id);
                o2.Name = "Bar";
                await connection.UpdateAsync(o2);
                o2 = await connection.GetAsync<ObjectY>(id);
                o2.Name.IsEqualTo("Bar");
                await connection.DeleteAsync(o2);
                o2 = await connection.GetAsync<ObjectY>(id);
                o2.IsNull();
            }
        }