コード例 #1
0
        public async Task Search_FOUND()
        {
            try
            {
                // Run the test against one instance of the context
                using (var context = new BloggingContext(Setup.DbOpts))
                {
                    var repository = new DotnetPlayground.Repositories.HashesRepository(context, Setup.Conf, Setup.Cache, Setup.Logger, Setup.ServerTiming);
                    await repository.AddRangeAsync(new[] {
                        new ThinHashes
                        {
                            Key        = "alamakota",
                            HashMD5    = "dc246bcdd6cb3548579770a034d2e678",
                            HashSHA256 = "63b347973bb99fed9277b33cb4646b205e9a31331acfa574add3d2351f445e43"
                        },
                        new ThinHashes
                        {
                            Key        = "fakefakef",
                            HashMD5    = "fakefakefakefakefakefakefakefake",
                            HashSHA256 = "fakefakefakefakefakefakefakefakefakefakefakefakefakefakefakefake"
                        }
                    });

                    await repository.SaveAsync();
                }

                using (var context = new BloggingContext(Setup.DbOpts))
                {
                    var repository = new DotnetPlayground.Repositories.HashesRepository(context, Setup.Conf, Setup.Cache, Setup.Logger, Setup.ServerTiming);
                    var found      = await repository.PagedSearchAsync("Key", "desc", "fake", 0, 10, CancellationToken);

                    Assert.True(found.Count > 0);
                    Assert.NotEmpty(found.Itemz);
                    Assert.True(1 == found.Itemz.Count());
                    Assert.Equal("fakefakef", found.Itemz.First().Key);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public async Task Paging_lots_of_elements(int itemsCount)
        {
            try
            {
                // Run the test against one instance of the context
                using (var context = new BloggingContext(Setup.DbOpts))
                {
                    var repository = new DotnetPlayground.Repositories.HashesRepository(context, Setup.Conf, Setup.Cache, Setup.Logger, Setup.ServerTiming);
                    var tasks      = new List <Task>(itemsCount + 1);
                    for (int i = 0; i < itemsCount; i++)
                    {
                        tasks.Add(repository.AddRangeAsync(new[] {
                            new ThinHashes
                            {
                                Key        = $"alamakota_{i}",
                                HashMD5    = $"dc246bcdd6cb3548579770a034d2e678_{i}",
                                HashSHA256 = $"63b347973bb99fed9277b33cb4646b205e9a31331acfa574add3d2351f445e43_{i}"
                            },
                            new ThinHashes
                            {
                                Key        = $"fakefakef_{i}",
                                HashMD5    = $"fakefakefakefakefakefakefakefake_{i}",
                                HashSHA256 = $"fakefakefakefakefakefakefakefakefakefakefakefakefakefakefakefake_{i}"
                            }
                        }));
                    }
                    Task.WaitAll(tasks.ToArray());
                    await repository.SaveAsync();
                }

                using (var context = new BloggingContext(Setup.DbOpts))
                {
                    var repository = new DotnetPlayground.Repositories.HashesRepository(context, Setup.Conf, Setup.Cache, Setup.Logger, Setup.ServerTiming);
                    var found      = await repository.PagedSearchAsync("Key", "asc", "fake", 2, 10, CancellationToken);

                    Assert.True(found.Count > 0);
                    Assert.NotEmpty(found.Itemz);
                    Assert.Equal(found.Count, itemsCount);
                    Assert.Equal(10, found.Itemz.Count());
                    Assert.Equal("fakefakef_10", found.Itemz.First().Key);
                    Assert.Equal("fakefakefakefakefakefakefakefakefakefakefakefakefakefakefakefake_10", found.Itemz.First().HashSHA256);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Setup.Conn.Dispose();
            }

            //2nd run
            var db = SetupInMemoryDB();

            db.Wait();
            Setup = db.Result;
            try
            {
                // Run the test against one instance of the context
                using (var context = new BloggingContext(Setup.DbOpts))
                {
                    var repository = new DotnetPlayground.Repositories.HashesRepository(context, Setup.Conf, Setup.Cache, Setup.Logger, Setup.ServerTiming);
                    var tasks      = new List <Task>(itemsCount + 1);
                    for (int i = 0; i < itemsCount; i++)
                    {
                        tasks.Add(repository.AddRangeAsync(new[] {
                            new ThinHashes
                            {
                                Key        = $"alamakota_{i}",
                                HashMD5    = $"dc246bcdd6cb3548579770a034d2e678_{i}",
                                HashSHA256 = $"63b347973bb99fed9277b33cb4646b205e9a31331acfa574add3d2351f445e43_{i}"
                            },
                            new ThinHashes
                            {
                                Key        = $"fakefakef_{i}",
                                HashMD5    = $"fakefakefakefakefakefakefakefake_{i}",
                                HashSHA256 = $"fakefakefakefakefakefakefakefakefakefakefakefakefakefakefakefake_{i}"
                            }
                        }));
                    }
                    Task.WaitAll(tasks.ToArray());
                    await repository.SaveAsync();
                }

                using (var context = new BloggingContext(Setup.DbOpts))
                {
                    var repository = new DotnetPlayground.Repositories.HashesRepository(context, Setup.Conf, Setup.Cache, Setup.Logger, Setup.ServerTiming);
                    var found      = await repository.PagedSearchAsync("Key", "asc", "63b347973bb99f", 2, 10, CancellationToken);

                    Assert.True(found.Count > 0);
                    Assert.NotEmpty(found.Itemz);
                    Assert.Equal(found.Count, itemsCount);
                    Assert.Equal(10, found.Itemz.Count());
                    Assert.Equal("alamakota_10", found.Itemz.First().Key);
                    Assert.Equal("63b347973bb99fed9277b33cb4646b205e9a31331acfa574add3d2351f445e43_10", found.Itemz.First().HashSHA256);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }