Example #1
0
        public void Can_Edit_Rule()
        {
            // Arrange - create the mock repository
            Mock <IRuleRepository> mock = new Mock <IRuleRepository>();

            mock.Setup(m => m.LoadRules).Returns(new MT_LOAD_RULE[] {
                new MT_LOAD_RULE {
                    LoadRuleId = 1, Code = "LR1"
                },
                new MT_LOAD_RULE {
                    LoadRuleId = 2, Code = "LR2"
                },
                new MT_LOAD_RULE {
                    LoadRuleId = 3, Code = "LR3"
                },
            }.AsQueryable());
            // Arrange - create the controller
            RuleController target = new RuleController(mock.Object);
            // Act
            MT_LOAD_RULE p1 = target.RuleEdit(1).ViewData.Model as MT_LOAD_RULE;
            MT_LOAD_RULE p2 = target.RuleEdit(2).ViewData.Model as MT_LOAD_RULE;
            MT_LOAD_RULE p3 = target.RuleEdit(3).ViewData.Model as MT_LOAD_RULE;

            // Assert
            Assert.AreEqual(1, p1.LoadRuleId);
            Assert.AreEqual(2, p2.LoadRuleId);
            Assert.AreEqual(3, p3.LoadRuleId);
        }
Example #2
0
        public void Can_Save_Valid_Changes()
        {
            // Arrange - create mock repository
            Mock <IRuleRepository> mock = new Mock <IRuleRepository>();
            // Arrange - create the controller
            RuleController target = new RuleController(mock.Object);
            // Arrange - create a loadRule
            MT_LOAD_RULE loadRule = new MT_LOAD_RULE {
                Code = "Test"
            };
            // Act - try to save the loadRule
            ActionResult result = target.RuleEdit(loadRule);

            // Assert - check that the repository was called
            mock.Verify(m => m.SaveLoadRule(loadRule));
            // Assert - check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Example #3
0
        public void Cannot_Save_Invalid_Changes()
        {
            // Arrange - create mock repository
            Mock <IRuleRepository> mock = new Mock <IRuleRepository>();
            // Arrange - create the controller
            RuleController target = new RuleController(mock.Object);
            // Arrange - create a loadRule
            MT_LOAD_RULE loadRule = new MT_LOAD_RULE {
                Code = "Test"
            };

            // Arrange - add an error to the model state
            target.ModelState.AddModelError("error", "error");
            // Act - try to save the loadRule
            ActionResult result = target.RuleEdit(loadRule);

            // Assert - check that the repository was not called
            mock.Verify(m => m.SaveLoadRule(It.IsAny <MT_LOAD_RULE>()), Times.Never());
            // Assert - check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Example #4
0
        public void Cannot_Edit_Nonexistent_Rule()
        {
            // Arrange - create the mock repository
            Mock <IRuleRepository> mock = new Mock <IRuleRepository>();

            mock.Setup(m => m.LoadRules).Returns(new MT_LOAD_RULE[] {
                new MT_LOAD_RULE {
                    LoadRuleId = 1, Code = "LR1"
                },
                new MT_LOAD_RULE {
                    LoadRuleId = 2, Code = "LR2"
                },
                new MT_LOAD_RULE {
                    LoadRuleId = 3, Code = "LR3"
                },
            }.AsQueryable());
            // Arrange - create the controller
            RuleController target = new RuleController(mock.Object);
            // Act
            MT_LOAD_RULE result = (MT_LOAD_RULE)target.RuleEdit(4).ViewData.Model;

            // Assert
            Assert.IsNull(result);
        }