Пример #1
0
        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();
        }
Пример #2
0
        public void TestModifyAuthor()
        {
            //string name = _uniqueNames.Pop();
            string name;

            _uniqueNames.TryPop(out name);
            StreamReader sr    = new StreamReader("../../SampleTextFiles/WordSpanningMultipleLines.txt");
            ITextModel   model = _modelFactory.GetTextModel(name, sr, UniversalConstants.CountSize);

            model.SetAuthor("tom");
            _textStore.Add(model);
            model = _textStore.GetOne(x => x.Name == name);
            Assert.AreEqual("tom", model.GetAuthor());
            _textStore.ModifyAuthor(model, "jones");
            model = _textStore.GetOne(x => x.Name == name);
            Assert.AreEqual("jones", model.GetAuthor());
            _textStore.Delete(model);
        }
Пример #3
0
        private void CompareTextModels(ITextModel model1, ITextModel model2)
        {
            Assert.AreEqual(model1.GetName(), model2.GetName());
            Assert.AreEqual(model1.GetAuthor(), model2.GetAuthor());
            Assert.AreEqual(model1.GetIncludeQuotes(), model2.GetIncludeQuotes());
            ISingleWordCountModel counts1        = model1.GetCounts();
            ISingleWordCountModel counts2        = model1.GetCounts();
            ISingleWordCountModel withQuotes1    = model1.GetCountsWithQuotes();
            ISingleWordCountModel withQuotes2    = model2.GetCountsWithQuotes();
            ISingleWordCountModel withoutQuotes1 = model1.GetCountsWithoutQuotes();
            ISingleWordCountModel withoutQuotes2 = model2.GetCountsWithoutQuotes();

            for (int i = 0; i < withQuotes1.GetLength(); i++)
            {
                Assert.AreEqual(counts1.GetAt(i), counts2.GetAt(i));
                Assert.AreEqual(withQuotes1.GetAt(i), withQuotes2.GetAt(i));
                Assert.AreEqual(withoutQuotes1.GetAt(i), withoutQuotes2.GetAt(i));
            }
            Assert.AreEqual(model1.GetLength(), model2.GetLength());
        }