daily pastebin goal
47%
SHARE
TWEET

test

a guest Sep 21st, 2016 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using WebApplication.Controllers;
  4. using Moq;
  5. using Domain.Abstract;
  6. using Domain.Entities;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using System.Web.Routing;
  10.  
  11. namespace UnitTest
  12. {
  13.     [TestClass]
  14.     public class TestHomeController
  15.     {
  16.         [TestMethod]
  17.         public void TestIndex()
  18.         {
  19.             Mock<IUserRepository> mockUserRepository = new Mock<IUserRepository>();
  20.             mockUserRepository.Setup(u => u.users).Returns(new MyUser[] {
  21.                new MyUser{ID=1, username = "Example1", password = "Password", email="example@gmail.com"},
  22.                new MyUser{ID=1, username = "Example2", password = "Password", email="example1@gmail.com"},
  23.                new MyUser{ID=1, username = "Example3", password = "Password", email="example2@gmail.com"}
  24.             });
  25.  
  26.             HomeController controller = new HomeController(mockUserRepository.Object);
  27.             ActionResult result = controller.Index();
  28.             Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
  29.             RedirectToRouteResult routeResult = result as RedirectToRouteResult;
  30.             Assert.AreEqual(routeResult.RouteValues["action"], "SignIn");
  31.        
  32.  
  33.         }
  34.  
  35.         [TestMethod]
  36.         public void TestSignInViewResult()
  37.         {
  38.             Mock<IUserRepository> mockUserRepository = new Mock<IUserRepository>();
  39.             mockUserRepository.Setup(u => u.users).Returns(new MyUser[] {
  40.                new MyUser{ID=1, username = "Example1", password = "Password", email="example@gmail.com"},
  41.                new MyUser{ID=1, username = "Example2", password = "Password", email="example1@gmail.com"},
  42.                new MyUser{ID=1, username = "Example3", password = "Password", email="example2@gmail.com"}
  43.             });
  44.  
  45.             HomeController controller = new HomeController(mockUserRepository.Object);
  46.             ViewResult result = controller.SignIn() as ViewResult;
  47.             Assert.IsNotNull(result);
  48.             Assert.AreEqual("SignIn", result.ViewName);
  49.         }
  50.  
  51.         [TestMethod]
  52.         public void TestSignInActionResult()
  53.         {
  54.             Mock<IUserRepository> mockUserRepository = new Mock<IUserRepository>();
  55.             mockUserRepository.Setup(u => u.users).Returns(new MyUser[] {
  56.                new MyUser{ID=1, username = "Example1", password = "Password", email="example@gmail.com"},
  57.                new MyUser{ID=1, username = "Example2", password = "Password", email="example1@gmail.com"},
  58.                new MyUser{ID=1, username = "Example3", password = "Password", email="example2@gmail.com"}
  59.             });
  60.  
  61.             HomeController controller = new HomeController(mockUserRepository.Object);
  62.             MyUser user = new MyUser { ID = 2, username = "Example1", password = "Password", email = "example@gmail.com" };
  63.  
  64.             RedirectToRouteResult result = controller.SignIn(user) as RedirectToRouteResult;
  65.  
  66.             Assert.Equals("Profile", result.RouteValues["action"]);
  67.            
  68.         }
  69.  
  70.         [TestMethod]
  71.         public void TestSignUpHomeController()
  72.         {
  73.             Mock<IUserRepository> mockUserRepository = new Mock<IUserRepository>();
  74.             mockUserRepository.Setup(u => u.users).Returns(new MyUser[] {
  75.                new MyUser{ID=1, username = "Example1", password = "Password", email="example@gmail.com"},
  76.                new MyUser{ID=1, username = "Example2", password = "Password", email="example1@gmail.com"},
  77.                new MyUser{ID=1, username = "Example3", password = "Password", email="example2@gmail.com"}
  78.             });
  79.  
  80.             HomeController controller = new HomeController(mockUserRepository.Object);
  81.             ActionResult result = controller.SignUp();
  82.             Assert.IsInstanceOfType(result, typeof(ViewResult));
  83.         }
  84.  
  85.         [TestMethod]
  86.         public void TestSignUpHomeControllerActionResult()
  87.         {
  88.             Mock<IUserRepository> mockUserRepository = new Mock<IUserRepository>();
  89.             mockUserRepository.Setup(u => u.users).Returns(new MyUser[] {
  90.                new MyUser{ID=1, username = "Example1", password = "Password", email="example@gmail.com"},
  91.                new MyUser{ID=1, username = "Example2", password = "Password", email="example1@gmail.com"},
  92.                new MyUser{ID=1, username = "Example3", password = "Password", email="example2@gmail.com"}
  93.             });
  94.  
  95.             MyUser user = new MyUser { ID = 2, username = "Ana", password = "Password", email = "ana@gmail.com" };
  96.             HomeController controller = new HomeController(mockUserRepository.Object);
  97.             RedirectResult result = (RedirectResult)controller.SignUp(user);
  98.             Assert.IsNotNull(result);
  99.  
  100.         }
  101.  
  102.     }
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top