public void Index() { // Arrange Mock <User> userMock = new Mock <User>(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.Index(); // Assert Assert.That(result, Is.TypeOf(typeof(RedirectToRouteResult)), "Should return a redirect"); Assert.That(controller.ModelState.IsValid, "No errors should be returned"); managerMock.Verify(); }
public void RemoveIgnoreInvalid() { // Arrange Mock <User> userMock = new Mock <User>(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); managerMock.Expect(m => m.GetUser(3)) .Returns <User>(null) .Verifiable(); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.RemoveIgnore(3); // Assert Assert.That(result, Is.TypeOf(typeof(ViewResult)), "Should return a view"); Assert.That(controller.ModelState.IsValid, Is.False, "Errors should be returned"); managerMock.Verify(); }
public void AddBuddy() { // Arrange Mock <User> buddyUserMock = new Mock <User>(); Mock <User> userMock = new Mock <User>(); userMock.Expect(u => u.AddBuddy(buddyUserMock.Object)) .Verifiable(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); managerMock.Expect(m => m.GetUser(1)) .Returns(buddyUserMock.Object) .Verifiable(); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.AddBuddy(1); // Assert Assert.That(result, Is.TypeOf(typeof(RedirectToRouteResult)), "Should return a redirect"); Assert.That(controller.ModelState.IsValid, "No errors should be returned"); managerMock.Verify(); }
public void BuddyList() { // Arrange Mock <User> userMock = new Mock <User>(); BuddyList[] list = new BuddyList[0]; userMock.Expect(u => u.GetBuddyList()) .Returns(list) .Verifiable(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.BuddyList(); // Assert Assert.That(result, Is.TypeOf(typeof(ViewResult)), "Should return a view"); Assert.That(controller.ModelState.IsValid, "No errors should be returned"); ViewResult viewResult = (ViewResult)result; Assert.That(viewResult.ViewData["BuddyList"], Is.EqualTo(list), "ViewData should have buddy list"); managerMock.Verify(); }
public void FindPlayer() { // Arrange Mock <User> userMock = new Mock <User>(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); Player[] list = new Player[0]; managerMock.Expect(m => m.FindPlayer("test")) .Returns(list) .Verifiable(); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.FindPlayer("test", 1); // Assert Assert.That(result, Is.TypeOf(typeof(ViewResult)), "Should return a view"); Assert.That(controller.ModelState.IsValid, "No errors should be returned"); ViewResult viewResult = (ViewResult)result; Assert.That(viewResult.ViewData["Matches"], Is.Empty, "ViewData should have empty player list"); Assert.That(viewResult.ViewData["name"], Is.EqualTo("test"), "ViewData should have player search"); managerMock.Verify(); }
public void RemoveIgnoreNotInList() { // Arrange Mock <User> ignoreUserMock = new Mock <User>(); Mock <User> userMock = new Mock <User>(); userMock.Expect(u => u.RemoveIgnore(ignoreUserMock.Object)) .Throws(new ArgumentException()) .Verifiable(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); managerMock.Expect(m => m.GetUser(2)) .Returns(ignoreUserMock.Object) .Verifiable(); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.RemoveIgnore(2); // Assert Assert.That(result, Is.TypeOf(typeof(ViewResult)), "Should return a view"); Assert.That(controller.ModelState.IsValid, Is.False, "Errors should be returned"); managerMock.Verify(); }