public void AddBuddyInvalid() { // 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.AddBuddy(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 AddBuddyExisting() { // Arrange Mock <User> buddyUserMock = new Mock <User>(); Mock <User> userMock = new Mock <User>(); userMock.Expect(u => u.AddBuddy(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.AddBuddy(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(); }