Exemplo n.º 1
0
        public void Cannot_Add_Log_With_Nonexisting_Activity()
        {
            // Arrange - create the mock repositories
            var mockRepositoryLog      = new Mock <IRepository <TimerLog> >();
            var mockRepositoryActivity = new Mock <IRepository <TimerActivity> >();

            var activity = new TimerActivity {
                ID = 1, Name = "Sport"
            };

            mockRepositoryActivity.Setup(m => m.GetAll()).Returns(new TimerActivity[]
            {
            }.AsQueryable);

            // Arrange - create a controller
            var target = new TimerController(mockRepositoryActivity.Object, null, mockRepositoryLog.Object);

            // action
            var result = target.AddLog(new AddLogViewModel
            {
                ActivityId = activity.ID
            });

            // Assert
            mockRepositoryLog.Verify(m => m.Save(It.IsAny <TimerLog>()), Times.Never);

            // Assert - check the method result type
            Assert.IsType <NotFoundResult>(result);
        }