public static void Main(string[] args) { var harness = new TestHarness(); harness.Test(new BubbleSort<int>(), GetIntTests()); harness.Test(new BubbleSort<string>(), GetStringTests()); Console.ReadKey(); }
public static void GetTestRunnersReturnsAllRunnersForSampleSuite(TestRunner r) { TestHarness harness = new TestHarness(); string sampleSuiteName = "TestFramework::SampleTests"; harness.FindTests(); TestSuite sampleSuite = harness.TestSuites[sampleSuiteName]; r.Expect(sampleSuite.GetTestRunners().Count).ToBe(2); }
public UtMethodDispatcher( TestHarness.ITestHarness testHarness, object instance, MethodInfo method, TestGranularity granularity ) : base(instance, method) { _granularity = granularity; _harness = testHarness as UnitTestHarness; }
public async Task CanDisposeOnEviction() { TestHarness harness = new TestHarness(cacheExpirationInSeconds: 1, disposeOnEviction: true); HttpContext context = CreateContext(RequestPathTenant11); TenantContext <TestTenant> tenantContext = await harness.TestTenantResolver.ResolveAsync(context); Thread.Sleep(2 * 1000); // access it again so that MemoryCache examines it's cache for pending evictions harness.Cache.Get(RequestPathTenant12); Thread.Sleep(1 * 1000); // access it again and we should see the eviction Assert.True(tenantContext.Tenant.Disposed); }
public void Update(TestHarness harness, bool autoDetectChanges) { using (var context = new OrdersContext(_connectionString)) { var customers = GetAllCustomersFromDatabase(); Assert.Equal(1000, customers.Length); context.Configuration.AutoDetectChangesEnabled = autoDetectChanges; using (harness.StartCollection()) { foreach (var customer in customers) { context.Entry(customer).State = EntityState.Modified; } } } }
public void Remove(TestHarness harness, bool autoDetectChanges) { using (var context = new OrdersContext(_connectionString)) { var customers = context.Customers.ToArray(); Assert.Equal(1000, customers.Length); context.Configuration.AutoDetectChangesEnabled = autoDetectChanges; using (harness.StartCollection()) { foreach (var customer in customers) { context.Customers.Remove(customer); } } } }
public async Task CannotDispose_OnEviction() { TestHarness harness = new TestHarness(cacheExpirationInSeconds: 1, disposeOnEviction: false); HttpContext context = CreateContext(RequestPathTenant11); TenantContext <TestTenant> tenantContext = await harness.TestTenantResolver.ResolveAsync(context); Thread.Sleep(1 * 1000); // access it again so that MemoryCache examines it's cache for pending evictions harness.Cache.Get(RequestPathTenant12); Thread.Sleep(1 * 1000); // access it again and even though it's disposed, it should not be evicted Assert.False(tenantContext.Tenant.Disposed); }
public void PrepareTestHarnessForCoverage(TestHarness harness, IFrameworkDefinition definition, ChutzpahTestSettingsFile testSettingsFile) { string blanketScriptName = GetBlanketScriptName(definition, testSettingsFile); // Construct array of scripts to exclude from instrumentation/coverage collection. var filesToExcludeFromCoverage = harness.TestFrameworkDependencies.Concat(harness.CodeCoverageDependencies) .Where(dep => dep.HasFile && IsScriptFile(dep.ReferencedFile)) .Select(dep => dep.Attributes["src"]) .Concat(excludePatterns.Select(ToRegex)) .ToList(); var filesToIncludeInCoverage = includePatterns.Select(ToRegex).ToList(); foreach (TestHarnessItem refScript in harness.ReferencedScripts.Where(rs => rs.HasFile)) { // Exclude files which the user is asking us to ignores if (!IsFileEligibleForInstrumentation(refScript.ReferencedFile.Path)) { filesToExcludeFromCoverage.Add(refScript.Attributes["src"]); } else { refScript.Attributes["type"] = "text/blanket"; // prevent Phantom/browser parsing } } // Name the coverage object so that the JS runner can pick it up. harness.ReferencedScripts.Add(new Script(string.Format("window.{0}='_$blanket';", Constants.ChutzpahCoverageObjectReference))); // Configure Blanket. TestHarnessItem blanketMain = harness.CodeCoverageDependencies.Single( d => d.Attributes.ContainsKey("src") && d.Attributes["src"].EndsWith(blanketScriptName)); string dataCoverNever = "[" + string.Join(",", filesToExcludeFromCoverage.Select(file => "'" + file + "'")) + "]"; string dataCoverOnly = filesToIncludeInCoverage.Any() ? "[" + string.Join(",", filesToIncludeInCoverage.Select(file => "'" + file + "'")) + "]" : "//.*/"; ChutzpahTracer.TraceInformation("Adding data-cover-never attribute to blanket: {0}", dataCoverNever); blanketMain.Attributes.Add("data-cover-flags", "ignoreError autoStart"); blanketMain.Attributes.Add("data-cover-only", dataCoverOnly); blanketMain.Attributes.Add("data-cover-never", dataCoverNever); }
public async void TestSubscriptionsNegativeActivate(string subscriptionId, string errorName) { // - Activate Subscription SubscriptionsActivateRequest activateRequest = new SubscriptionsActivateRequest(subscriptionId); activateRequest.RequestBody(new SubscriptionActivateRequest() { Reason = "Need to activate" }); PayPalHttp.HttpException httpException = await Assert.ThrowsAsync <PayPalHttp.HttpException>(() => { return(TestHarness.client().Execute(activateRequest)); }); Assert.Equal(errorName, httpException.GetError().Name); }
public async Task GetCognitiveServiceKeys() { var dataStore = await AAD.GetTokenWithDataStore(); var result = await TestHarness.ExecuteActionAsync("Microsoft-GetAzureSubscriptions", dataStore); Assert.IsTrue(result.IsSuccess); var responseBody = JObject.FromObject(result.Body); var subscriptionId = responseBody["value"][0]; dataStore.AddToDataStore("Azure", "SelectedResourceGroup", "testing"); dataStore.AddToDataStore("CognitiveService", "CognitiveServiceName", "TestCognitiveService2"); var response = TestHarness.ExecuteAction("Microsoft-GetCognitiveKey", dataStore); Assert.IsTrue(response.Status == ActionStatus.Success); }
public async void EndRun(TestHarness harness) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { pnlFooter.Visibility = Visibility.Collapsed; if (harness.Failures > 0) { lblResults.Text = string.Format(CultureInfo.InvariantCulture, "{0}/{1} tests failed!", harness.Failures, harness.Count); lblResults.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0x6E)); } else { lblResults.Text = string.Format(CultureInfo.InvariantCulture, "{0} tests passed!", harness.Count); } lblResults.Visibility = Visibility.Visible; }); }
public async void TestSubscriptionsNegativeCancel(string subscriptionId, string errorName) { // - Cancel Subscription SubscriptionsCancelRequest cancelRequest = new SubscriptionsCancelRequest(subscriptionId); cancelRequest.RequestBody(new SubscriptionCancelRequest() { Reason = "Cancel reason" }); PayPalHttp.HttpException httpException = await Assert.ThrowsAsync <PayPalHttp.HttpException>(() => { return(TestHarness.client().Execute(cancelRequest)); }); Assert.Equal(errorName, httpException.GetError().Name); }
public void SetConfigValuesInSql_Success() { var dataStore = TestHarness.GetCommonDataStoreWithSql().Result; dataStore.AddToDataStore("SqlServerIndex", 0, DataStoreType.Any); dataStore.AddToDataStore("Customize", "SqlGroup", "SolutionTemplate", DataStoreType.Public); dataStore.AddToDataStore("Customize", "SqlSubGroup", "System Center", DataStoreType.Public); dataStore.AddToDataStore("Customize", "SqlEntryName", "endpointcompliancetarget", DataStoreType.Public); dataStore.AddToDataStore("Customize", "SqlEntryValue", "0.99", DataStoreType.Public); dataStore.AddToDataStore("Customize1", "SqlGroup", "SolutionTemplate", DataStoreType.Public); dataStore.AddToDataStore("Customize1", "SqlSubGroup", "System Center", DataStoreType.Public); dataStore.AddToDataStore("Customize1", "SqlEntryName", "healthevaluationtarget", DataStoreType.Public); dataStore.AddToDataStore("Customize1", "SqlEntryValue", "0.99", DataStoreType.Public); dataStore.AddToDataStore("Customize3", "SqlGroup", "SolutionTemplate", DataStoreType.Public); dataStore.AddToDataStore("Customize3", "SqlSubGroup", "System Center", DataStoreType.Public); dataStore.AddToDataStore("Customize3", "SqlEntryName", "healthevaluationtarget", DataStoreType.Public); dataStore.AddToDataStore("Customize3", "SqlEntryValue", "120", DataStoreType.Public); SqlCredentials creds = new SqlCredentials() { Server = Credential.Instance.Sql.Server, Username = Credential.Instance.Sql.Username, Password = Credential.Instance.Sql.Password, Authentication = SqlAuthentication.SQL, Database = TestHarness.CurrentDatabase }; TestHarness.RunSqlCommandWithoutTransaction(creds, "CREATE TABLE [dbo].[testTable]" + "(" + "id INT IDENTITY(1, 1) NOT NULL," + "configuration_group VARCHAR(150) NOT NULL," + "configuration_subgroup VARCHAR(150) NOT NULL," + "name VARCHAR(150) NOT NULL," + "value VARCHAR(max) NULL, " + "visible BIT NOT NULL DEFAULT 0" + ");"); dataStore.AddToDataStore("SqlConfigTable", "testTable"); var response = TestHarness.ExecuteAction("Microsoft-SetConfigValueInSql", dataStore); Assert.IsTrue(response.Status == ActionStatus.Success); }
public async Task TryAdd_ShouldReturnFalse_WhenMaxNumResourcesReached() { var testHarness = new TestHarness(); const int minNumResources = 1; const int maxNumResources = 1; using (var sut = CreateSut(testHarness, minNumResources, maxNumResources)) { await Task.Delay(100); // Allow time for resource creation var resource = new TestResource(28371273); var result = sut.TryAdd(resource); Assert.False(result); } }
public void SetUp() { _harness = TestHarness.CreateHarness(); _harness.Planner.Start().Wait(); _harness.Inviter.Start().Wait(); _harness.WithFiveUnsentInvitations(); _harness.Inviter.PizzaInviterLoopTick().Wait(); _harness.Now = _harness.Now.AddDays(2); _harness.Inviter.PizzaInviterLoopTick().Wait(); _harness.Core.Invocations.Clear(); _harness.Now = _harness.Now.AddDays(1); _harness.Inviter.PizzaInviterLoopTick().Wait(); }
public async Task CheckCDMEntities() { //Get Token var dataStore = await AAD.GetUserTokenFromPopup(); var result = await TestHarness.ExecuteActionAsync("Microsoft-GetAzureSubscriptions", dataStore); Assert.IsTrue(result.IsSuccess); var responseBody = JObject.FromObject(result.Body); dataStore.AddToDataStore("EnvironmentID", "Legacy-1806a3cb-4a99-4491-aa5f-ac186fd73f10", DataStoreType.Private); //dataStore.AddToDataStore("ObjectID", "63439178-643b-4b6d-92ed-db2e1f2f5b14", DataStoreType.Private); dataStore.AddToDataStore("EntityName", "TestEntity", DataStoreType.Private); var getCDMEntityResponse = TestHarness.ExecuteAction("Microsoft-CheckCDMEntities", dataStore); Assert.IsTrue(getCDMEntityResponse.Status == ActionStatus.Success); }
public void WriteErrorLine_ContinuingLine() { // TODO: This behavior probably is not desired. using var my = new TestHarness(taskId: 1); my.ConsoleState.IsAtBol = false; my.ConsoleState.LastTaskId = my.TaskId; my.MockUI .Setup(u => u.WriteErrorLine("message")) .Verifiable(); my.TaskHostUI.WriteErrorLine("message"); my.ConsoleState.IsAtBol.Should().BeTrue(); my.ConsoleState.LastTaskId.Should().Be(my.TaskId); }
public async Task SetUp() { _harness = TestHarness.CreateHarness(); _harness.Start(); _harness.Tick(); _plan = _harness.ActivePizzaPlans.Single(); _userIdOfGustRejecting = _plan.Invited.First().UserId; _firstInvitedUsers = _plan.Invited.Select(u => u.UserId).ToList(); await _harness.Inviter.HandleMessage( new NewMessage() { user = _userIdOfGustRejecting, text = "no" }); _harness.Core.Invocations.Clear(); _harness.Tick(); }
public void WriteInformation() { using var my = new TestHarness(); var originalIsAtBol = my.ConsoleState.IsAtBol; var originalLastTaskId = my.ConsoleState.LastTaskId; var record = new InformationRecord(new object(), "any"); my.MockUI .Setup(u => u.WriteInformation(record)) .Verifiable(); my.TaskHostUI.WriteInformation(record); my.ConsoleState.IsAtBol.Should().Be(originalIsAtBol); my.ConsoleState.LastTaskId.Should().Be(originalLastTaskId); }
public async Task Get_ShouldThrowException_WhenResourceFactoryThrowsException() { var exception = new Exception("Expect to receive me from Get"); const int maxNumAttempts = 3; async Task <TestResource> FailingFactory() { throw exception; } var testHarness = new TestHarness(FailingFactory); using (var sut = CreateSut(testHarness, 1, 1, maxNumResourceCreationAttempts: maxNumAttempts)) { await Assert.ThrowsAsync <Exception>(() => sut.Get()); } }
static void Test(int size, int min, int max, int windowSize1, int windowSize2) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Console.WriteLine($"Beginning test with {size} elements from {min} to {max}, with window sizes of {windowSize1} and {windowSize2}"); var randomStream = new RandomInputStream(size, min, max); var generator = new MyStatsGen(windowSize1, windowSize2, randomStream); var testHarness = new TestHarness(randomStream, generator, windowSize1, windowSize2); testHarness.Run(checkResults: true, printProgress: false); var time = stopwatch.Elapsed; Console.WriteLine($"Compeleted in {time.TotalSeconds} seconds\n"); }
public async Task CannotResolve_TenantContextFromCaheAppTenantResolver_IfHttpContextIsNull() { // Arrange TestHarness harness = new TestHarness(); HttpContext context = CreateContext(Fixture.UrlTenant1); // Act Task Res() => Task.Run(async() => { TenantContext <AppTenant> tenantContext = await harness.AppTenantResolver.ResolveAsync(null); }); // Assert Exception ex = await Assert.ThrowsAsync <ArgumentNullException>(Res).ConfigureAwait(false); Assert.NotNull(ex); Assert.Contains("context", ex.Message); }
public void WriteLine_TextInColor_BeginningLine() { using var my = new TestHarness(taskId: 1); var fg = Random.NextEnum <ConsoleColor>(); var bg = Random.NextEnum <ConsoleColor>(); my.ConsoleState.IsAtBol = true; my.MockUI .Setup(u => u.WriteLine(fg, bg, "[Task 1]: message")) .Verifiable(); my.TaskHostUI.WriteLine(fg, bg, "message"); my.ConsoleState.IsAtBol.Should().BeTrue(); my.ConsoleState.LastTaskId.Should().Be(my.TaskId); }
public async Task GetExperimentsTest() { var dataStore = await TestHarness.GetCommonDataStoreWithUserToken(); ManagementSDK sdk = new ManagementSDK(); var workspaces = sdk.GetWorkspacesFromRdfe(dataStore.GetJson("AzureToken")["access_token"].ToString(), dataStore.GetJson("SelectedSubscription")["SubscriptionId"].ToString()); var workspaceSettings = new WorkspaceSetting() { AuthorizationToken = workspaces[0].AuthorizationToken.PrimaryToken, Location = workspaces[0].Region, WorkspaceId = workspaces[0].Id }; var experiments = sdk.GetExperiments(workspaceSettings); string rawJson = string.Empty; Experiment exp = sdk.GetExperimentById(workspaceSettings, experiments[0].ExperimentId, out rawJson); }
public async Task DeployCognitiveServiceTextTest() { var dataStore = await TestHarness.GetCommonDataStore(); dataStore.AddToDataStore("CognitiveServiceName", "TestCognitiveService"); dataStore.AddToDataStore("CognitiveSkuName", "F0"); dataStore.AddToDataStore("DeploymentName", "deployment"); var response = TestHarness.ExecuteAction("Microsoft-DeployCognitiveServiceText", dataStore); Assert.IsTrue(response.Status == ActionStatus.Success); response = TestHarness.ExecuteAction("Microsoft-GetCognitiveServiceKeys", dataStore); Assert.IsTrue(response.Status == ActionStatus.Success); dataStore.AddObjectDataStore(response.Body.GetJObject(), DataStoreType.Private); Assert.IsTrue(dataStore.GetValue("CognitiveServiceKey") != null); }
static void TestSetDouble() { TestHarness.TestCase("Fraction Set(double)"); Fraction f = new Fraction(); double[] set_double_input = new double[] { -2.06, -0.06, 0.0, 0.06, 2.06, 0.3, 0.33, 0.33333333, 20221.6543599839 }; int [,] set_double_output = new int[, ] { { -103, 50 }, { -3, 50 }, { 0, 1 }, { 3, 50 }, { 103, 50 }, { 3, 10 }, { 33, 100 }, { 1, 3 }, { 25742166, 1273 } }; for (int i = 0; i < set_double_input.Length; i++) { f.Set(set_double_input[i]); TestHarness.Test(String.Format("Set({0}) = ({1}/{2})", set_double_input[i], set_double_output[i, 0], set_double_output[i, 1]), R(f, set_double_output[i, 0], set_double_output[i, 1])); } }
public async Task ConvertToClass_InitPropertiesInConstructor_MatchExpected() { var harness = await TestHarness.Init(@"namespace Custom { public record T[|estRec|]ord(string FirstName, string LastName) {} public class ClassWithProperties { public string First { get;set; } } }"); var result = await harness.Subject.ConvertToClass(harness.Subject.Context.Document, harness.Subject.Record, true, CancellationToken.None); var textAsync = await result.GetTextAsync(CancellationToken.None); textAsync.ToString().Should().Be(@"namespace Custom { public class TestRecord { public string FirstName { get; set; } public string LastName { get; set; } public TestRecord(string firstName, string lastName) { this.FirstName = firstName; this.LastName = lastName; } } public class ClassWithProperties { public string First { get;set; } } }"); var root = await result.GetSyntaxRootAsync(); var testRecord = root.DescendantNodes().OfType <ClassDeclarationSyntax>().SingleOrDefault(x => x.Identifier.ToString() == "TestRecord"); testRecord.Should().NotBeNull(); testRecord !.ContainsAnnotations.Should().BeTrue(); testRecord !.HasAnnotation(Formatter.Annotation).Should().BeTrue(); }
public void Write_TextInColor_ContinuingLine() { using var my = new TestHarness(taskId: 1); var fg = Random.NextEnum <ConsoleColor>(); var bg = Random.NextEnum <ConsoleColor>(); my.ConsoleState.IsAtBol = false; my.ConsoleState.LastTaskId = my.TaskId; my.MockUI .Setup(u => u.Write(fg, bg, "message")) .Verifiable(); my.TaskHostUI.Write(fg, bg, "message"); my.ConsoleState.IsAtBol.Should().BeFalse(); my.ConsoleState.LastTaskId.Should().Be(my.TaskId); }
static void TestRound() { int [,] round_data = new int [, ] { { 3333, 10000, 10, 3, 10 }, { 3333, 10000, 100, 33, 100 }, { 639, 5176, 100, 3, 25 }, { 2147483647, 106197, 1000, 10110849, 500 } }; TestHarness.TestCase("Fraction round"); Fraction f = new Fraction(); int i, n = round_data.GetUpperBound(0); for (i = 0; i <= n; i++) { S(f, round_data[i, 0], round_data[i, 1]); f.Round(round_data[i, 2]); TestHarness.Test(String.Format("({0}/{1}).Round({2}) = ({3}/{4})", round_data[i, 0], round_data[i, 1], round_data[i, 2], round_data[i, 3], round_data[i, 4]), R(f, round_data[i, 3], round_data[i, 4])); } }
private static void Delete(TestHarness harness) { using (var context = new OrdersContext(_connectionString)) { using (context.Database.BeginTransaction()) { foreach (var customer in context.Customers) { context.Customers.Remove(customer); } harness.StartCollection(); var records = context.SaveChanges(); harness.StopCollection(); Assert.Equal(1000, records); } } }
public async Task ResourceShouldNotBeDisposedAfterConnectionPoolIsDisposedIfReusableResourceIsNotDisposed() { var testHarness = new TestHarness(); ReusableResource <TestResource> reusableResource; using (var sut = CreateSut(testHarness, 1, 1)) { reusableResource = await sut.Get(); // Dispose the pool *without* ever disposing reusableResource. } // Allow some time for the disposal to possibly happen, because it might (well, does) happen on a different // thread. await Task.Delay(Timeout / 2); // The inner resource wrapped by the ReusableResource should still be alive Assert.False(reusableResource.Resource.IsDisposed); }
public async Task ShouldCreateResourcesWhenMinNumResourcesIsZero() { var testHarness = new TestHarness(); const int minNumResources = 0; const int numResourcesToCreate = 5; using (var sut = CreateSut(testHarness, minNumResources, minNumResources + 10)) { var tasks = Enumerable.Range(0, numResourcesToCreate) .Select(_ => sut.Get()); await Task.WhenAll(tasks); await Task.Delay(100); Assert.Equal(numResourcesToCreate, testHarness.CreatedResources.Count); } }
public async void TestProductsGetRequest() { var products = await ProductsCreateTest.CreateDefaultProductsIfNotExitsAsync(); int pageSize = 2; ProductsGetRequest request = new ProductsGetRequest(page: 1, pageSize: pageSize, totalRequired: true); var response = await TestHarness.client().Execute(request); Assert.Equal(200, (int)response.StatusCode); ProductCollection retrievedProductCollection = response.Result <ProductCollection>(); Assert.NotNull(retrievedProductCollection); Assert.Equal(pageSize, retrievedProductCollection.Products.Count); Assert.True(retrievedProductCollection.TotalItems.Value > pageSize); Assert.NotNull(retrievedProductCollection.Links); }
public static void BeforeEach(BeforeEachTestRunner r) { harness = new TestHarness(); sampleSuiteName = "TestFramework::SampleTests"; }
void OnInspectorUpdate() { if (_testHarness == null) { _testHarness = new TestHarness(); } if (!_testHarness.HasTests) { _testHarness.FindTests(); ShowWindow(); } }