public void ShouldTruncateAllDataOnRequest()
        {
            var repo = new Repository();
            var file = new File {
                Path = "TestPath", Name = "TestFile1.txt"
            };
            var word = new Word {
                Term = Guid.NewGuid().ToString()
            };
            var fileWord = new FileWord {
                File = file, Word = word
            };

            repo.SaveEntitiesAsync(new[] { fileWord }, new[] { file }, new[] { word }).Wait();
            using (var context = new FileWordsDataflowDbContext())
            {
                Assert.IsTrue(context.Files.Any() && context.Words.Any() && context.FileWords.Any());
            }

            repo.TruncateDataAsync().Wait();
            using (var context = new FileWordsDataflowDbContext())
            {
                Assert.IsTrue(!context.Files.Any() && !context.Words.Any() && !context.FileWords.Any());
            }
        }
 public async Task TruncateDataAsync()
 {
     using (var context = new FileWordsDataflowDbContext())
     {
         await context.Database.ExecuteSqlCommandAsync("DELETE FROM [FileWords]");
         await context.Database.ExecuteSqlCommandAsync("DELETE FROM [Files]");
         await context.Database.ExecuteSqlCommandAsync("DELETE FROM [Words]");
     }
 }
 public async Task SaveEntitiesAsync(
     IEnumerable<FileWord> fileWords, 
     IEnumerable<File> files,
     IEnumerable<Word> words)
 {
     using (var context = new FileWordsDataflowDbContext())
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         context.Configuration.ValidateOnSaveEnabled = false;
         context.Files.AddRange(files);
         context.Words.AddRange(words);
         context.FileWords.AddRange(fileWords);
         await context.SaveChangesAsync();
     }
 }
        public async Task<IList<FileWordStats>> GetFileWordStatsAsync(int skip, int take)
        {
            using (var context = new FileWordsDataflowDbContext())
            {
                var results =
                    from fw in context.FileWords.AsNoTracking()
                    group fw by new { fw.WordId, fw.FileId } into groups
                    let firstWord = groups.OrderBy(i => i.Row).ThenBy(i => i.Col).FirstOrDefault()
                    select new FileWordStats
                    {
                        Word = firstWord.Word.Term,
                        File = firstWord.File.Name,
                        FirstRow = firstWord.Row,
                        FirstCol = firstWord.Col,
                        Occurrences = groups.Count()
                    };

                var res = await results.OrderBy(i => i.Word).ThenBy(i => i.File).Skip(skip).Take(take).ToArrayAsync();
                return res;
            }
        }