public void When_Using_Custom_Named_Template_Payload_Loads_Correctly() { const string rawTemplate = "{\"deviceId\": \"$.DeviceId\" }"; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { Constants.PayloadDistributionConfigName, "fixSize(51,12) template(49, mytemplate)" }, { "mytemplate", rawTemplate } }) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); Assert.Equal(2, target.PayloadGenerator.Payloads.Length); // will be ordered by percentage var fixPayload = Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[0]); Assert.Equal(51, target.PayloadGenerator.Payloads[0].Distribution); Assert.Equal(12, fixPayload.Payload.Length); var templatedPayload = Assert.IsType <TemplatedPayload>(target.PayloadGenerator.Payloads[1]); Assert.Equal(49, target.PayloadGenerator.Payloads[1].Distribution); Assert.Equal(rawTemplate, templatedPayload.Template.ToString()); }
public void TestFormatter() { var outputLines = new List <string>(); var parameters = new Dictionary <string, string> { { "ServerInstance", "." }, { "Username", "sa" }, { "Password", "SA_PASSWORD" } }; var conf = new RunnerConfiguration { IsRemote = false, OnObjectOutput = line => { outputLines.Add(line); }, Parameters = parameters }; var runner = new PowerShellRunner(conf); runner.Run(ScriptFile); Assert.AreEqual(outputLines.Count, 2); Assert.IsTrue(outputLines.ElementAt(0).Contains("Connecting")); Assert.IsTrue(outputLines.ElementAt(1).Contains("TimeOfQuery")); }
public void When_Using_Base64_Fix_Payload_Loads_Correctly() { const string rawTemplate = "{\"deviceId\": \"$.DeviceId\" }"; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { Constants.PayloadDistributionConfigName, "fix(10, MTA=) template(25, default) fix(65, NjU=)" }, { "mytemplate", rawTemplate } }) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); Assert.Equal(3, target.PayloadGenerator.Payloads.Length); // will be ordered by percentage var fixPayload65 = Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[0]); Assert.Equal(65, fixPayload65.Distribution); Assert.Equal("65", Encoding.UTF8.GetString(fixPayload65.Payload)); Assert.Equal(2, fixPayload65.Payload.Length); var templatedPayload = Assert.IsType <TemplatedPayload>(target.PayloadGenerator.Payloads[1]); Assert.Equal(25, templatedPayload.Distribution); Assert.Equal(RunnerConfiguration.DefaultTemplate, templatedPayload.Template.ToString()); var fixPayload10 = Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[2]); Assert.Equal(10, fixPayload10.Distribution); Assert.Equal("10", Encoding.UTF8.GetString(fixPayload10.Payload)); Assert.Equal(2, fixPayload10.Payload.Length); }
public void When_Using_Dynamic_Payload_Loads_Correctly() { var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { Constants.PayloadDistributionConfigName, "fixSize(10,12) template(25, default) fix(65, aaaaBBBBBCCC)" }, }) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); Assert.Equal(3, target.PayloadGenerator.Payloads.Length); // will be ordered by percentage Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[0]); Assert.Equal(65, target.PayloadGenerator.Payloads[0].Distribution); Assert.Equal(9, ((FixPayload)target.PayloadGenerator.Payloads[0]).Payload.Length); Assert.IsType <TemplatedPayload>(target.PayloadGenerator.Payloads[1]); Assert.Equal(25, target.PayloadGenerator.Payloads[1].Distribution); Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[2]); Assert.Equal(10, target.PayloadGenerator.Payloads[2].Distribution); Assert.Equal(12, ((FixPayload)target.PayloadGenerator.Payloads[2]).Payload.Length); }
/// <summary> /// Builds a default run state for test purposes. /// </summary> /// <param name="model">The application model to include in the run state.</param> /// <returns>A run state object.</returns> public static RunState BuildRunState(IApplicationModel model) { var config = new RunnerConfiguration() { FailFast = true, FailStages = Runner.Core.Stages.All }; config.Args.Add("microsoft.cli.findpaths", new string[] { "C:\\source\\repos\\ambiztalk\\src\\Microsoft.AzureIntegrationMigration.BizTalk.StageRunners\\bin\\Debug" }); config.Args.Add("microsoft.cli.findpatterns", "*StageRunners*.dll"); config.Args.Add("microsoft.cli.templateconfigpath", "C:\\source\\repos\\ambiztalk\\config"); config.Args.Add("microsoft.biztalk.msidiscoverer.msidir", "C:\\Temp\\Scenarios"); config.Args.Add("microsoft.biztalk.msidiscoverer.unpackdir", "C:\\Temp\\Output"); var stageRunner1 = new Mock <IStageRunner>(); stageRunner1.Object.Priority = 1; stageRunner1.Object.Skip = false; config.StageRunners.Add(stageRunner1.Object); var stageRunner2 = new Mock <IStageRunner>(); stageRunner2.Object.Priority = 2; stageRunner2.Object.Skip = false; config.StageRunners.Add(stageRunner2.Object); var state = new RunState(config, model); return(state); }
public static IApp StartApp(Platform platform, RunnerConfiguration runnerConfiguration) { if (platform == Platform.Android) { return(ConfigureApp .Android .ApkFile(runnerConfiguration.AndroidConfiguration.AppPath) .EnableLocalScreenshots() .StartApp()); } if (runnerConfiguration.IosConfiguration.Simulator) { return(ConfigureApp .iOS .DeviceIdentifier(runnerConfiguration.IosConfiguration.SimulatorIdentifier) .AppBundle(runnerConfiguration.IosConfiguration.AppPath) .EnableLocalScreenshots() .StartApp()); } var iosDeviceIdentifier = runnerConfiguration.IosConfiguration.DeviceIdentifier; var iosBundleName = runnerConfiguration.IosConfiguration.BundleName; return(ConfigureApp .iOS .DeviceIdentifier(iosDeviceIdentifier) .InstalledApp(iosBundleName) .PreferIdeSettings() .EnableLocalScreenshots() .StartApp()); }
public static TRunner Configure <TRunner>( this TRunner runner, Action <IConfigure> configure) where TRunner : ReflectionBasedScenarioRunner { var runnerConfiguration = new RunnerConfiguration(runner); configure(runnerConfiguration); return(runner); }
public void When_Loading_From_File_With_Custom_Intervals_Loads_Correctly() { var configuration = new ConfigurationBuilder() .AddJsonFile("./test_files/test4-config-multiple-internals-per-device.json", false, false) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.Equal(10_000, target.GetMessageIntervalForDevice("sim000001")[0]); Assert.Equal(100, target.GetMessageIntervalForDevice("sim000002")[0]); Assert.Equal(1_000, target.GetMessageIntervalForDevice("sim000003")[0]); }
public FeatureBase(Platform platform) { RunnerConfiguration.Platform = platform; if (!RunnerConfiguration.IsAppCenterTest) { RunnerConfiguration.GetInstance(); } BaseAppInitializer = new BaseAppInitializer(); RunnerConfiguration.Current.ScreenQueries = new ScreenQueries(RunnerConfiguration.Platform); }
public void DisableStage(IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config = new RunnerConfiguration()); "When disabling the Verify stage" .x(() => e = Record.Exception(() => config.Stages -= Stages.Verify)); "Then the property set should succeed" .x(() => e.Should().BeNull()); "And the Stages property should not have the Verify stage enabled" .x(() => config.Stages.Should().NotHaveFlag(Stages.Verify)); }
public void SetStage(IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config = new RunnerConfiguration()); "When setting the Stages property to Assessment" .x(() => e = Record.Exception(() => config.Stages = Stages.Assessment)); "Then the property set should succeed" .x(() => e.Should().BeNull()); "And the Stages property should be set to Assessment" .x(() => config.Stages.Should().Be(Stages.Assessment)); }
public void SetFailStageWithAllStages(IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config = new RunnerConfiguration()); "When enabling the fail fast flag for all stages" .x(() => e = Record.Exception(() => config.Stages |= Stages.All)); "Then enabling all flags should succeed" .x(() => e.Should().BeNull()); "And the FailStages property should have all stages enabled" .x(() => config.Stages.Should().HaveFlag(Stages.All)); }
public void EnableFailFast(IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config = new RunnerConfiguration()); "When setting the FailFast property to True" .x(() => e = Record.Exception(() => config.FailFast = true)); "Then the property set should succeed" .x(() => e.Should().BeNull()); "And the FailFast property should be set to True" .x(() => config.FailFast.Should().BeTrue()); }
public void SetUp() { var config = new RunnerConfiguration(); config.AddProviderValidator(new DuplicateVersionsValidator()); config.AddCleaner(new ConsolidateDuplicateReleasesCleaner()); config.AddStatsProvider(new NuGetStatsProvider()); config.AddStatsProvider(new GitHubStatsProvider("Particular")); config.AddProjectProvider(new GitHubProjectProvider("Particular")); releaseStatsRunner = ReleaseStatsFactory.CreateRunner(config); }
public void When_Loading_From_File_Loads_Correctly() { var configuration = new ConfigurationBuilder() .AddJsonFile("./test_files/test1-config.json", false, false) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); var payload = Assert.Single(target.PayloadGenerator.Payloads); var templatedPayload = Assert.IsType <TemplatedPayload>(payload); Assert.Equal(2, templatedPayload.Variables.Variables.Count); Assert.True(templatedPayload.Variables.Variables[0].Sequence); Assert.Equal(new[] { "Counter" }, templatedPayload.Variables.Variables[0].GetReferenceVariableNames()); }
public void When_Loading_From_File_With_Variable_Intervals_Loads_Correctly() { var configuration = new ConfigurationBuilder() .AddJsonFile("./test_files/test6-config-payloads-with-variable-intervals.json", false, false) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); int[] intervalsDevice1 = target.GetMessageIntervalForDevice("sim000001"); Assert.Equal(10_000, intervalsDevice1[0]); int[] intervalsDevice2 = target.GetMessageIntervalForDevice("sim000002"); Assert.Equal(20_000, intervalsDevice2[0]); Assert.Equal(30_000, intervalsDevice2[1]); Assert.Equal(15_000, intervalsDevice2[2]); }
public async Task When_SendingMessage_With_Different_Payload_Per_Device_Should_Work() { var configuration = new ConfigurationBuilder() .AddJsonFile("./test_files/test3-config-multiple-devices.json") .Build(); var stats = new RunnerStats(); var config = RunnerConfiguration.Load(configuration, NullLogger.Instance); var senderDevice1 = new TestSender(false, false, "device0001", config); var senderDevice2 = new TestSender(false, false, "device0002", config); var senderDevice3 = new TestSender(false, false, "device0003", config); const int messageCount = 3; for (int i = 0; i < messageCount; i++) { await Task.WhenAll( senderDevice1.SendMessageAsync(stats, default), senderDevice2.SendMessageAsync(stats, default), senderDevice3.SendMessageAsync(stats, default)); } foreach (var expectedMessageForDevice1 in new[] { "{\"value\":\"1\"}", "{\"value\":\"true\"}", "{\"value\":\"2\"}", }) { Assert.Equal(1, senderDevice1.TestMessages.Count(x => expectedMessageForDevice1 == Encoding.UTF8.GetString(x.MessageBytes))); } foreach (var expectedMessageForDevice3 in new[] { "{\"a\":\"b\",\"value\":\"1\"}", "{\"a\":\"b\",\"value\":\"true\"}", "{\"a\":\"b\",\"value\":\"2\"}", }) { Assert.Equal(1, senderDevice3.TestMessages.Count(x => expectedMessageForDevice3 == Encoding.UTF8.GetString(x.MessageBytes))); } const string expectedMessageForDevice2 = "{\"value\":\"myfixvalue\"}"; Assert.Equal(messageCount, senderDevice2.TestMessages.Count(x => Encoding.UTF8.GetString(x.MessageBytes) == expectedMessageForDevice2)); }
public async Task When_SendMessageAsync_SendAsync_Succeeds_MessagesSent_Is_Incremented() { const string deviceId = "device1"; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>()) .Build(); var stats = new RunnerStats(); var config = RunnerConfiguration.Load(configuration, NullLogger.Instance); var sender = new TestSender(false, false, deviceId, config); await sender.SendMessageAsync(stats, CancellationToken.None); Assert.Equal(1, stats.MessagesSent); Assert.Equal(0, stats.TotalSendTelemetryErrors); Assert.Single(sender.TestMessages); }
public void When_No_Template_Is_Set_Loads_Default_Template() { var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { }) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); Assert.Single(target.PayloadGenerator.Payloads); var templatedPayload = Assert.IsType <TemplatedPayload>(target.PayloadGenerator.Payloads[0]); Assert.Equal(RunnerConfiguration.DefaultTemplate, templatedPayload.Template.ToString()); Assert.Equal(100, target.PayloadGenerator.Payloads[0].Distribution); }
public void TestProgress() { var progress = new List <int>(); var conf = new RunnerConfiguration { IsRemote = false, OnProgress = i => { progress.Add(i); }, }; var executor = new PowerShellRunner(conf); executor.Run(ScriptFile); Assert.AreEqual(progress.Count, 11); for (int i = 0; i <= 10; i++) { Assert.AreEqual(progress.ElementAt(i), i * 10); } }
public async Task When_SendMessageAsync_SendAsync_Throws_NonTransientExcption_SendTelemetryErrors_Is_Incremented() { const string deviceId = "device1"; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>()) .Build(); var stats = new RunnerStats(); var config = RunnerConfiguration.Load(configuration, NullLogger.Instance); var sender = new TestSender(false, true, deviceId, config); var stopwatch = Stopwatch.StartNew(); await sender.SendMessageAsync(stats, CancellationToken.None); stopwatch.Stop(); Assert.InRange(stopwatch.ElapsedMilliseconds, sender.TransientErrorWaitTime, (sender.MaxNumberOfSendAttempts + 1) * sender.TransientErrorWaitTime); Assert.Equal(0, stats.MessagesSent); Assert.InRange(stats.TotalSendTelemetryErrors, 1, int.MaxValue); Assert.Empty(sender.TestMessages); }
public void ConstructWithSuccess(IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config.Should().BeNull()); "When constructing the runner configuration" .x(() => e = Record.Exception(() => config = new RunnerConfiguration())); "Then the runner configuration constructor should succeed" .x(() => e.Should().BeNull()); "And configuration should be available" .x(() => { config.Stages.Should().Be(Stages.All); config.StageRunners.Should().NotBeNull().And.HaveCount(0); config.Args.Count.Should().Be(0); config.FailFast.Should().BeFalse(); config.FailStages.Should().Be(Stages.None); }); }
public void When_Using_Sequence_Payload_Loads_Correctly() { const string rawTemplate = "{\"value\": \"$.Value\" }"; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { "Variables", "[{\"name\":\"Value\", \"sequence\":true, \"values\":[\"$.Counter\", \"true\"]}, {\"name\":\"Counter\"}]" }, { "Template", rawTemplate }, }) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); var payload = Assert.Single(target.PayloadGenerator.Payloads); var templatedPayload = Assert.IsType <TemplatedPayload>(payload); Assert.Equal(2, templatedPayload.Variables.Variables.Count); Assert.True(templatedPayload.Variables.Variables[0].Sequence); Assert.Equal(new[] { "Counter" }, templatedPayload.Variables.Variables[0].GetReferenceVariableNames()); }
public void SetFailStageWithSingleStage(IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config = new RunnerConfiguration()); "When enabling the fail fast flag for a single stage" .x(() => e = Record.Exception(() => config.FailStages |= Stages.Verify)); "Then enabling the flag should succeed" .x(() => e.Should().BeNull()); "And the FailStages property should have the single stage enabled" .x(() => { config.FailStages.Should().HaveFlag(Stages.Verify); config.FailStages.Should().NotHaveFlag(Stages.Discover); config.FailStages.Should().NotHaveFlag(Stages.Parse); config.FailStages.Should().NotHaveFlag(Stages.Analyze); config.FailStages.Should().NotHaveFlag(Stages.Report); config.FailStages.Should().NotHaveFlag(Stages.Convert); }); }
public void When_Loading_From_File_With_Multiple_Payloads_Loads_Correctly() { var configuration = new ConfigurationBuilder() .AddJsonFile("./test_files/test2-config-multiple-payloads.json", false, false) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); Assert.Equal(2, target.PayloadGenerator.Payloads.Length); var templatedPayload = Assert.IsType <TemplatedPayload>(target.PayloadGenerator.Payloads[0]); Assert.Equal(2, templatedPayload.Variables.Variables.Count); Assert.True(templatedPayload.Variables.Variables[0].Sequence); Assert.Equal("device0001", templatedPayload.DeviceId); Assert.Equal(new[] { "Counter" }, templatedPayload.Variables.Variables[0].GetReferenceVariableNames()); var fixPayload = Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[1]); Assert.Equal("{\"value\":\"myfixvalue\"}", Encoding.UTF8.GetString(fixPayload.Payload)); Assert.Equal("device0002", fixPayload.DeviceId); }
public void When_Loading_From_File_With_Non_Encoded_Json_Payloads_Loads_Correctly() { var configuration = new ConfigurationBuilder() .AddJsonFile("./test_files/test5-config-payloads-as-json.json", false, false) .Build(); var target = RunnerConfiguration.Load(configuration, NullLogger.Instance); Assert.NotNull(target.PayloadGenerator); Assert.Equal(2, target.PayloadGenerator.Payloads.Length); var templatedPayload = Assert.IsType <TemplatedPayload>(target.PayloadGenerator.Payloads[0]); var device1Vars = new Dictionary <string, object> { { Constants.DeviceIdValueName, "device0001" }, }; var(device1Message, _) = templatedPayload.Generate(device1Vars); var device1MessageMap = JsonConvert.DeserializeObject <Dictionary <string, string> >(Encoding.UTF8.GetString(device1Message)); Assert.Equal(2, device1MessageMap.Count); Assert.Equal("1", device1MessageMap["value"]); Assert.Equal("20", device1MessageMap["a_second_value"]); var fixPayload = Assert.IsType <FixPayload>(target.PayloadGenerator.Payloads[1]); var device2Vars = new Dictionary <string, object> { { Constants.DeviceIdValueName, "device0002" }, }; var(device2Message, _) = fixPayload.Generate(device2Vars); var device2MessageMap = JsonConvert.DeserializeObject <Dictionary <string, string> >(Encoding.UTF8.GetString(device2Message)); Assert.Single(device2MessageMap); Assert.Equal("myfixvalue", device2MessageMap["value"]); }
public async Task When_SendMessageAsync_With_Header_Property_Is_Added() { const string deviceId = "device1"; const string propertyKey = "myPropertyKey"; const string propertyValue = "My Propert Value"; var rawTemplate = $"{{ \"{propertyKey}\": \"{propertyValue}\" }}"; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { "Header", rawTemplate } }) .Build(); var stats = new RunnerStats(); var config = RunnerConfiguration.Load(configuration, NullLogger.Instance); var sender = new TestSender(false, false, deviceId, config); await sender.SendMessageAsync(stats, CancellationToken.None); Assert.Equal(propertyValue, sender.TestMessages.Single().Properties[propertyKey]); Assert.Equal(1, stats.MessagesSent); Assert.Equal(0, stats.TotalSendTelemetryErrors); Assert.Single(sender.TestMessages); }
public void ConstructWithStageRunnersSuccess(IList <IStageRunner> stageRunners, IRunnerConfiguration config, Exception e) { "Given runner configuration" .x(() => config.Should().BeNull()); "And a list of stage runners" .x(() => stageRunners = _mockStageRunners.ConvertAll(m => m.Object)); "When constructing the runner configuration" .x(() => e = Record.Exception(() => config = new RunnerConfiguration(stageRunners))); "Then the runner configuration constructor should succeed" .x(() => e.Should().BeNull()); "And configuration should be available" .x(() => { config.Stages.Should().Be(Stages.All); config.StageRunners.Should().NotBeNull().And.HaveCount(4); config.Args.Count.Should().Be(0); config.FailFast.Should().BeFalse(); config.FailStages.Should().Be(Stages.None); }); }
public TestSender(bool throwTransientException, bool throwNonTransientException, string deviceId, RunnerConfiguration config) : base(deviceId, config) { this.throwTransientException = throwTransientException; this.throwNonTransientException = throwNonTransientException; }
private void LoadCommands() { Commands = new ObservableCollection <CommandViewModel>( RunnerConfiguration.GetCommands().Select(c => new CommandViewModel(c))); }