static void ThrowIfChapterAlreadyExist(ISaga saga, IChapter chapter) { if (saga.Chapters.Any(s => s.GetType() == chapter.GetType())) { throw new ChapterAlreadyExistException(); } }
#pragma warning disable 1591 // Xml Comments public ICanValidate GetValidatorFor(IChapter chapter) { if (chapter == null) return NullChapterValidator; var type = chapter.GetType(); return GetValidatorFor(type); }
public void SetCurrentChapter(IChapter chapter) { CurrentChapter = chapter; if (!Contains(chapter.GetType())) { AddChapter(chapter); } chapter.OnSetCurrent(); }
#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); } }
#pragma warning restore 1591 // Xml Comments ChapterHolder GetChapterHolderFromChapter(IChapter chapter) { var chapterHolder = new ChapterHolder { Type = chapter.GetType().AssemblyQualifiedName, SerializedChapter = _serializer.ToJson(chapter) }; return(chapterHolder); }
#pragma warning disable 1591 // Xml Comments public ICanValidate GetValidatorFor(IChapter chapter) { if (chapter == null) { return(NullChapterValidator); } var type = chapter.GetType(); return(GetValidatorFor(type)); }
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); }
/// <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())); }
#pragma warning restore 1591 // Xml Comments ChapterHolder GetChapterHolderFromChapter(IChapter chapter) { var chapterHolder = new ChapterHolder { Type = chapter.GetType().AssemblyQualifiedName, SerializedChapter = _serializer.ToJson(chapter) }; return chapterHolder; }
public void AddChapter(IChapter chapter) { ThrowIfChapterAlreadyExist(chapter.GetType()); _chapters.Add(chapter); SetChapterPropertyIfAny(chapter); }