BookStoreTest.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using BookStore;
  3. namespace BookStoreTest
  4. {
  5. public class BST
  6. {
  7. public static MainWindow w = new MainWindow();
  8. public static string[] tb = { "Name", "0", "Author", "Category" };
  9. public static void Text(string i)
  10. {
  11. w.TbName.Text = tb[0] + i;
  12. w.TbPrice.Text = tb[1];
  13. w.TbAuthor.Text = tb[2] + i;
  14. w.TbCategory.Text = tb[3] + i;
  15. }
  16. }
  17. [TestClass]
  18. public class BookStoreTest
  19. {
  20. [TestMethod]
  21. public void Test1_Insert()
  22. {
  23. int c = BST.w.BooksGrid.Items.Count;
  24. BST.Text(""); BST.w.BIC(); // Добавление строки
  25. Assert.AreEqual(c + 1, BST.w.BooksGrid.Items.Count); // Проверка добавления строки
  26. BST.w.TbClear(); BST.w.BooksGrid.SelectedIndex = BST.w.BooksGrid.Items.Count - 1; // Выбор добавленной строки
  27. Assert.AreEqual(BST.tb[0], BST.w.TbName.Text); // Проверки корректности добавления
  28. Assert.AreEqual(BST.tb[1], BST.w.TbPrice.Text);
  29. Assert.AreEqual(BST.tb[2], BST.w.TbAuthor.Text);
  30. Assert.AreEqual(BST.tb[3], BST.w.TbCategory.Text);
  31. }
  32. [TestMethod]
  33. public void Test2_Update()
  34. {
  35. int c = BST.w.BooksGrid.Items.Count;
  36. BST.w.BooksGrid.SelectedIndex = BST.w.BooksGrid.Items.Count - 1;
  37. BST.Text("2");
  38. BST.w.BUC(); BST.w.TbClear(); BST.w.BGSC();
  39. Assert.AreEqual(c, BST.w.BooksGrid.Items.Count); // Проверка отсутствия новых строк
  40. Assert.AreEqual(BST.tb[0] + "2", BST.w.TbName.Text); // Проверки корректности обновления
  41. Assert.AreEqual(BST.tb[1], BST.w.TbPrice.Text);
  42. Assert.AreEqual(BST.tb[2] + "2", BST.w.TbAuthor.Text);
  43. Assert.AreEqual(BST.tb[3] + "2", BST.w.TbCategory.Text);
  44. }
  45. [TestMethod]
  46. public void Test3_Delete()
  47. {
  48. int c = BST.w.BooksGrid.Items.Count;
  49. BST.w.BooksGrid.SelectedIndex = BST.w.BooksGrid.Items.Count - 1; BST.w.BDC();
  50. Assert.AreEqual(c - 1, BST.w.BooksGrid.Items.Count); // Проверка удаления строки
  51. }
  52. }
  53. }