Example #1
0
        public void Can_Edit_Activity()
        {
            // Организация - создание имитированного хранилища данных
            Mock <IActivityRepository> mock = new Mock <IActivityRepository>();
            ActivityType type1 = new ActivityType {
                ActivityTypeId = Guid.NewGuid(), ActivityTypeTitle = "Один"
            };
            ActivityType type2 = new ActivityType {
                ActivityTypeId = Guid.NewGuid(), ActivityTypeTitle = "Два"
            };
            ActivityType type3 = new ActivityType {
                ActivityTypeId = Guid.NewGuid(), ActivityTypeTitle = "Три"
            };

            mock.Setup(m => m.Activities).Returns(new List <Activity>
            {
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра1", ActivityTypeCurrent = type1
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра2", ActivityTypeCurrent = type1
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра3", ActivityTypeCurrent = type2
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра4", ActivityTypeCurrent = type2
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра5", ActivityTypeCurrent = type3
                }
            });

            // Организация - создание контроллера
            AdminController controller = new AdminController(mock.Object, null);
            List <Activity> result     = ((IEnumerable <Activity>)controller.ActivitiesAdministration().ViewData.Model).ToList();

            // Действие
            Activity game1 = controller.EditActivity(result[0].ActivityId).ViewData.Model as Activity;
            Activity game2 = controller.EditActivity(result[1].ActivityId).ViewData.Model as Activity;
            Activity game3 = controller.EditActivity(result[2].ActivityId).ViewData.Model as Activity;

            // Assert
            Assert.AreEqual(result[0].ActivityId.ToString(), game1.ActivityId.ToString());
            Assert.AreEqual(result[1].ActivityId.ToString(), game2.ActivityId.ToString());
            Assert.AreEqual(result[2].ActivityId.ToString(), game3.ActivityId.ToString());
        }
Example #2
0
        public void Index_Contains_All_Activities()
        {
            // Организация - создание имитированного хранилища данных
            Mock <IActivityRepository> mock = new Mock <IActivityRepository>();

            mock.Setup(m => m.Activities).Returns(new List <Activity>
            {
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра1"
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра2"
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра3"
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра4"
                },
                new Activity {
                    ActivityId = Guid.NewGuid(), ActivityName = "Игра5"
                }
            });

            // Организация - создание контроллера
            AdminController controller = new AdminController(mock.Object, null);

            // Действие
            List <Activity> result = ((IEnumerable <Activity>)controller.ActivitiesAdministration().ViewData.Model).ToList();

            // Утверждение
            Assert.AreEqual(result.Count, 5);
            Assert.AreEqual("Игра1", result[0].ActivityName);
            Assert.AreEqual("Игра2", result[1].ActivityName);
            Assert.AreEqual("Игра3", result[2].ActivityName);
        }