Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using PartyInvites.Entities;
  3. using PartyInvites.Concrete;
  4. using PartyInvites.Abstract;
  5. using PartyInvites.Controllers;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. using Moq;
  12. using PartyInvites.Models;
  13.  
  14. namespace PartyInvites.Test
  15. {
  16. [TestClass]
  17. public class HomeControllerTests
  18. {
  19. [TestMethod]
  20. public void TestGetAllResponses()
  21. {
  22. //arrange
  23. List<GuestResponse> responses = new List<GuestResponse>();
  24.  
  25. GuestResponse guestResponse = new GuestResponse()
  26. {
  27. Email = "mjwghout@avans.nl",
  28. Name = "Maikel",
  29. Phone = "0655878923",
  30. WillAttend = true,
  31. PhotoUrl = ""
  32. };
  33. responses.Add(guestResponse);
  34.  
  35. GuestResponse guestResponse2 = new GuestResponse()
  36. {
  37. Email = "mjwghout@avans.nl",
  38. Name = "Maikel",
  39. Phone = "0655878923",
  40. WillAttend = false,
  41. PhotoUrl = ""
  42. };
  43. responses.Add(guestResponse2);
  44.  
  45. Mock<IRepository> mock = new Mock<IRepository>();
  46. mock.Setup(m => m.GetAllResponses()).Returns(responses);
  47. HomeController controller = new HomeController(mock.Object);
  48.  
  49. //act
  50. ViewResult result = controller.Registrations(null);
  51.  
  52. //assert
  53. Assert.AreEqual(2, ((GuestResponseViewModel)result.Model).GuestResponses.Count());
  54. }
  55.  
  56. [TestMethod]
  57. public void TestGetWillAttendResponses()
  58. {
  59. //arrange
  60. List<GuestResponse> responses = new List<GuestResponse>();
  61.  
  62. GuestResponse guestResponse = new GuestResponse()
  63. {
  64. Email = "mjwghout@avans.nl",
  65. Name = "Maikel",
  66. Phone = "0655878923",
  67. WillAttend = true,
  68. PhotoUrl = ""
  69. };
  70. responses.Add(guestResponse);
  71.  
  72. GuestResponse guestResponse2 = new GuestResponse()
  73. {
  74. Email = "mjwghout@avans.nl",
  75. Name = "Maikel",
  76. Phone = "0655878923",
  77. WillAttend = true,
  78. PhotoUrl = ""
  79. };
  80. responses.Add(guestResponse2);
  81.  
  82. Mock<IRepository> mock = new Mock<IRepository>();
  83. mock.Setup(m => m.GetAllResponses()).Returns(responses);
  84. HomeController controller = new HomeController(mock.Object);
  85.  
  86. //act
  87. ViewResult result = controller.Registrations("Aanwezig");
  88.  
  89. //assert
  90. Assert.AreEqual(2, ((GuestResponseViewModel)result.Model).GuestResponses.Count());
  91. }
  92.  
  93. [TestMethod]
  94. public void TestGetWillAttendResponses2()
  95. {
  96. //arrange
  97. List<GuestResponse> responses = new List<GuestResponse>();
  98.  
  99. GuestResponse guestResponse = new GuestResponse()
  100. {
  101. Email = "mjwghout@avans.nl",
  102. Name = "Maikel",
  103. Phone = "0655878923",
  104. WillAttend = true,
  105. PhotoUrl = ""
  106. };
  107. responses.Add(guestResponse);
  108.  
  109. GuestResponse guestResponse2 = new GuestResponse()
  110. {
  111. Email = "mjwghout@avans.nl",
  112. Name = "Maikel",
  113. Phone = "0655878923",
  114. WillAttend = false,
  115. PhotoUrl = ""
  116. };
  117. responses.Add(guestResponse2);
  118.  
  119. Mock<IRepository> mock = new Mock<IRepository>();
  120. mock.Setup(m => m.GetAllResponses()).Returns(responses);
  121. HomeController controller = new HomeController(mock.Object);
  122.  
  123. //act
  124. ViewResult result = controller.Registrations("Aanwezig");
  125.  
  126. //assert
  127. Assert.AreEqual(1, ((GuestResponseViewModel)result.Model).GuestResponses.Count());
  128. }
  129.  
  130. [TestMethod]
  131. public void TestGetWillNotAttendResponses()
  132. {
  133. //arrange
  134. List<GuestResponse> responses = new List<GuestResponse>();
  135.  
  136. GuestResponse guestResponse = new GuestResponse()
  137. {
  138. Email = "mjwghout@avans.nl",
  139. Name = "Maikel",
  140. Phone = "0655878923",
  141. WillAttend = false,
  142. PhotoUrl = ""
  143. };
  144. responses.Add(guestResponse);
  145.  
  146. GuestResponse guestResponse2 = new GuestResponse()
  147. {
  148. Email = "mjwghout@avans.nl",
  149. Name = "Maikel",
  150. Phone = "0655878923",
  151. WillAttend = false,
  152. PhotoUrl = ""
  153. };
  154. responses.Add(guestResponse2);
  155.  
  156. Mock<IRepository> mock = new Mock<IRepository>();
  157. mock.Setup(m => m.GetAllResponses()).Returns(responses);
  158. HomeController controller = new HomeController(mock.Object);
  159.  
  160. //act
  161. ViewResult result = controller.Registrations("Niet aanwezig");
  162.  
  163. //assert
  164. Assert.AreEqual(2, ((GuestResponseViewModel)result.Model).GuestResponses.Count());
  165. }
  166.  
  167. [TestMethod]
  168. public void TestGetWillNotAttendResponses2()
  169. {
  170. //arrange
  171. List<GuestResponse> responses = new List<GuestResponse>();
  172.  
  173. GuestResponse guestResponse = new GuestResponse()
  174. {
  175. Email = "mjwghout@avans.nl",
  176. Name = "Maikel",
  177. Phone = "0655878923",
  178. WillAttend = false,
  179. PhotoUrl = ""
  180. };
  181. responses.Add(guestResponse);
  182.  
  183. GuestResponse guestResponse2 = new GuestResponse()
  184. {
  185. Email = "mjwghout@avans.nl",
  186. Name = "Maikel",
  187. Phone = "0655878923",
  188. WillAttend = true,
  189. PhotoUrl = ""
  190. };
  191. responses.Add(guestResponse2);
  192.  
  193. Mock<IRepository> mock = new Mock<IRepository>();
  194. mock.Setup(m => m.GetAllResponses()).Returns(responses);
  195. HomeController controller = new HomeController(mock.Object);
  196.  
  197. //act
  198. ViewResult result = controller.Registrations("Niet aanwezig");
  199.  
  200. //assert
  201. Assert.AreEqual(1, ((GuestResponseViewModel)result.Model).GuestResponses.Count());
  202. }
  203. }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement