public void SetupContext() { var mapper = new SessionContext(); mapper.AddContext <ScenarioLifetimeTestMappingContext>(); StoryContext = mapper.GetContextForStory(); }
public async Task UserCreatedEventHandler_Consume_Creates_User() { StoryContext.OpenInMemoryConnection(); try { var userCreatedEvent = new UserCreatedEvent { UserKey = Guid.NewGuid(), ProfileImage = "image", FirstName = "John", LastName = "Doe" }; using (var context = StoryContext.GetInMemoryContext()) { var handler = new UserCreatedEventHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); await handler.ConsumeAsync(userCreatedEvent); } using (var context = StoryContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Users.Count()); Assert.AreEqual(userCreatedEvent.UserKey, context.Users.Single().UserKey); Assert.AreEqual(userCreatedEvent.ProfileImage, context.Users.Single().ProfileImage); Assert.AreEqual(Helpers.GetUserName(userCreatedEvent), context.Users.Single().Name); } } finally { StoryContext.CloseInMemoryConnection(); } }
public async Task GetCharitiesRequestHandler_Handle_Returns_Charities() { StoryContext.OpenInMemoryConnection(); try { using (var context = StoryContext.GetInMemoryContext()) { for (var i = 0; i < 25; i++) { context.Charities.Add(new Charity { CharityKey = Guid.NewGuid(), Name = "charity" }); } context.SaveChanges(); } GetCharitiesResponse response; using (var context = StoryContext.GetInMemoryContext()) { var handler = new GetCharitiesRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetCharitiesRequest()); } Assert.AreEqual(25, response.Charities.Count); } finally { StoryContext.CloseInMemoryConnection(); } }
public void Clear() { using (var context = new StoryContext(DbPath)) { context.Items.RemoveRange(context.Items); } }
public Storyboard() { Root = new StoryboardBlock(null); current = Root; stack = new Stack <StoryboardBlock>(); Context = new StoryContext(); }
public string Get(string key) { using (var context = new StoryContext(DbPath)) { return(context.Items.Find(key)?.Value); } }
public string MakeUpBeginning(StoryContext context) { return(string.Format("Once upon a time there was a {0} {1} named {2}, who liked {3}", context.MainCharacter.Adjective, context.MainCharacter.Type, context.MainCharacter.Name, WhatDidHeLike(context.MainCharacter))); }
protected void BeforeAll() { _eventBus = StorEvilEvents.Bus; _sessionContext = TestSession.SessionContext(GetType().Assembly.Location).GetContextForStory(); _interpreter = TestSession.GetInterpreter(GetType().Assembly.Location); _scenarioLineExecuter = new ScenarioLineExecuter(_interpreter, _eventBus); }
public void MakeUpBeginning_ShouldStartWithOnceUponATime() { StoryContext context = new StoryContext(); context.MainCharacter = new Character("baboon", "Bob", "silly", "fruit"); var result = imagination.MakeUpBeginning(context); Assert.Contains("Once upon a time", result); }
public async Task CreateStoryRequestHandler_Handle_Returns_InvalidUserKey() { StoryContext.OpenInMemoryConnection(); try { var author = new User { UserKey = Guid.NewGuid() }; var charity = new Charity { CharityKey = Guid.NewGuid() }; using (var context = StoryContext.GetInMemoryContext()) { context.Users.Add(author); context.Charities.Add(charity); context.SaveChanges(); } var request = new CreateStoryRequest { CharityKey = charity.CharityKey, StoryKey = Guid.NewGuid(), AuthorUserKey = Guid.NewGuid(), Title = "title", CoverImage = "cover", Images = new List <string> { "image1", "image2" } }; CreateStoryResponse response; using (var context = StoryContext.GetInMemoryContext()) { var handler = new CreateStoryRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(request); } using (var context = StoryContext.GetInMemoryContext()) { Assert.IsFalse(response.IsSuccess); Assert.IsFalse(context.Stories.Any()); Assert.IsFalse(context.Images.Any()); Assert.AreEqual(ErrorType.InvalidUserKey, response.ErrorType); } } finally { StoryContext.CloseInMemoryConnection(); } }
public void Delete(string key) { using (var context = new StoryContext(DbPath)) { context.Items.Remove(new StoryContextItem() { Key = key }); } }
public StoryContext WhatDoTheyWantAStoryAbout(List <Word> words) { if (words.Count == 0) { throw new InvalidInputException(); } StoryContext storyContext = new StoryContext(); storyContext.MainCharacter = WhoIsTheMainCharacter(words); storyContext.WordsToUse = words; return(storyContext); }
void Start() { StoryContext context = new StoryContext(); context.StoryEntry = this; StoryRunner runner = new StoryRunner(); context.StoryPlayer = runner; installer.Install(context); context.Resolve(); runner.Run(installer.GetScenarioName()); }
/// <summary> /// Notifies the client that its Control has been activated. Activation occurs when /// the Control gets focus, or a parent "host" Control gets focus.</summary> /// <param name="control">Client Control that was activated</param> /// <remarks>This method is only called by IControlHostService if the Control was previously /// registered for this IControlHostClient.</remarks> public void Activate(Control control) { if (control.Tag is StoryDocument) { IDocument doc = (IDocument)control.Tag; m_documentRegistry.ActiveDocument = doc; StoryContext context = doc.As <StoryContext>(); m_contextRegistry.ActiveContext = context; m_commandService.SetActiveClient(this); } }
protected void StartScenario(Story story, Scenario scenario) { _eventBus.Raise(new ScenarioStarting { Scenario = scenario }); if (CurrentStoryContext == null) { CurrentStoryContext = _context.GetContextForStory(); } CurrentScenarioContext = CurrentStoryContext.GetScenarioContext(); CurrentScenario = scenario; LastStatus = LineStatus.Passed; //ScenarioInterpreter.NewScenario(); }
protected void RunStory(Story story) { FakeEventBus = new CapturingEventBus(); //new ExtensionMethodHandler(new AssemblyRegistry(new[] { typeof(TestExtensionMethods).Assembly})); Context = new StoryContext(new FakeSessionContext(), typeof(T)); if (UseCompilingRunner()) { RunInCompilingRunner(story); } else { GetRunner().HandleStory(story); } }
public async Task GetStoryByUrlRequestHandler_Handle_Returns_Story() { StoryContext.OpenInMemoryConnection(); try { var charity = new Charity { CharityKey = Guid.NewGuid(), Url = "some" }; var story = new Story { StoryKey = Guid.NewGuid(), Title = "title", Charity = charity, UrlComponent = "none" }; using (var context = StoryContext.GetInMemoryContext()) { context.Stories.Add(story); context.SaveChanges(); } GetStoryByUrlResponse response; using (var context = StoryContext.GetInMemoryContext()) { var handler = new GetStoryByUrlRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetStoryByUrlRequest { CharityUrl = "some", StoryUrlComponent = "none" }); } Assert.IsTrue(response.IsSuccess); Assert.AreEqual(story.StoryKey, response.Story.StoryKey); Assert.AreEqual(story.Title, response.Story.Title); Assert.IsNull(response.Story.AuthorUserKey); } finally { StoryContext.CloseInMemoryConnection(); } }
public async Task CharityUpdatedEventHandler_Handles_Event() { StoryContext.OpenInMemoryConnection(); try { var charityUpdatedEvent = new CharityUpdatedEvent { CharityKey = Guid.NewGuid(), Name = "newName" }; var otherKey = Guid.NewGuid(); using (var context = StoryContext.GetInMemoryContext()) { var charity1 = new Charity { CharityKey = charityUpdatedEvent.CharityKey, Name = "oldName" }; var charity2 = new Charity { CharityKey = otherKey, Name = "otherOldName" }; context.Charities.Add(charity1); context.Charities.Add(charity2); context.SaveChanges(); } using (var context = StoryContext.GetInMemoryContext()) { var handler = new CharityUpdatedEventHandler(context); await handler.ConsumeAsync(charityUpdatedEvent); } using (var context = StoryContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Charities.Count(a => a.CharityKey == charityUpdatedEvent.CharityKey && a.Name == charityUpdatedEvent.Name)); Assert.AreEqual(1, context.Charities.Count(a => a.CharityKey == otherKey && a.Name == "otherOldName")); } } finally { StoryContext.CloseInMemoryConnection(); } }
public void HandleStory(Story story) { EventBus.Raise(new StoryStarting { Story = story }); Scenario[] scenariosMatchingFilter = GetScenariosMatchingFilter(story); using (StoryContext contextForStory = _context.GetContextForStory()) { Execute(story, scenariosMatchingFilter, contextForStory); } EventBus.Raise(new StoryFinished { Story = story }); }
public async Task ApproveStoryRequestHandler_Handle_Returns_AlreadyActive() { StoryContext.OpenInMemoryConnection(); try { var charity = new Charity { CharityKey = Guid.NewGuid() }; var story = new Story { StoryKey = Guid.NewGuid(), IsApproved = true, Charity = charity }; using (var context = StoryContext.GetInMemoryContext()) { context.Stories.Add(story); context.SaveChanges(); } ApproveStoryResponse response; using (var context = StoryContext.GetInMemoryContext()) { var handler = new ApproveStoryRequestHandler(context); response = await handler.Handle(new ApproveStoryRequest { StoryKey = story.StoryKey }); } using (var context = StoryContext.GetInMemoryContext()) { Assert.IsFalse(response.IsSuccess); Assert.IsTrue(context.Stories.Single().IsApproved); Assert.AreEqual(ErrorType.AlreadyActive, response.ErrorType); } } finally { StoryContext.CloseInMemoryConnection(); } }
public async Task UserUpdatedEventHandler_Consume_Updates_Name() { StoryContext.OpenInMemoryConnection(); try { var userUpdatedEvent = new UserUpdatedEvent { UserKey = Guid.NewGuid(), FirstName = "Ellen", LastName = "Doe", EmailAddress = "*****@*****.**", ProfileImage = "new image" }; var user = new User { UserKey = userUpdatedEvent.UserKey, Name = "John Doe", ProfileImage = "old image" }; using (var context = StoryContext.GetInMemoryContext()) { context.Users.Add(user); context.SaveChanges(); } using (var context = StoryContext.GetInMemoryContext()) { var handler = new UserUpdatedEventHandler(context); await handler.ConsumeAsync(userUpdatedEvent); } using (var context = StoryContext.GetInMemoryContext()) { Assert.AreEqual("Ellen Doe", context.Users.Single().Name); Assert.AreEqual("new image", context.Users.Single().ProfileImage); } } finally { StoryContext.CloseInMemoryConnection(); } }
public async Task UserUpdatedEventHandler_Consume_Event_Has_No_UserKey() { StoryContext.OpenInMemoryConnection(); try { var userUpdatedEvent = new UserUpdatedEvent { UserKey = Guid.Empty, FirstName = "Ellen", LastName = "Doe", ProfileImage = "new image" }; var charityAction = new User { UserKey = Guid.NewGuid(), Name = "John Doe", ProfileImage = "old image" }; using (var context = StoryContext.GetInMemoryContext()) { context.Users.Add(charityAction); context.SaveChanges(); } using (var context = StoryContext.GetInMemoryContext()) { var handler = new UserUpdatedEventHandler(context); await handler.ConsumeAsync(userUpdatedEvent); } using (var context = StoryContext.GetInMemoryContext()) { Assert.AreEqual("John Doe", context.Users.Single().Name); Assert.AreEqual("old image", context.Users.Single().ProfileImage); } } finally { StoryContext.CloseInMemoryConnection(); } }
private void contextRegistry_ActiveContextChanged(object sender, EventArgs e) { // make sure we're always tracking the most recently active EventSequenceContext StoryContext context = m_contextRegistry.GetMostRecentContext <StoryContext>(); if (m_storyContext != context) { m_storyContext = context; Story story = m_storyContext.Cast <Story>(); if (story.Settings == null) { //DomNode node = new DomNode(Schema.settingsType.Type, Schema.storyType.settingsChild); //story.Cast<DomNode>().SetChild(Schema.storyType.settingsChild, node); story.Settings = Settings.New(Schema.storyType.settingsChild); } m_CharacterSettingsContext = story.Settings.Cast <CharacterSettingsContext>(); m_characteListViewAdapter.ListView = m_CharacterSettingsContext; } }
public async Task GetStoryByKeyRequestHandler_Handle_Returns_No_Story() { StoryContext.OpenInMemoryConnection(); try { var charity = new Charity { CharityKey = Guid.NewGuid() }; var story = new Story { StoryKey = Guid.NewGuid(), Title = "title", Charity = charity }; using (var context = StoryContext.GetInMemoryContext()) { context.Stories.Add(story); context.SaveChanges(); } GetStoryByKeyResponse response; using (var context = StoryContext.GetInMemoryContext()) { var handler = new GetStoryByKeyRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetStoryByKeyRequest { StoryKey = Guid.NewGuid() }); } Assert.IsFalse(response.IsSuccess); Assert.IsNull(response.Story); } finally { StoryContext.CloseInMemoryConnection(); } }
public async Task GetStoriesRequestHandlerTests_Handle_Returns_Stories() { StoryContext.OpenInMemoryConnection(); try { var charity = new Charity { CharityKey = Guid.NewGuid() }; using (var context = StoryContext.GetInMemoryContext()) { for (var i = 0; i < 25; i++) { context.Stories.Add(new Story { StoryKey = Guid.NewGuid(), Charity = charity }); } context.SaveChanges(); } GetStoriesResponse response; using (var context = StoryContext.GetInMemoryContext()) { var handler = new GetStoriesRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(new GetStoriesRequest { PageNumber = 2, PageSize = 20 }); } Assert.AreEqual(25, response.TotalNumberOfResults); Assert.AreEqual(5, response.Results.Count); } finally { StoryContext.CloseInMemoryConnection(); } }
public ActionResult Index() { StoryContext context = new StoryContext(); var stories = context.Stories.ToList(); return(View()); //try //{ // int x = 10000; // for (int i = 10; i>= -10; i--) // { // x = x / i; // } //}catch(Exception ex) //{ // log.Debug("Error in index", ex); //} }
public async Task CharityCreatedEventHandler_Handle_Returns_Success() { StoryContext.OpenInMemoryConnection(); try { var Event = new CharityCreatedEvent() { Category = Core.Enums.Category.EnvironmentAndNatureConservation, CharityKey = Guid.NewGuid(), CoverImage = "No image given", Email = "*****@*****.**", IBAN = "NotReallyAnIBAN", KVKNumber = "10", Name = "TestName", Url = "test", OwnerUserName = "******", Slogan = "This is a very good testing slogan", ThankYou = "ThankYou" }; using (var context = StoryContext.GetInMemoryContext()) { var handler = new CharityCreatedEventHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); await handler.ConsumeAsync(Event); } using (var context = StoryContext.GetInMemoryContext()) { Assert.AreEqual(1, context.Charities.Count()); Assert.AreEqual(Event.Name, context.Charities.Single().Name); Assert.AreEqual(Event.Url, context.Charities.Single().Url); } } finally { StoryContext.CloseInMemoryConnection(); } }
public bool Save(string key, string value) { using (var context = new StoryContext(DbPath)) { var record = new StoryContextItem() { Key = key, Value = value }; var exists = context.Items.Any(t => string.Equals(key, t.Key)); if (exists) { context.Items.Update(record); } else { context.Items.Add(record); } return(context.SaveChanges() > 0); } }
public string GimmeAGoodEnding(StoryContext context) { return(string.Format("Um, yeah. And {0} lived happily ever after!", context.MainCharacter.Name)); }
public void SetupContext() { var mapper = new StoryContextFactory(); mapper.AddContext<TestMappingContext>(); StoryContext = mapper.GetContextForStory(new Story("", "", new IScenario[] {})); }
public void AllLinksExistFor_Test() { // Arrange var sut = new StoryContext { Stories = new List <IStory> { new Story { Acts = new List <IAct> { new Act { Name = "Something", Choices = new List <IChoice> { new BaseChoice { Text = "abc", Triggers = new List <ITrigger> { new BaseTrigger { Link = "Link 1" } } } } }, new Sequence { Name = "Link 1", Choices = new List <IChoice> { new BaseChoice { Text = "def", Triggers = new List <ITrigger> { new BaseTrigger { Link = "Link 2" } } } } } } }, new Story { Acts = new List <IAct> { new Act { Name = "A Name", Choices = new List <IChoice> { new BaseChoice { Text = "ghi", Triggers = new List <ITrigger> { new BaseTrigger { Link = "Link 1" } } } } }, new Sequence { Name = "Link 2", Choices = new List <IChoice> { new BaseChoice { Text = "jkl", Triggers = new List <ITrigger> { new BaseTrigger { Link = "A Name" } } } } } }, Sequences = new List <ISequence> { new Sequence { Name = "Another", Choices = new List <IChoice> { new BaseChoice { Text = "mno", Triggers = new List <ITrigger> { new BaseTrigger { Link = "Something" } } } } } } } } }; // Act var t1 = sut.AllLinksExistFor(sut.Stories[0].Acts[0]); var t2 = sut.AllLinksExistFor(sut.Stories[0].Acts[1]); var t3 = sut.AllLinksExistFor(sut.Stories[1].Acts[0]); var t4 = sut.AllLinksExistFor(sut.Stories[1].Acts[1]); var t5 = sut.AllLinksExistFor(sut.Stories[1].Sequences[0]); // Assert t1.Should().BeTrue(); t2.Should().BeTrue(); t3.Should().BeTrue(); t4.Should().BeTrue(); t5.Should().BeTrue(); }
private object GetScenarioContext(StoryContext storyContext) { return storyContext.GetScenarioContext().GetContext(TestContextType); }
private void contextRegistry_ActiveContextChanged(object sender, EventArgs e) { // make sure we're always tracking the most recently active EventSequenceContext StoryContext context = m_contextRegistry.GetMostRecentContext<StoryContext>(); if (m_storyContext != context) { m_storyContext = context; Story story = m_storyContext.Cast<Story>(); if(story.Settings == null) { //DomNode node = new DomNode(Schema.settingsType.Type, Schema.storyType.settingsChild); //story.Cast<DomNode>().SetChild(Schema.storyType.settingsChild, node); story.Settings = Settings.New(Schema.storyType.settingsChild); } m_CharacterSettingsContext = story.Settings.Cast<CharacterSettingsContext>(); m_characteListViewAdapter.ListView = m_CharacterSettingsContext; } }
public void SetupContext() { var mapper = new SessionContext(); mapper.AddContext<ScenarioLifetimeTestMappingContext>(); StoryContext = mapper.GetContextForStory(); }