UnitTest1.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using WSUniversalLib;
  4. namespace UnitTestProject1
  5. {
  6. [TestClass]
  7. public class UnitTest1
  8. {
  9. [TestMethod]
  10. public void GetQuantityForProduct_AreEqual_CheckData()
  11. {
  12. Assert.AreEqual(Calculation.GetQuantityForProduct(3, 1, 15, 20, 45), 114147);
  13. }
  14. [TestMethod]
  15. public void GetQuantityForProduct_CheckError_IsTrue()
  16. {
  17. bool res = true;
  18. if(Calculation.GetQuantityForProduct(3, 1, 15, 20, 45) == -1)
  19. {
  20. res = false;
  21. }
  22. Assert.IsTrue(res);
  23. }
  24. [TestMethod]
  25. public void GetQuantityForProduct_CheckError_IsFalse()
  26. {
  27. bool res = true;
  28. if (Calculation.GetQuantityForProduct(5, 1, 15, 20, 45) == -1)
  29. {
  30. res = false;
  31. }
  32. Assert.IsFalse(res);
  33. }
  34. [TestMethod]
  35. public void GetQuantityForProduct_CheckData_IsNotNull()
  36. {
  37. Assert.IsNotNull(Calculation.GetQuantityForProduct(3, 1, 15, 20, 45));
  38. }
  39. [TestMethod]
  40. public void GetQuantityForProduct_CheckData_ReturnTypeIsInt()
  41. {
  42. Assert.IsInstanceOfType(Calculation.GetQuantityForProduct(3, 1, 15, 20, 45), typeof(int));
  43. }
  44. [TestMethod]
  45. public void GetQuantityForProduct_CheckData_ReturnTypeIsNotInt()
  46. {
  47. Assert.IsNotInstanceOfType(Calculation.GetQuantityForProduct(3, 1, 15, 20, 45), typeof(double));
  48. }
  49. [TestMethod]
  50. public void GetQuantityForProduct_AreEqualNotEqual()
  51. {
  52. Assert.AreNotEqual(Calculation.GetQuantityForProduct(3, 1, 15, 20, 45), 777);
  53. }
  54. [TestMethod]
  55. public void GetQuantityForProduct_CheckData_InvalidProdType()//Тут начинаются сложные тесты
  56. {
  57. Assert.AreEqual(Calculation.GetQuantityForProduct(5, 1, 15, 20, 45), -1);
  58. }
  59. [TestMethod]
  60. public void GetQuantityForProduct_ThrowException_InvalidCount()
  61. {
  62. Assert.ThrowsException<System.Exception>(() => Calculation.GetQuantityForProduct(3, 1, 0, 20, 45));
  63. }
  64. [TestMethod]
  65. public void GetQuantityForProduct_ThrowException_InvalidWidth()
  66. {
  67. Assert.ThrowsException<System.Exception>(() => Calculation.GetQuantityForProduct(3, 1, 15, 0, 45));
  68. }
  69. [TestMethod]
  70. public void GetQuantityForProduct_ThrowException_InvalidLength()
  71. {
  72. Assert.ThrowsException<System.Exception>(() => Calculation.GetQuantityForProduct(3, 1, 15, 20, 0));
  73. }
  74. }
  75. }