Exemple #1
0
        public void AddTopic()
        {
            this.DataPreparer.CreateDisciplinesSet3();
            var expectedItems = this.DataPreparer.GetTopics();
            expectedItems[0].IsDeleted = true; // for test
            var controller = this.GetController<TopicController>();

            expectedItems.ForEach(item => controller.Create(item.ToCreateModel()));

            expectedItems = this.DataPreparer.GetTopics();
            var actualItems = this.DataPreparer.ChapterIds.SelectMany(id => this.DisciplineStorage.GetTopics(item => item.ChapterRef == id))
                .OrderBy(item => item.Id)
                .ToList();
            AdvAssert.AreEqual(expectedItems, actualItems);
            Assert.AreNotEqual(expectedItems.Last().SortOrder, actualItems.Last().SortOrder);

            // check authomatically added curriculum chapter topics
            actualItems.ForEach(
                item =>
                Assert.AreEqual(1, this.CurriculumStorage.GetCurriculumChapterTopics(c => c.TopicRef == item.Id).Count));

            var chapterId = this.DataPreparer.ChapterIds[0];

            // add bad topic
            controller = this.GetController<TopicController>();
            var badTopic = new Topic
                {
                    TestCourseRef = null, 
                    TestTopicTypeRef = null, 
                    TheoryCourseRef = null, 
                    TheoryTopicTypeRef = null, 
                    Name = "BadTopic", 
                    ChapterRef = chapterId, 
                };
            controller.Create(badTopic.ToCreateModel());
            Assert.AreEqual(false, controller.ModelState.IsValid);
            Assert.AreEqual(expectedItems.Count, this.DataPreparer.ChapterIds.Sum(id => this.DisciplineStorage.GetTopics(item => item.ChapterRef == id).Count));

            // add bad topic
            controller = this.GetController<TopicController>();
            badTopic = this.DataPreparer.GetTopics()[0];
            badTopic.Name = Enumerable.Repeat('A', 60).ToString();
            controller.Create(badTopic.ToCreateModel());
            Assert.AreEqual(false, controller.ModelState.IsValid);
            Assert.AreEqual(expectedItems.Count, this.DataPreparer.ChapterIds.Sum(id => this.DisciplineStorage.GetTopics(item => item.ChapterRef == id).Count));
        }