コード例 #1
0
        public void ShouldFailToBindGenre()
        {
            // Arrange
            IArtistsRepository repos = MockArtistsRepository.CreateMockRepository("Pop", null);
            GenreBinder binder = new GenreBinder(repos);

            ModelBindingContext ctx = BinderHelpers.CreateModelBindingContext("genre", "plibble");

            // Act
            IGenre g = binder.BindModel(null, ctx) as IGenre;

            // Assert
            Assert.AreEqual(null, g);
            Assert.AreEqual(false, ctx.ModelState.IsValid);
            Assert.AreEqual(1, ctx.ModelState["genre"].Errors.Count);
        }
コード例 #2
0
        public void ShouldBindGenre()
        {
            // Arrange
            IArtistsRepository repos = MockArtistsRepository.CreateMockRepository("Pop", null);
            GenreBinder binder = new GenreBinder(repos);

            ModelBindingContext ctx = BinderHelpers.CreateModelBindingContext("genre", "pop");

            // Act
            IGenre g = binder.BindModel(null, ctx) as IGenre;

            // Assert
            Assert.AreNotEqual(null, g);
            Assert.AreEqual(true, ctx.ModelState.IsValid);
            Assert.AreEqual(0, g.Id);
            Assert.AreEqual("Pop", g.Name);
        }