public void ApplyPost() { var mockUser = University.GetUser("a101"); var stickerType = University.GetStickerTypes(mockUser.Category).FirstOrDefault(); var mockData = new StickerApplication { SelectedType = stickerType.ID.ToString(), Vehicle = new Vehicle { OwnerName = "Test Owner", PlateNumber = "06ZZ1234", RegistrationNumber = "ZZ123456" } }; StickerController controller = new StickerController(); controller.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), controller); RedirectToRouteResult result = controller.Apply(mockData) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual("1", result.RouteValues["ok"]); Assert.AreEqual("Index", result.RouteValues["action"]); ViewResult indexResult = controller.Index() as ViewResult; Assert.IsNotNull(indexResult); Assert.IsInstanceOfType(indexResult.Model, typeof(List <StickerApplication>)); List <StickerApplication> model = indexResult.Model as List <StickerApplication>; Assert.AreNotEqual(0, model.Count); Assert.AreEqual("06ZZ1234", model.FirstOrDefault().Vehicle.PlateNumber); }
public void ApplyGetMethod() { var mockUser = University.GetUser("a101"); StickerController controller = new StickerController(); controller.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), controller); ViewResult result = controller.Apply() as ViewResult; Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Model, typeof(StickerApplication)); }
public void ApplyPostForNoMoreSticker() { var mockUser = University.GetUser("e101"); var stickerType = University.GetStickerTypes(mockUser.Category).FirstOrDefault(); var mockData = new StickerApplication { SelectedType = stickerType.ID.ToString(), Vehicle = new Vehicle { OwnerName = "Test Owner", PlateNumber = "06ZZ1234", RegistrationNumber = "ZZ123456" } }; StickerController controller = new StickerController(); controller.ControllerContext = new ControllerContext(MockAuthContext(mockUser).Object, new RouteData(), controller); RedirectToRouteResult result = controller.Apply(mockData) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual("1", result.RouteValues["nomoresticker"]); Assert.AreEqual("Sticker", result.RouteValues["controller"]); Assert.AreEqual("Index", result.RouteValues["action"]); }