public void Add(ITextModel model) { string name = model.GetName(); if (_db.Texts.Any(x => x.Name == name)) { throw new ArgumentException($"Cannot add model since a model already exists in the database with name {model.GetName()}."); } WordCount withQuotes = TranslateCounts(model.GetCountsWithQuotes()); _db.WordCounts.Add(withQuotes); _db.SaveChanges(); WordCount withoutQuotes = TranslateCounts(model.GetCountsWithoutQuotes()); _db.WordCounts.Add(withoutQuotes); _db.SaveChanges(); Text text = new Text() { Name = model.GetName(), Author = model.GetAuthor(), WithQuotesId = withQuotes.Id, WithoutQuotesId = withoutQuotes.Id, IncludeQuotes = 1 }; _db.Texts.Add(text); _db.SaveChanges(); }
public void TestAdd() { string name; _uniqueNames.TryPop(out name); IGroupModel model = _modelFactory.GetGroupModel(name, UniversalConstants.CountSize); _groupStore.Add(model); Grouping result = _db.Groupings.FirstOrDefault(x => x.Name == name); Assert.IsNotNull(result); if (result != null) { _db.Groupings.Remove(result); _db.SaveChanges(); } }
public void TestAdd() { //string name = _uniqueNames.Pop(); string name; _uniqueNames.TryPop(out name); StreamReader text = new StreamReader("../../SampleTextFiles/WordSpanningMultipleLines.txt"); ITextModel model = _modelFactory.GetTextModel(name, text, UniversalConstants.CountSize); _textStore.Add(model); Text result = _db.Texts.FirstOrDefault(x => x.Name == name); Assert.IsNotNull(result); if (result != null) { _db.Texts.Remove(result); _db.SaveChanges(); } }
public void DangerousDeleteAllTextsAndGroups() { var textGroups = _db.Text_Grouping; _db.Text_Grouping.RemoveRange(textGroups); _db.SaveChanges(); var groupGroups = _db.Grouping_Grouping; _db.Grouping_Grouping.RemoveRange(groupGroups); _db.SaveChanges(); var texts = _db.Texts; _db.Texts.RemoveRange(texts); _db.SaveChanges(); var groups = _db.Groupings; _db.Groupings.RemoveRange(groups); _db.SaveChanges(); var counts = _db.WordCounts; _db.WordCounts.RemoveRange(counts); _db.SaveChanges(); }