コード例 #1
0
ファイル: TrackControllerTest.cs プロジェクト: Baptista/PI
        public void Create_POST_Does_Not_Save_Changes_If_ModelState_Is_Not_Valid()
        {
            // Arrange
            var controller = new TrackController();
            var repo = new Mock<TestDB>();
            repo.Setup(r => r.SaveChanges()).Throws<Exception>();
            controller._repo = repo.Object;
            controller.ModelState.AddModelError("testError", new Exception());

            // Act
            controller.Create(new TrackModel());

            // Assert
        }
コード例 #2
0
ファイル: TrackControllerTest.cs プロジェクト: Baptista/PI
        public void Create_POST_Redirects_Same_Model_To_GET_If_ModelState_Not_Valid()
        {
            // Arrange
            var controller = new TrackController();
            var track = new TrackModel { Name = "One", Artist = "Metallica" };
            var repo = new Mock<TestDB>();
            controller._repo = repo.Object;
            controller.ModelState.AddModelError("testError", new Exception());

            // Act
            var result = controller.Create(track) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(track, result.Model);
        }
コード例 #3
0
ファイル: TrackControllerTest.cs プロジェクト: Baptista/PI
        public void Index_always_returns_IEnumerable_of_TrackModel()
        {
            // Arrange
            var controller = new TrackController();
            var repo = new TestDB();
            repo.Tracks.Add(new Track { Artist = "Metallica", Name = "Battery", Duration = 5.12 });
            repo.Tracks.Add(new Track { Artist = "Nirvana", Name = "Polly", Duration = 2.3 });
            controller._repo = repo;
            // TODO: Mock data mappers
            controller._t2mMapper = new SpotiChelas.DataMappers.TrackToTrackModelMapper();

            // Act
            var result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Model);
            Assert.IsInstanceOfType(result.Model, typeof(IEnumerable<TrackModel>));
        }
コード例 #4
0
ファイル: TrackControllerTest.cs プロジェクト: Baptista/PI
        public void Create_POST_Saves_Track_If_ModelState_Is_Valid()
        {
            // Arrange
            var controller = new TrackController();
            var track = new TrackModel { Name = "One", Artist = "Metallica" };
            var repo = new Mock<TestDB>();

            controller._repo = repo.Object;
            // TODO: Mock data mappers
            controller._m2tMapper = new SpotiChelas.DataMappers.TrackModelToTrackMapper();

            // Act
            var result = controller.Create(track) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("action", result.RouteValues.First().Key);
            Assert.AreEqual("Index", result.RouteValues.First().Value);
            Assert.AreEqual(1, repo.Object.Tracks.Count());
            repo.Verify(x => x.SaveChanges());
        }
コード例 #5
0
ファイル: TrackControllerTest.cs プロジェクト: Baptista/PI
        public void Test_Index()
        {
            // Arrange
            var controller = new TrackController();
            var repo = new TestDB();
            repo.Tracks.Add(new Track { Artist = "Metallica", Name = "Battery", Duration = 5.12 });
            repo.Tracks.Add(new Track { Artist = "Nirvana", Name = "Polly", Duration = 2.3 });
            controller._repo = repo;
            // TODO: Mock data mappers
            controller._t2mMapper = new SpotiChelas.DataMappers.TrackToTrackModelMapper();

            // Act
            var result = controller.Index() as ViewResult;
            var list = result.Model as IEnumerable<TrackModel>;

            // Assert
            Assert.AreEqual(2, list.Count());
        }