Esempio n. 1
0
 static void ThrowIfChapterAlreadyExist(ISaga saga, IChapter chapter)
 {
     if (saga.Chapters.Any(s => s.GetType() == chapter.GetType()))
     {
         throw new ChapterAlreadyExistException();
     }
 }
Esempio n. 2
0
#pragma warning disable 1591 // Xml Comments
        public ICanValidate GetValidatorFor(IChapter chapter)
        {
            if (chapter == null)
                return NullChapterValidator;

            var type = chapter.GetType();
            return GetValidatorFor(type);
        }
Esempio n. 3
0
 public void SetCurrentChapter(IChapter chapter)
 {
     CurrentChapter = chapter;
     if (!Contains(chapter.GetType()))
     {
         AddChapter(chapter);
     }
     chapter.OnSetCurrent();
 }
Esempio n. 4
0
#pragma warning restore 1591 // Xml Comments
        void SetChapterPropertyIfAny(IChapter chapter)
        {
            var property = ChapterProperties.Where(p => p.PropertyType.Equals(chapter.GetType())).SingleOrDefault();

            if (property != null)
            {
                property.SetValue(this, chapter, null);
            }
        }
Esempio n. 5
0
#pragma warning restore 1591 // Xml Comments



        ChapterHolder GetChapterHolderFromChapter(IChapter chapter)
        {
            var chapterHolder = new ChapterHolder
            {
                Type = chapter.GetType().AssemblyQualifiedName,
                SerializedChapter = _serializer.ToJson(chapter)
            };

            return(chapterHolder);
        }
Esempio n. 6
0
#pragma warning disable 1591 // Xml Comments
        public ICanValidate GetValidatorFor(IChapter chapter)
        {
            if (chapter == null)
            {
                return(NullChapterValidator);
            }

            var type = chapter.GetType();

            return(GetValidatorFor(type));
        }
Esempio n. 7
0
        public IEnumerator Chapter()
        {
            // Given we have a training with a chapter
            ICourse training1 = new LinearTrainingBuilder("Training")
                                .AddChapter(new LinearChapterBuilder("Chapter")
                                            .AddStep(new BasicStepBuilder("Step")))
                                .Build();

            // When we serialize and deserialize it
            ICourse training2 = JsonTrainingSerializer.Deserialize((JsonTrainingSerializer.Serialize(training1)));

            // Then chapter's type, name, first step and next chapter should not change.
            IChapter chapter1 = training1.Data.FirstChapter;
            IChapter chapter2 = training2.Data.FirstChapter;

            Assert.AreEqual(chapter1.GetType(), chapter2.GetType());
            Assert.AreEqual(chapter1.Data.Name, chapter2.Data.Name);
            Assert.AreEqual(chapter1.Data.FirstStep.Data.Name, chapter2.Data.FirstStep.Data.Name);
            Assert.AreEqual(training1.Data.Chapters.Count, training2.Data.Chapters.Count);

            return(null);
        }
Esempio n. 8
0
 /// <summary>
 /// Check if a transition is allowed between to chapters by instance of chapters
 /// </summary>
 /// <param name="fromChapter">From <see cref="IChapter"/></param>
 /// <param name="toChapter">To <see cref="IChapter"/></param>
 /// <returns>True if transition is allowed, false if not</returns>
 public static bool CanTransition(IChapter fromChapter, IChapter toChapter)
 {
     return(CanTransition(fromChapter.GetType(), toChapter.GetType()));
 }
Esempio n. 9
0
#pragma warning restore 1591 // Xml Comments



        ChapterHolder GetChapterHolderFromChapter(IChapter chapter)
		{
			var chapterHolder = new ChapterHolder
			                    	{
			                    		Type = chapter.GetType().AssemblyQualifiedName,
			                    		SerializedChapter = _serializer.ToJson(chapter)
			                    	};
			return chapterHolder;
		}
Esempio n. 10
0
 public void AddChapter(IChapter chapter)
 {
     ThrowIfChapterAlreadyExist(chapter.GetType());
     _chapters.Add(chapter);
     SetChapterPropertyIfAny(chapter);
 }