コード例 #1
0
        public void Show_Topics_Test()
        {
            ICollection <IntermediateCategory> intercat = new List <IntermediateCategory> {
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 1, NameOfMainCategory = "Zdrowie ", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 2, NameOfMainCategory = "Kuchnia ", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 3, NameOfMainCategory = "Sport ", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 4, NameOfMainCategory = "Kino", MainCategoryByCitiesId = 1
                }
            }.ToList();

            ICollection <Topic> topics = new List <Topic> {
                new Topic {
                    TopicId = 1, TopicData = "Data 1", TopicName = "Topic 1", IntermediateCategoryId = 1
                },
                new Topic {
                    TopicId = 2, TopicData = "Data 2", TopicName = "Topic 2", IntermediateCategoryId = 1
                },
                new Topic {
                    TopicId = 3, TopicData = "Data 3", TopicName = "Topic 3", IntermediateCategoryId = 1
                }
            };


            Mock <IIntermediateCategoryRepository> mockI = new Mock <IIntermediateCategoryRepository>();

            mockI.Setup(m => m.Get(1)).Returns(new IntermediateCategory()
            {
                IntermediateCategoryId = 1, NameOfMainCategory = "Zdrowie ", MainCategoryByCitiesId = 1, Topic = topics
            });

            Mock <ITopicRepository> mockT = new Mock <ITopicRepository>();

            TopicController controller = new TopicController(mockT.Object, mockI.Object);

            IEnumerable <Topic> topicResult = (IEnumerable <Topic>)controller.Show_Topics(1).Model;

            ViewResult resultx = controller.Show_Topics(1) as ViewResult;
            string     text    = resultx.ViewName;

            Topic[] result = topicResult.ToArray();

            Assert.IsTrue(result.Length == 3);
            Assert.AreEqual(result[0].TopicId, 1);
            Assert.AreEqual(result[1].TopicName, "Topic 2");
            Assert.AreEqual(result[2].TopicData, "Data 3");
        }
コード例 #2
0
        public void Show_Topics_Test_id_out_of_range()
        {
            ICollection <IntermediateCategory> intercat = new List <IntermediateCategory> {
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 1, NameOfMainCategory = "Zdrowie ", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 2, NameOfMainCategory = "Kuchnia ", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 3, NameOfMainCategory = "Sport ", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 4, NameOfMainCategory = "Kino", MainCategoryByCitiesId = 1
                },
                new IntermediateCategory()
                {
                    IntermediateCategoryId = 0, NameOfMainCategory = "Error", Topic = new List <Topic>()
                }
            }.ToList();



            Mock <IIntermediateCategoryRepository> mockI = new Mock <IIntermediateCategoryRepository>();

            mockI.Setup(m => m.Get(666)).Returns(new IntermediateCategory()
            {
                IntermediateCategoryId = 1, NameOfMainCategory = "Error", Topic = new List <Topic>()
            });
            Mock <ITopicRepository> mockT = new Mock <ITopicRepository>();

            TopicController controller = new TopicController(mockT.Object, mockI.Object);

            ViewResult result = controller.Show_Topics(666) as ViewResult;

            string viewName = result.ViewName;

            Assert.AreEqual(result.ViewName.ToString(), "Error");
        }