public void RemoveBuddyInvalid() { // 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.RemoveBuddy(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 RemoveBuddy() { // Arrange Mock <User> buddyUserMock = new Mock <User>(); Mock <User> userMock = new Mock <User>(); userMock.Expect(u => u.RemoveBuddy(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.RemoveBuddy(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 RemoveBuddyNotInList() { // Arrange Mock <User> buddyUserMock = new Mock <User>(); Mock <User> userMock = new Mock <User>(); userMock.Expect(u => u.RemoveBuddy(buddyUserMock.Object)) .Throws(new ArgumentException()) .Verifiable(); Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object); managerMock.Expect(m => m.GetUser(2)) .Returns(buddyUserMock.Object) .Verifiable(); BuddyListController controller = new BuddyListController(managerMock.Object); // Act ActionResult result = controller.RemoveBuddy(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(); }