UnitTest1.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using boo;
  4. using System.Linq;
  5. namespace UnitTestProject1
  6. {
  7. [TestClass]
  8. public class UnitTest1
  9. {
  10. BookStoreContext _context = new BookStoreContext();
  11. [TestMethod]
  12. public void TestMethod1()
  13. {
  14. var page = new MainWindow();
  15. string name, price, category, author;
  16. int exp, res;
  17. //1
  18. name = "Обещание";
  19. author = "Юрайан Кониецко";
  20. price = "550";
  21. category = "Комикс";
  22. exp = _context.Books.Where(b => b.Name == name && b.Price == 550 && b.Author == author && b.Category == category).Count() + 1;
  23. Assert.IsTrue(page.InsertBook(name, price, author, category));
  24. res = _context.Books.Where(b => b.Name == name && b.Price == 550 && b.Author == author && b.Category == category).Count();
  25. Assert.AreEqual(exp, res);
  26. Books book = _context.Books.Where(b => b.Name == name && b.Price == 550 && b.Author == author && b.Category == category).FirstOrDefault();
  27. _context.Books.Remove(book);
  28. _context.SaveChanges();
  29. //2
  30. name = "";
  31. author = "";
  32. price = "";
  33. category = "";
  34. exp = _context.Books.Count();
  35. Assert.IsFalse(page.InsertBook(name, price, author, category));
  36. res = _context.Books.Count();
  37. Assert.AreEqual(exp, res);
  38. }
  39. }
  40. }