private void Then_the_contact_book_should_contains_all_other_contacts(ScenarioContext ctx) { Assert.AreElementsEqualIgnoringOrder( ctx.ContactBook.Contacts.ToArray(), ctx.AddedContacts.Except(ctx.RemovedContacts).ToArray(), "All contacts that has not been explicitly removed should be still present in contact book"); }
private void Then_all_contacts_should_be_available_in_the_contact_book(ScenarioContext ctx) { Assert.That( ctx.ContactBook.Contacts.ToArray(), Is.EquivalentTo(ctx.AddedContacts), "Contacts should be added to contact book"); }
private void Then_all_contacts_should_be_available_in_the_contact_book(ScenarioContext ctx) { Assert.AreElementsEqualIgnoringOrder( ctx.AddedContacts, ctx.ContactBook.Contacts.ToArray(), "Contacts should be added to contact book"); }
private void Then_all_contacts_should_be_available_in_the_contact_book(ScenarioContext ctx) { CollectionAssert.AreEquivalent( ctx.AddedContacts, ctx.ContactBook.Contacts.ToArray(), "Contacts should be added to contact book"); }
public void Initialize() { featureContext = new FeatureContext(null); scenarioContext = new ScenarioContext(featureContext, null); stepContext = new StepContext(featureContext, scenarioContext); sut = new ContextHandler(featureContext, scenarioContext, stepContext); }
private void Then_the_contact_book_should_contains_all_other_contacts(ScenarioContext ctx) { Assert.That( ctx.AddedContacts.Except(ctx.RemovedContacts).ToArray(), Is.EquivalentTo(ctx.ContactBook.Contacts.ToArray()), "All contacts that has not been explicitly removed should be still present in contact book"); }
private void Then_the_contact_book_should_not_contain_removed_contact_any_more(ScenarioContext ctx) { Assert.AreEqual( Enumerable.Empty<Contact>(), ctx.ContactBook.Contacts.Where(c => ctx.RemovedContacts.Contains(c)).ToArray(), "Contact book should not contain removed books"); }
public void Setup() { skeletonProviders = new Dictionary<ProgrammingLanguage, IStepDefinitionSkeletonProvider>(); skeletonProviders.Add(ProgrammingLanguage.CSharp, new Mock<IStepDefinitionSkeletonProvider>().Object); var culture = new CultureInfo("en-US"); contextManagerStub = new Mock<IContextManager>(); scenarioContext = new ScenarioContext(new ScenarioInfo("scenario_title"), null, null); contextManagerStub.Setup(cm => cm.ScenarioContext).Returns(scenarioContext); contextManagerStub.Setup(cm => cm.FeatureContext).Returns(new FeatureContext(new FeatureInfo(culture, "feature_title", "", ProgrammingLanguage.CSharp), culture)); runtimeBindingRegistryBuilderStub = new Mock<IRuntimeBindingRegistryBuilder>(); bindingRegistryStub = new Mock<IBindingRegistry>(); bindingRegistryStub.Setup(br => br.GetHooks(HookType.BeforeStep)).Returns(beforeStepEvents); bindingRegistryStub.Setup(br => br.GetHooks(HookType.AfterStep)).Returns(afterStepEvents); bindingRegistryStub.Setup(br => br.GetHooks(HookType.BeforeScenarioBlock)).Returns(beforeScenarioBlockEvents); bindingRegistryStub.Setup(br => br.GetHooks(HookType.AfterScenarioBlock)).Returns(afterScenarioBlockEvents); runtimeConfiguration = new RuntimeConfiguration(); errorProviderStub = new Mock<IErrorProvider>(); testTracerStub = new Mock<ITestTracer>(); stepDefinitionMatcherStub = new Mock<IStepDefinitionMatchService>(); methodBindingInvokerMock = new Mock<IBindingInvoker>(); stepErrorHandlers = new Dictionary<string, IStepErrorHandler>(); }
public void SetUp() { // ScenarioContext is needed, because the [Binding]-instances live there var scenarioContext = new ScenarioContext(null,new ObjectContainer()); contextManagerStub.Setup(cm => cm.ScenarioContext).Returns(scenarioContext); bindingRegistryStub.Setup(br => br.GetStepTransformations()).Returns(stepTransformations); }
public void SetUp() { // ScenarioContext is needed, because the [Binding]-instances live there var scenarioContext = new ScenarioContext(null, null, null); contextManagerStub.Setup(cm => cm.ScenarioContext).Returns(scenarioContext); List<StepTransformationBinding> stepTransformations = new List<StepTransformationBinding>(); bindingRegistryStub.Setup(br => br.StepTransformations).Returns(stepTransformations); }
void RegisterInheritanceHierarchyOfContextInSettings(ScenarioContext context) { var type = context.GetType(); while (type != typeof(object)) { endpointConfiguration.GetSettings().Set(type.FullName, scenarioContext); type = type.BaseType; } }
public Result Initialize(RunDescriptor run, EndpointBehaviour endpointBehaviour, IDictionary<Type, string> routingTable, string endpointName) { try { behaviour = endpointBehaviour; scenarioContext = run.ScenarioContext; configuration = ((IEndpointConfigurationFactory)Activator.CreateInstance(endpointBehaviour.EndpointBuilderType)).Get(); configuration.EndpointName = endpointName; if (!string.IsNullOrEmpty(configuration.CustomMachineName)) { NServiceBus.Support.RuntimeEnvironment.MachineNameAction = () => configuration.CustomMachineName; } //apply custom config settings endpointBehaviour.CustomConfig.ForEach(customAction => customAction(config)); config = configuration.GetConfiguration(run, routingTable); if (scenarioContext != null) { config.Configurer.RegisterSingleton(scenarioContext.GetType(), scenarioContext); scenarioContext.ContextPropertyChanged += scenarioContext_ContextPropertyChanged; } bus = config.CreateBus(); Configure.Instance.ForInstallationOn<Windows>().Install(); Task.Factory.StartNew(() => { while (!stopped) { contextChanged.WaitOne(TimeSpan.FromSeconds(5)); //we spin around each 5 s since the callback mechanism seems to be shaky lock (behaviour) { foreach (var when in behaviour.Whens) { if (executedWhens.Contains(when.Id)) continue; if(when.ExecuteAction(scenarioContext, bus)) executedWhens.Add(when.Id); } } } }); return Result.Success(); } catch (Exception ex) { Logger.Error("Failed to initalize endpoint " + endpointName, ex); return Result.Failure(ex); } }
private void AddSomeContacts(ScenarioContext ctx) { ctx.AddedContacts = new[] { new Contact("Jack", "123-456-789"), new Contact("Samantha", "321-654-987"), new Contact("Josh", "132-465-798") }; foreach (var contact in ctx.AddedContacts) ctx.ContactBook.AddContact(contact.Name, contact.PhoneNumber); }
void ProcessStep(Step step, Criterion criterion, ScenarioContext scenarioContext, IExecutionContextFactory executionContextFactory) { dynamic executionContext = executionContextFactory.Create(scenarioContext.Scenario, step); _progressReporter.Report(new StepStartedReport(scenarioContext.Scenario.ScenarioId, criterion.CriterionId, step.StepId, executionContext.ExecutionContextId)); StepExecutionResult result = executionContext.Execute(step as dynamic, scenarioContext); _progressReporter.Report(new StepStoppedReport(scenarioContext.Scenario.ScenarioId, criterion.CriterionId, step.StepId, executionContext.ExecutionContextId, result)); }
public void Run(Criterion criterion, ScenarioContext scenarioContext, IExecutionContextFactory executionContextFactory) { _progressReporter.Report(new CriterionStartedReport(scenarioContext.Scenario.ScenarioId, criterion.CriterionId)); foreach (Step step in criterion.Steps) { ProcessStep(step, criterion, scenarioContext, executionContextFactory); } _progressReporter.Report(new CriterionStoppedReport(scenarioContext.Scenario.ScenarioId, criterion.CriterionId)); }
public async Task Initialize(RunDescriptor run, EndpointBehavior endpointBehavior, IDictionary<Type, string> routingTable, string endpointName) { try { behavior = endpointBehavior; scenarioContext = run.ScenarioContext; runSettings = run.Settings; var endpointConfigurationFactory = (IEndpointConfigurationFactory)Activator.CreateInstance(endpointBehavior.EndpointBuilderType); endpointConfigurationFactory.ScenarioContext = run.ScenarioContext; configuration = endpointConfigurationFactory.Get(); configuration.EndpointName = endpointName; if (!string.IsNullOrEmpty(configuration.CustomMachineName)) { RuntimeEnvironment.MachineNameAction = () => configuration.CustomMachineName; } //apply custom config settings if (configuration.GetConfiguration == null) { throw new Exception($"Missing EndpointSetup<T> in the constructor of {endpointName} endpoint."); } endpointConfiguration = await configuration.GetConfiguration(run, routingTable).ConfigureAwait(false); RegisterInheritanceHierarchyOfContextInSettings(scenarioContext); endpointBehavior.CustomConfig.ForEach(customAction => customAction(endpointConfiguration, scenarioContext)); if (configuration.SendOnly) { endpointConfiguration.SendOnly(); } startable = await Endpoint.Create(endpointConfiguration).ConfigureAwait(false); if (!configuration.SendOnly) { var transportInfrastructure = endpointConfiguration.GetSettings().Get<TransportInfrastructure>(); scenarioContext.HasNativePubSubSupport = transportInfrastructure.OutboundRoutingPolicy.Publishes == OutboundRoutingType.Multicast; } } catch (Exception ex) { Logger.Error("Failed to initialize endpoint " + endpointName, ex); throw; } }
public ContextAppender(ScenarioContext context) { this.context = context; }
protected override void SetupContextTags() { var f = new FeatureContext(null, new string[0]); Tiny.TinyIoCContainer.Current.Register(f); var c = new ScenarioContext(f, null, new[] { "DontRun" }); Tiny.TinyIoCContainer.Current.Register(c); }
protected override void SetupContextTags() { var f = new FeatureContext(null, new[] { "tag1" }); Tiny.TinyIoCContainer.Current.Register(f); var c = new ScenarioContext(f, null, new[] { "tag2", "tag5" }); Tiny.TinyIoCContainer.Current.Register(c); }
private void Then_the_contact_book_should_contains_all_other_contacts(ScenarioContext ctx) { Assert.Equal( ctx.ContactBook.Contacts.ToArray(), ctx.AddedContacts.Except(ctx.RemovedContacts).ToArray()); }
public ContextAppender(ScenarioContext context, EndpointConfiguration endpointConfiguration) { this.context = context; this.endpointConfiguration = endpointConfiguration; }
private void Given_my_contact_book_is_filled_with_contacts(ScenarioContext ctx) { ctx.ContactBook = new ContactBook(); AddSomeContacts(ctx); }
private void Then_the_contact_book_should_be_empty(ScenarioContext ctx) { Assert.IsEmpty(ctx.ContactBook.Contacts, "Contact book should be empty"); }
private void Given_my_contact_book_is_empty(ScenarioContext ctx) { ctx.ContactBook = new ContactBook(); }
private void When_I_clear_it(ScenarioContext ctx) { foreach (var contact in ctx.ContactBook.Contacts.ToArray()) ctx.ContactBook.Remove(contact.Name); StepExecution.Bypass("Contact book clearing is not implemented yet. Contacts are removed one by one."); }
private void Given_my_contact_book_is_filled_with_many_contacts(ScenarioContext ctx) { for (int i = 0; i < 10000; ++i) ctx.ContactBook.AddContact(i.ToString(CultureInfo.InvariantCulture), i.ToString(CultureInfo.InvariantCulture)); }
private void When_I_add_new_contacts(ScenarioContext ctx) { AddSomeContacts(ctx); }
private void Then_all_contacts_should_be_available_in_the_contact_book(ScenarioContext ctx) { Assert.Equal( ctx.AddedContacts, ctx.ContactBook.Contacts.ToArray()); }
public ContextHandler(FeatureContext featureContext, ScenarioContext scenarioContext, StepContext stepContext) { this.featureContext = featureContext; this.scenarioContext = scenarioContext; this.stepContext = stepContext; }
private void When_I_remove_one_contact(ScenarioContext ctx) { ctx.RemovedContacts = ctx.ContactBook.Contacts.Take(1).ToArray(); foreach (var contact in ctx.RemovedContacts) ctx.ContactBook.Remove(contact.Name); }