Ejemplo n.º 1
0
        public async Task AddRangeAsync_Disposed()
        {
            var expectedResult = new List <FileIndexItem>
            {
                new FileIndexItem {
                    FileHash = "TEST4"
                },
                new FileIndexItem {
                    FileHash = "TEST5"
                }
            };

            var serviceScopeFactory = CreateNewScope();
            var scope             = serviceScopeFactory.CreateScope();
            var dbContextDisposed = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();

            // Dispose here
            await dbContextDisposed.DisposeAsync();

            await new Query(dbContextDisposed,
                            new AppSettings {
                AddMemoryCache = false
            }, serviceScopeFactory, new FakeIWebLogger(), new FakeMemoryCache()).AddRangeAsync(expectedResult);

            var context     = new InjectServiceScope(serviceScopeFactory).Context();
            var queryFromDb = context.FileIndex.Where(p => p.FileHash == "TEST4" || p.FileHash == "TEST5").ToList();

            Assert.AreEqual(expectedResult.FirstOrDefault().FileHash, queryFromDb.FirstOrDefault().FileHash);
            Assert.AreEqual(expectedResult[1].FileHash, queryFromDb[1].FileHash);
        }
Ejemplo n.º 2
0
        public async Task IsHashInImportDbAsync_True()
        {
            var dbContext = new InjectServiceScope(_serviceScope).Context();

            await dbContext.ImportIndex.AddAsync(new ImportIndexItem
            {
                Status = ImportStatus.Ok, FileHash = "TEST2", AddToDatabase = DateTime.UtcNow,
            });

            await dbContext.SaveChangesAsync();

            var result = await _importQuery.IsHashInImportDbAsync("TEST2");

            Assert.IsTrue(result);
        }