public void AddQuoteTest() { string id = Guid.NewGuid().ToString(); Console.WriteLine("About to test adding a quote and saving to disk for ID: " + id); QuoteList target = new QuoteList(id); Assert.IsTrue(target.Quotes.Count == 0, "We have not added any quotes yet but the quotelist is full for ID: " + id); IQuote inQuote = GetTestingQuote(); Console.WriteLine("About to add the following test quote: " + inQuote.ToString()); target.AddQuote(inQuote); inQuote = GetTestingQuote(); Console.WriteLine("About to add the following test quote: " + inQuote.ToString()); target.AddQuote(inQuote); int numberOfQuotesToSave = target.Quotes.Count; target.Save(); //Now test that we get this quote back: target = new QuoteList(id); Assert.IsTrue(target.Quotes.Count == numberOfQuotesToSave, "We added " + numberOfQuotesToSave + " quote(s) so this collection should contain the same number of quotes."); Console.WriteLine("Test was successful."); }
internal static void Save(QuoteList inQuoteList) { XDocument document = new XDocument(); document.Add(XElement.Parse(@"<QuoteList xmlns='http://kiander.com'></QuoteList>")); document.Root.Add(new XAttribute("QuoteListId", inQuoteList.Id)); foreach (IQuote quote in inQuoteList.Quotes) { XElement quoteRecord = new XElement("QuoteRecord"); quoteRecord.Add(new XElement("QuoteID", quote.Id)); quoteRecord.Add(new XElement("Quote", quote.Text)); quoteRecord.Add(new XElement("Author", quote.Author)); XElement categories = new XElement("Categories"); if (quote.Categories != null) { foreach (string category in quote.Categories) { categories.Add(new XElement("Category", category)); } } if (quote.Categories == null || quote.Categories.Count < 1) { categories.Add(new XElement("Category", string.Empty)); } quoteRecord.Add(categories); document.Root.Add(quoteRecord); } if (File.Exists(DataFileHelper.FullPath(inQuoteList.Id))) File.Delete(DataFileHelper.FullPath(inQuoteList.Id)); document.Save(DataFileHelper.FullPath(inQuoteList.Id)); }
public void CategoriesTest() { QuoteList quotes = new QuoteList(QuoteList.GlobalQuoteListId); List<string> categories = quotes.Categories; Console.WriteLine("Found {0} categories.", categories.Count); foreach (string category in categories) { Console.Write(category + " "); } }
internal static void LoadFromDataFile(QuoteList inQuoteList) { if (File.Exists(DataFileHelper.FullPath(inQuoteList.Id))) { XElement quoteList = XElement.Load(DataFileHelper.FullPath(inQuoteList.Id)); foreach (XElement quoteRecord in quoteList.Descendants("QuoteRecord")) { string quoteId = (string)quoteRecord.Element("QuoteID"); string quoteText = (string)quoteRecord.Element("Quote"); string author = (string)quoteRecord.Element("Author"); List<string> categories = new List<string>(); foreach (XElement category in quoteRecord.Element("Categories").Descendants("Category")) { categories.Add((string)category); } IQuote quote = new Quote(quoteId, quoteText, author, categories); inQuoteList.Quotes.Add(quote); } } }
public QuoteListWrapper(string GuidToUse) { _UserGuid = GuidToUse; _QuoteList = new QuoteList(_UserGuid); }
public QuoteListWrapper() { _UserGuid = Membership.GetUserNameByEmail(HttpContext.Current.User.Identity.Name); _QuoteList = new QuoteList(_UserGuid); }
public void DeleteQuoteTest() { string id = Guid.NewGuid().ToString(); Console.WriteLine("About to test adding a quote for ID: " + id); QuoteList target = new QuoteList(id); IQuote quoteToDeleteLater = GetTestingQuote(); Console.WriteLine("Adding GUID: " + quoteToDeleteLater.Id); target.AddQuote(quoteToDeleteLater); //Add a few more... target.AddQuote(GetTestingQuote()); target.AddQuote(GetTestingQuote()); int quotesAdded = target.Quotes.Count; target.Save(); Console.WriteLine("Verifying all quotes exist."); target = new QuoteList(id); Assert.IsTrue(target.Quotes.Count == quotesAdded, "This collection should contain " + quotesAdded + " quotes."); //Now delete the GUID above. Console.WriteLine("About to delete the quote: " + quoteToDeleteLater.Id); target.DeleteQuote(quoteToDeleteLater.Id); target.Save(); target = new QuoteList(id); Assert.IsTrue(target.Quotes.Count == (quotesAdded - 1), "This collection should contain " + (quotesAdded - 1) + " quotes."); Console.WriteLine("Test was successful."); }
/// <summary> ///I commented the [TestMethod()] attribute because this is a utility that should not be used ///unless needed. ///</summary> //[TestMethod()] public void Utility_ResetQuoteIDs() { string id = "";//"ed32da6e-da85-477e-9b21-ddf131a532e8"; Console.WriteLine("About to reset all QuoteIDs for ID: " + id); QuoteList target = new QuoteList(id); foreach (IQuote quote in target.Quotes) { quote.Id = Guid.NewGuid().ToString(); Console.WriteLine("Reset quote: " + quote.ToString()); } target.Save(); Console.WriteLine("Reset was successful."); }
public void GetRandomQuoteTest() { QuoteList quotes = new QuoteList(QuoteList.GlobalQuoteListId); Console.WriteLine("Testing the GetRandomQuote() Operation."); Console.WriteLine(string.Empty); Console.WriteLine("GetRandomQuote returned: {0}", quotes.GetRandomQuote()); Console.WriteLine(string.Empty); Console.WriteLine("GetRandomQuote returned: {0}", quotes.GetRandomQuote()); Console.WriteLine(string.Empty); Console.WriteLine("GetRandomQuote returned: {0}", quotes.GetRandomQuote()); Console.WriteLine(string.Empty); Console.WriteLine("GetRandomQuote returned: {0}", quotes.GetRandomQuote()); Console.WriteLine(string.Empty); Console.WriteLine("GetRandomQuote returned: {0}", quotes.GetRandomQuote()); }
public void GetQuotesBySearchTextTest() { string searchText = "rent";// "action"; QuoteList quotes = new QuoteList(QuoteList.GlobalQuoteListId); List<IQuote> quotesBySearchText = quotes.GetQuotesBySearchText(searchText); Console.WriteLine("Found {0} quotes with searchText: '{1}'.", quotesBySearchText.Count, searchText); foreach (IQuote quote in quotesBySearchText) { Console.WriteLine(quote.ToString()); } }
public void GetQuotesByCategoryTest() { string category = "action"; QuoteList quotes = new QuoteList(QuoteList.GlobalQuoteListId); List<IQuote> quotesByCategory = quotes.GetQuotesByCategory(category); Console.WriteLine("Found {0} quotes with category '{1}'.", quotesByCategory.Count, category); foreach (IQuote quote in quotesByCategory) { Console.WriteLine(quote.ToString()); } }