public JsonParsingBenchmark() { var mockHttp = GetMockHttpMessageHandler(); _client = new Client("my API key", mockHttp, null, null); _legacyClient = new LegacyClient("my API key", mockHttp, null, null); }
public void WriteTest() { var instance1 = new LegacyClient(); instance1.Settings = new ClientSettings(ClientType.Legacy) { Name = "test" }; const string testFile = "..\\..\\TestFiles\\new.ext"; var configurationManager = new ClientSettingsManager(GetPluginManager()); configurationManager.Write(new[] { instance1.Settings }, testFile, 1); Assert.AreEqual("..\\..\\TestFiles\\new.ext", configurationManager.FileName); Assert.AreEqual(1, configurationManager.FilterIndex); Assert.AreEqual(".ext", configurationManager.FileExtension); File.Delete(testFile); }
public void UpdateBenchmarkDataTest() { // setup var benchmarkCollection = new ProteinBenchmarkService(); var database = MockRepository.GenerateMock <IUnitInfoDatabase>(); var legacyClient = new LegacyClient { BenchmarkService = benchmarkCollection, UnitInfoDatabase = database }; var unitInfo1 = new UnitInfo(); unitInfo1.OwningClientName = "Owner"; unitInfo1.OwningClientPath = "Path"; unitInfo1.ProjectID = 2669; unitInfo1.ProjectRun = 1; unitInfo1.ProjectClone = 2; unitInfo1.ProjectGen = 3; unitInfo1.FinishedTime = new DateTime(2010, 1, 1); var currentUnitInfo = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1 }; var unitInfo1Clone = unitInfo1.DeepClone(); unitInfo1Clone.FramesObserved = 4; unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3 }); var unitInfoLogic1 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone }; var unitInfo2 = new UnitInfo(); unitInfo2.OwningClientName = "Owner"; unitInfo2.OwningClientPath = "Path"; unitInfo2.ProjectID = 2669; unitInfo2.ProjectRun = 2; unitInfo2.ProjectClone = 3; unitInfo2.ProjectGen = 4; unitInfo2.FinishedTime = new DateTime(2010, 1, 1); var unitInfoLogic2 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo2 }; var unitInfo3 = new UnitInfo(); unitInfo3.OwningClientName = "Owner"; unitInfo3.OwningClientPath = "Path"; unitInfo3.ProjectID = 2669; unitInfo3.ProjectRun = 3; unitInfo3.ProjectClone = 4; unitInfo3.ProjectGen = 5; unitInfo3.FinishedTime = new DateTime(2010, 1, 1); var unitInfoLogic3 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo3 }; var parsedUnits = new[] { unitInfoLogic1, unitInfoLogic2, unitInfoLogic3 }; // arrange database.Stub(x => x.Connected).Return(true); database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(3); var benchmarkClient = new ProteinBenchmarkSlotIdentifier("Owner", "Path"); // assert before act Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(false, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData)); // act legacyClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 2); // assert after act Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(true, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime); database.VerifyAllExpectations(); }
public void UpdateBenchmarkDataTest() { // setup var benchmarkCollection = new ProteinBenchmarkCollection(); var database = MockRepository.GenerateMock<IUnitInfoDatabase>(); var legacyClient = new LegacyClient { BenchmarkCollection = benchmarkCollection, UnitInfoDatabase = database }; var unitInfo1 = new UnitInfo(); unitInfo1.OwningClientName = "Owner"; unitInfo1.OwningClientPath = "Path"; unitInfo1.ProjectID = 2669; unitInfo1.ProjectRun = 1; unitInfo1.ProjectClone = 2; unitInfo1.ProjectGen = 3; unitInfo1.FinishedTime = new DateTime(2010, 1, 1); var currentUnitInfo = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1 }; var unitInfo1Clone = unitInfo1.DeepClone(); unitInfo1Clone.FramesObserved = 4; unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2 }); unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3 }); var unitInfoLogic1 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone }; var unitInfo2 = new UnitInfo(); unitInfo2.OwningClientName = "Owner"; unitInfo2.OwningClientPath = "Path"; unitInfo2.ProjectID = 2669; unitInfo2.ProjectRun = 2; unitInfo2.ProjectClone = 3; unitInfo2.ProjectGen = 4; unitInfo2.FinishedTime = new DateTime(2010, 1, 1); var unitInfoLogic2 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo2 }; var unitInfo3 = new UnitInfo(); unitInfo3.OwningClientName = "Owner"; unitInfo3.OwningClientPath = "Path"; unitInfo3.ProjectID = 2669; unitInfo3.ProjectRun = 3; unitInfo3.ProjectClone = 4; unitInfo3.ProjectGen = 5; unitInfo3.FinishedTime = new DateTime(2010, 1, 1); var unitInfoLogic3 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo3 }; var parsedUnits = new[] { unitInfoLogic1, unitInfoLogic2, unitInfoLogic3 }; // arrange database.Stub(x => x.Connected).Return(true); database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(3); var benchmarkClient = new BenchmarkClient("Owner", "Path"); // assert before act Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(false, new List<int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData)); // act legacyClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 2); // assert after act Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient)); Assert.AreEqual(true, new List<int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669)); Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime); database.VerifyAllExpectations(); }
public async Task <int> RunAsync() { // ----------------------------------------------------------------------------- // Do you want to proxy requests through Fiddler? Can be useful for debugging. var useFiddler = true; var fiddlerPort = 8866; // By default Fiddler4 uses port 8888 and Fiddler Everywhere uses port 8866 // Change the default values in the legacy client. var optionsToCorrectLegacyDefaultValues = new StrongGridClientOptions() { LogLevelFailedCalls = LogLevel.Error, LogLevelSuccessfulCalls = LogLevel.Debug }; // ----------------------------------------------------------------------------- // Configure StrongGrid client var apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); var proxy = useFiddler ? new WebProxy($"http://localhost:{fiddlerPort}") : null; var legacyClient = new LegacyClient(apiKey, proxy, optionsToCorrectLegacyDefaultValues, _loggerFactory.CreateLogger <LegacyClient>()); var client = new Client(apiKey, proxy, null, _loggerFactory.CreateLogger <Client>()); // Configure Console var source = new CancellationTokenSource(); Console.CancelKeyPress += (s, e) => { e.Cancel = true; source.Cancel(); }; // Ensure the Console is tall enough and centered on the screen Console.WindowHeight = Math.Min(60, Console.LargestWindowHeight); Utils.CenterConsole(); // These are the integration tests that we will execute var integrationTests = new Type[] { typeof(AccessManagement), typeof(Alerts), typeof(ApiKeys), typeof(Batches), typeof(Blocks), typeof(Bounces), typeof(ContactsAndCustomFields), typeof(Designs), typeof(EmailActivities), typeof(EmailValidation), typeof(GlobalSuppressions), typeof(InvalidEmails), typeof(IpAddresses), typeof(IpPools), typeof(LegacyCampaignsAndSenderIdentities), typeof(LegacyCategories), typeof(LegacyContactsAndCustomFields), typeof(LegacyListsAndSegments), typeof(ListsAndSegments), typeof(Mail), typeof(SenderAuthentication), typeof(Settings), typeof(SingleSendsAndSenderIdentities), typeof(SpamReports), typeof(Statistics), typeof(Subusers), typeof(Teammates), typeof(Templates), typeof(UnsubscribeGroupsAndSuppressions), typeof(User), typeof(WebhookSettings), typeof(WebhookStats) }; // Execute the async tests in parallel (with max degree of parallelism) var results = await integrationTests.ForEachAsync( async testType => { var log = new StringWriter(); try { var integrationTest = (IIntegrationTest)Activator.CreateInstance(testType); if (testType.Name.StartsWith("Legacy")) { await integrationTest.RunAsync(legacyClient as IBaseClient, log, source.Token).ConfigureAwait(false); } else { await integrationTest.RunAsync(client as IBaseClient, log, source.Token).ConfigureAwait(false); } return(TestName : testType.Name, ResultCode : ResultCodes.Success, Message : SUCCESSFUL_TEST_MESSAGE); } catch (OperationCanceledException) { await log.WriteLineAsync($"-----> TASK CANCELLED").ConfigureAwait(false); return(TestName : testType.Name, ResultCode : ResultCodes.Cancelled, Message : "Task cancelled"); } catch (Exception e) { var exceptionMessage = e.GetBaseException().Message; await log.WriteLineAsync($"-----> AN EXCEPTION OCCURRED: {exceptionMessage}").ConfigureAwait(false); return(TestName : testType.Name, ResultCode : ResultCodes.Exception, Message : exceptionMessage); } finally { lock (Console.Out) { Console.Out.WriteLine(log.ToString()); } } }, MAX_SENDGRID_API_CONCURRENCY) .ConfigureAwait(false); // Display summary var summary = new StringWriter(); await summary.WriteLineAsync("\n\n**************************************************").ConfigureAwait(false); await summary.WriteLineAsync("******************** SUMMARY *********************").ConfigureAwait(false); await summary.WriteLineAsync("**************************************************").ConfigureAwait(false); foreach (var(TestName, ResultCode, Message) in results.OrderBy(r => r.TestName).ToArray()) { var name = TestName.Length <= TEST_NAME_MAX_LENGTH ? TestName : TestName.Substring(0, TEST_NAME_MAX_LENGTH - 3) + "..."; await summary.WriteLineAsync($"{name.PadRight(TEST_NAME_MAX_LENGTH, ' ')} : {Message}").ConfigureAwait(false); } await summary.WriteLineAsync("**************************************************").ConfigureAwait(false); await Console.Out.WriteLineAsync(summary.ToString()).ConfigureAwait(false); // Prompt user to press a key in order to allow reading the log in the console var promptLog = new StringWriter(); await promptLog.WriteLineAsync("\n\n**************************************************").ConfigureAwait(false); await promptLog.WriteLineAsync("Press any key to exit").ConfigureAwait(false); Utils.Prompt(promptLog.ToString()); // Return code indicating success/failure var resultCode = (int)ResultCodes.Success; if (results.Any(result => result.ResultCode != ResultCodes.Success)) { if (results.Any(result => result.ResultCode == ResultCodes.Exception)) { resultCode = (int)ResultCodes.Exception; } else if (results.Any(result => result.ResultCode == ResultCodes.Cancelled)) { resultCode = (int)ResultCodes.Cancelled; } else { resultCode = (int)results.First(result => result.ResultCode != ResultCodes.Success).ResultCode; } } return(await Task.FromResult(resultCode)); }