Example #1
0
        public void AsTypedEnumerableAsync()
        {
            SetupAndAssert(async dbCmd =>
            {
                IManagedEnumerable <CategoryAsClass> result = await dbCmd
                                                              .CommandType(CommandType.Text)
                                                              .CommandText(@"select * from main.[Category]")
                                                              .AsEnumerableAsync <CategoryAsClass>()
                                                              .ConfigureAwait(false);

                ManagedEnumerable <CategoryAsClass> enumerable = result as ManagedEnumerable <CategoryAsClass>;
                Assert.False(enumerable.Diposed);

                using (result)
                {
                    Assert.NotNull(result);
                    int count = 0;

                    foreach (CategoryAsClass item in result)
                    {
                        count++;
                        Assert.True(item.Id >= 0);
                        Assert.True(!string.IsNullOrEmpty(item.CategoryName));
                        Assert.True(!string.IsNullOrEmpty(item.Description));
                    }

                    Assert.Equal(8, count);

                    // Command and Reader should be cleaned up at this point.
                    Assert.ThrowsAny <NullReferenceException>(() => result.Count());
                    Assert.True(enumerable.Diposed);
                }
            });
        }
Example #2
0
        public void ExecuteFirst_NoResults()
        {
            SetupAndAssert(dbCmd =>
            {
                IManagedEnumerable <dynamic> result = dbCmd
                                                      .CommandType(CommandType.Text)
                                                      .CommandText(@"select * from main.[Category] where Id = 20")
                                                      .AsEnumerable();

                ManagedEnumerable enumerable = result as ManagedEnumerable;
                Assert.False(enumerable.Diposed);

                Assert.ThrowsAny <InvalidOperationException>(() => result.ExecuteFirst());

                Assert.True(enumerable.Diposed);
            });
        }
Example #3
0
        public void ExecuteSingle()
        {
            SetupAndAssert(dbCmd =>
            {
                IManagedEnumerable <dynamic> result = dbCmd
                                                      .CommandType(CommandType.Text)
                                                      .CommandText(@"select * from main.[Category] where Id = 1")
                                                      .AsEnumerable();

                ManagedEnumerable enumerable = result as ManagedEnumerable;
                Assert.False(enumerable.Diposed);

                var tmp = result.ExecuteSingle();

                Assert.NotNull(tmp);
                Assert.True(enumerable.Diposed);
            });
        }
Example #4
0
        public void AsDynamicEnumerableAsync_Cancel()
        {
            SetupAndAssert(async dbCmd =>
            {
                CancellationTokenSource cts = new CancellationTokenSource();
                CancellationToken token     = cts.Token;

                IManagedEnumerable <dynamic> result = await dbCmd
                                                      .CommandType(CommandType.Text)
                                                      .CommandText(@"select * from main.[Category]")
                                                      .CancellationToken(token)
                                                      .AsEnumerableAsync()
                                                      .ConfigureAwait(false);

                ManagedEnumerable enumerable = result as ManagedEnumerable;
                Assert.False(enumerable.Diposed);

                using (result)
                {
                    Assert.NotNull(result);
                    int count = 0;

                    foreach (dynamic item in result)
                    {
                        count++;
                        Assert.IsType <long>(item.Id);
                        Assert.IsType <string>(item.CategoryName);
                        Assert.IsType <string>(item.Description);

                        Assert.True(item.Id >= 0);
                        Assert.True(!string.IsNullOrEmpty(item.CategoryName));
                        Assert.True(!string.IsNullOrEmpty(item.Description));
                        cts.Cancel();
                    }

                    Assert.Equal(1, count);

                    // Command and Reader should be cleaned up at this point.
                    Assert.ThrowsAny <NullReferenceException>(() => result.Count());
                    Assert.True(enumerable.Diposed);
                }
            });
        }
Example #5
0
        public void AsTypedEnumerable_Cancel()
        {
            SetupAndAssert(dbCmd =>
            {
                CancellationTokenSource cts = new CancellationTokenSource();
                CancellationToken token     = cts.Token;

                IManagedEnumerable <CategoryAsClass> result = dbCmd
                                                              .CommandType(CommandType.Text)
                                                              .CommandText(@"select * from main.[Category]")
                                                              .CancellationToken(token)
                                                              .AsEnumerable <CategoryAsClass>();

                ManagedEnumerable <CategoryAsClass> enumerable = result as ManagedEnumerable <CategoryAsClass>;
                Assert.False(enumerable.Diposed);

                using (result)
                {
                    Assert.NotNull(result);
                    int count = 0;

                    foreach (CategoryAsClass item in result)
                    {
                        count++;
                        Assert.True(item.Id >= 0);
                        Assert.True(!string.IsNullOrEmpty(item.CategoryName));
                        Assert.True(!string.IsNullOrEmpty(item.Description));
                        cts.Cancel();
                    }

                    Assert.Equal(1, count);;

                    // Command and Reader should be cleaned up at this point.
                    Assert.ThrowsAny <NullReferenceException>(() => result.Count());
                    Assert.True(enumerable.Diposed);
                }
            });
        }
Example #6
0
        public void AsDynamicEnumerable()
        {
            SetupAndAssert(dbCmd =>
            {
                IManagedEnumerable <dynamic> result = dbCmd
                                                      .CommandType(CommandType.Text)
                                                      .CommandText(@"select * from main.[Category]")
                                                      .AsEnumerable();

                ManagedEnumerable enumerable = result as ManagedEnumerable;
                Assert.False(enumerable.Diposed);

                using (result)
                {
                    Assert.NotNull(result);
                    int count = 0;

                    foreach (dynamic item in result)
                    {
                        count++;
                        Assert.IsType <long>(item.Id);
                        Assert.IsType <string>(item.CategoryName);
                        Assert.IsType <string>(item.Description);

                        Assert.True(item.Id >= 0);
                        Assert.True(!string.IsNullOrEmpty(item.CategoryName));
                        Assert.True(!string.IsNullOrEmpty(item.Description));
                    }

                    Assert.Equal(8, count);

                    // Command and Reader should be cleaned up at this point.
                    Assert.ThrowsAny <NullReferenceException>(() => result.Count());
                    Assert.True(enumerable.Diposed);
                }
            });
        }