コード例 #1
0
 public void Should_Be_Successful_When_Life_Is_Good()
 {
     var validator = new SequenceGeneratorValidator();
     var model = new SequenceGeneratorModel()
     {
         MaxValue = 5
     };
     validator.ShouldNotHaveValidationErrorFor(m => m.MaxValue, model);
 }
コード例 #2
0
 public void Should_Have_Error_When_MaxValue_Is_Less_Than_MinValue()
 {
     var validator = new SequenceGeneratorValidator();
     var model = new SequenceGeneratorModel(6)
     {
         MaxValue = 5
     };
     validator.ShouldHaveValidationErrorFor(m => m.MaxValue, model);
 }
コード例 #3
0
 public void Should_Have_Error_When_MaxValue_Is_Null()
 {
     var validator = new SequenceGeneratorValidator();
     var model = new SequenceGeneratorModel()
     {
         MaxValue = null
     };
     validator.ShouldHaveValidationErrorFor(m => m.MaxValue, model);
 }
コード例 #4
0
        public void Generate_Does_Nothing_If_The_MaxValue_Is_Not_Known()
        {
            // Arrange
            var controller = new SequencesController(null);
            var model = new SequenceGeneratorModel()
            {
                MaxValue = null
            };

            // Act
            var result = controller.Generate(model);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(model.Results == null);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = result as ViewResult;
            Assert.AreEqual("Index", viewResult.ViewName);
        }
コード例 #5
0
        public void Generate_Returns_A_Model_With_Results()
        {
            // Arrange
            var controller = new SequencesController(new [] { new AscendingSequenceCalculator() });
            var model = new SequenceGeneratorModel()
            {
                MaxValue = 5
            };

            // Act
            var result = controller.Generate(model);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(model.Results != null);
            Assert.AreEqual(1, model.Results.Count()); // Because we have one calculator plugged in
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = result as ViewResult;
            Assert.IsTrue(viewResult.ViewData.ModelState.IsValid);
            Assert.AreEqual("Index", viewResult.ViewName);
        }
コード例 #6
0
        public void Generate_Returns_Json_If_Via_Ajax_Request()
        {
            // Arrange
            var controller = new SequencesController(new[] { new AscendingSequenceCalculator() });
            var model = new SequenceGeneratorModel()
            {
                MaxValue = 5
            };
            var context = NewAjaxContext();
            controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);

            // Act
            var result = controller.Generate(model);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(JsonResult));
            var jsonResult = result as JsonResult;
            Assert.IsInstanceOfType(jsonResult.Data, typeof(SequenceGeneratorModel));
            Assert.AreSame(jsonResult.Data, model);
        }