Ejemplo n.º 1
0
        public void ShouldFailToBindArtist()
        {
            // Arrange
            List<string> artists = new List<string>() {
                "Artist1", "Artist2"
            };

            IArtistsRepository repos = MockArtistsRepository.CreateMockRepository("Pop", artists);
            ArtistBinder binder = new ArtistBinder(repos);

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

            // Act
            IArtist a = binder.BindModel(null, ctx) as IArtist;

            // Assert
            Assert.AreEqual(null, a);
            Assert.AreEqual(false, ctx.ModelState.IsValid);
            Assert.AreEqual(1, ctx.ModelState["artist"].Errors.Count);
        }
Ejemplo n.º 2
0
        public void ShouldBindArtist()
        {
            // Arrange
            List<string> artists = new List<string>() {
                "Artist1", "Artist2"
            };

            IArtistsRepository repos = MockArtistsRepository.CreateMockRepository("Pop", artists);
            ArtistBinder binder = new ArtistBinder(repos);

            ModelBindingContext ctx = BinderHelpers.CreateModelBindingContext("artist", "artist2");

            // Act
            IArtist a = binder.BindModel(null, ctx) as IArtist;

            // Assert
            Assert.AreNotEqual(null, a);
            Assert.AreEqual(true, ctx.ModelState.IsValid);
            Assert.AreEqual(2, a.Id);
            Assert.AreEqual("Artist2", a.Name);
        }