Пример #1
0
        public void AddIgnoreInvalid()
        {
            // 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.AddIgnore(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();
        }
Пример #2
0
        public void AddIgnore()
        {
            // Arrange
            Mock <User> ignoreUserMock = new Mock <User>();
            Mock <User> userMock       = new Mock <User>();

            userMock.Expect(u => u.AddIgnore(ignoreUserMock.Object))
            .Verifiable();
            Mock <GameManager> managerMock = new Mock <GameManager>(userMock.Object);

            managerMock.Expect(m => m.GetUser(1))
            .Returns(ignoreUserMock.Object)
            .Verifiable();
            BuddyListController controller = new BuddyListController(managerMock.Object);

            // Act
            ActionResult result = controller.AddIgnore(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();
        }
Пример #3
0
        public void AddIgnoreExisting()
        {
            // Arrange
            Mock <User> ignoreUserMock = new Mock <User>();
            Mock <User> userMock       = new Mock <User>();

            userMock.Expect(u => u.AddIgnore(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.AddIgnore(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();
        }