Example #1
0
        public void Cannot_Edit_Nonexistent_Activity()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerActivity> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerActivity {
                    Name = "Apple", ID = 1
                },
                new TimerActivity {
                    Name = "Orange", ID = 2
                },
                new TimerActivity {
                    Name = "Banana", ID = 3
                }
            }.AsQueryable());

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


            // Act
            var result = MVCHelper.GetViewModel <TimerActivity>(target.EditActivity(4));

            // Assert
            Assert.Null(result);
        }
Example #2
0
        public void Can_Edit_Activity()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerActivity> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerActivity {
                    Name = "Apple", ID = 1
                },
                new TimerActivity {
                    Name = "Orange", ID = 2
                },
                new TimerActivity {
                    Name = "Banana", ID = 3
                }
            }.AsQueryable());

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

            // Act
            var p1 = MVCHelper.GetViewModel <CaptionActivity>(target.EditActivity(1));
            var p2 = MVCHelper.GetViewModel <CaptionActivity>(target.EditActivity(2));
            var p3 = MVCHelper.GetViewModel <CaptionActivity>(target.EditActivity(3));

            // Assert
            Assert.Equal(1, p1.Activity.ID);
            Assert.Equal(2, p2.Activity.ID);
            Assert.Equal(3, p3.Activity.ID);
        }
Example #3
0
        public void History_Contains_All_Logs()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerLog> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerLog {
                    Activity = new TimerActivity(), Date = DateTime.Now, ID = 1
                },
                new TimerLog {
                    Activity = new TimerActivity(), Date = DateTime.Now, ID = 2
                },
                new TimerLog {
                    Activity = new TimerActivity(), Date = DateTime.Now, ID = 3
                }
            }.AsQueryable);

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

            // Action
            var result
                = MVCHelper.GetViewModel <IEnumerable <TimerLog> >(target.History())?.ToArray();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Length);
            Assert.Equal(1, result[0].ID);
            Assert.Equal(2, result[1].ID);
            Assert.Equal(3, result[2].ID);
        }
Example #4
0
        public void EditActivities_Contains_All_Activities()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerActivity> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerActivity {
                    Name = "Apple"
                },
                new TimerActivity {
                    Name = "Orange"
                },
                new TimerActivity {
                    Name = "Banana"
                }
            }.AsQueryable());

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

            // Action
            var result
                = MVCHelper.GetViewModel <IEnumerable <TimerActivity> >(target.EditActivities())?.ToArray();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Length);
            Assert.Equal("Apple", result[0].Name);
            Assert.Equal("Orange", result[1].Name);
            Assert.Equal("Banana", result[2].Name);
        }
Example #5
0
        public void Can_Edit_Sound()
        {
            // Arrange - create the mock repository
            var mock = new Mock <IRepository <TimerSound> >();

            mock.Setup(m => m.GetAll()).Returns(new[]
            {
                new TimerSound {
                    Name = "Apple", Data = new byte[] { 0x01 }, ID = 1
                },
                new TimerSound {
                    Name = "Orange", Data = new byte[] { 0x02 }, ID = 2
                },
                new TimerSound {
                    Name = "Banana", Data = new byte[] { 0x03 }, ID = 3
                }
            }.AsQueryable());

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

            // Act
            var p1 = MVCHelper.GetViewModel <EditSoundViewModel>(target.EditSound(1));
            var p2 = MVCHelper.GetViewModel <EditSoundViewModel>(target.EditSound(2));
            var p3 = MVCHelper.GetViewModel <EditSoundViewModel>(target.EditSound(3));

            // Assert
            Assert.Equal(1, p1.ID);
            Assert.Equal(2, p2.ID);
            Assert.Equal(3, p3.ID);
        }