public void FetchAllScripts_Test() { //Arange var stubFactory = new Mock<IPrompterDbContextFactory>(); var stubContext = new Mock<IPrompterDbContext>(); var scriptDbSet = new Mock<IDbSet<Script>>(); var script = new Script { ScriptId = 1, Title = "test", OptionsId = 1, Sections = new List<Section> { new Section { Order = 2, }, new Section { Order = 1, } } }; var fakeScripts = new List<Script> { script, new Script { Sections = new List<Section>() } }.AsQueryable(); stubFactory.Setup(s => s.Create()) .Returns(stubContext.Object); scriptDbSet.Setup(s => s.Provider) .Returns(fakeScripts.Provider); scriptDbSet.Setup(s => s.Expression) .Returns(fakeScripts.Expression); scriptDbSet.Setup(s => s.GetEnumerator()) .Returns(fakeScripts.GetEnumerator()); stubContext.Setup(s => s.Scripts) .Returns(scriptDbSet.Object); var service = new ScriptService(stubFactory.Object); //Act var actual = service.FetchAllScripts(); //Assert Assert.That(actual.Count, Is.EqualTo(2)); Assert.That(actual.Contains(script)); Assert.That(SectionsAreOrdered(actual[0]), Is.True); Assert.That(actual[0].Title == "test"); stubContext.Verify(s => s.Scripts, Times.Once); }
public Script Parse(Stream stream) { stream.CheckForNull("stream"); Options options = new Options(); Script script = new Script { Sections = new List<Section>(), Options = options, EntityState = EntityState.Added }; using (PresentationDocument document = PresentationDocument.Open(stream, false)) { int order = 0; for (int i = 0; i < SlidesCount(document); i++) { string notes = GetSlideNotes(document, i); if (!string.IsNullOrWhiteSpace(notes)) { script.Sections.Add( new Section { Text = notes, Order = order, SectionId = order, EntityState = EntityState.Added }); ++order; } } } return script; }
public void Get_ById_Test() { //Arange var stubScriptService = new Mock<IScriptService>(); var stubMapper = new Mock<IScriptMapper>(); var script = new Script { ScriptId = 1 }; var transferScript = new TransferScript { ScriptId = 1 }; stubScriptService.Setup(ss => ss.FetchScriptById(1)) .Returns(script); stubMapper.Setup(m => m.Map(script)) .Returns(transferScript); var controller = new ScriptController(stubScriptService.Object, stubMapper.Object, new CookieParser()); //Act var actual = controller.Get(1); //Assert Assert.That(actual.ScriptId == script.ScriptId); stubMapper.Verify(m => m.Map(script), Times.Once); stubScriptService.Verify(ss => ss.FetchScriptById(1), Times.Once); }
private bool SectionsAreOrdered(Script script) { if (script == null || script.Sections == null) { return false; } int prev = 0; foreach (var section in script.Sections) { if (section.Order < prev) return false; prev = section.Order; } return true; }