public void ShouldReturnIdsAcrossMultipleGenerators() { // Arrange var account = CloudStorageAccount.DevelopmentStorageAccount; using (var testScope = new TestScope(account)) { var store1 = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator1 = new UniqueIdGenerator(store1) { BatchSize = 3 }; var store2 = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator2 = new UniqueIdGenerator(store2) { BatchSize = 3 }; // Act var generatedIds = new[] { generator1.NextId(testScope.IdScopeName), //1 generator1.NextId(testScope.IdScopeName), //2 generator1.NextId(testScope.IdScopeName), //3 generator2.NextId(testScope.IdScopeName), //4 generator1.NextId(testScope.IdScopeName), //7 generator2.NextId(testScope.IdScopeName), //5 generator2.NextId(testScope.IdScopeName), //6 generator2.NextId(testScope.IdScopeName), //10 generator1.NextId(testScope.IdScopeName), //8 generator1.NextId(testScope.IdScopeName) //9 }; // Assert CollectionAssert.AreEqual( new[] { 1, 2, 3, 4, 7, 5, 6, 10, 8, 9 }, generatedIds); } }
public void TestInfix() { IParseLineDelimiters pld = new TestDelims(); IScope scope = new TestScope(); { DelimiterList list = ParseLine.Do("3 + 8", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(11, value.AsInt); } { DelimiterList list = ParseLine.Do("4 + 2 + 7", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(13, value.AsInt); } { // precedence should work as expected DelimiterList list = ParseLine.Do("4 + 2 * 7", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(18, value.AsInt); } { // precedence comes into play DelimiterList list = ParseLine.Do("4 * 2 + 7", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(15, value.AsInt); } { DelimiterList list = ParseLine.Do("3 + x", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(9, value.AsInt); } }
public void TestBuiltin() { IScope scope = new TestScope(); INodeRequestor values = new TestValueIntRequestor(); Value result = EvalNode.Do(ToNode("1234"), scope, values, null); Assert.AreEqual(1234, result.AsInt); }
public void ConstructorShouldNotCreateFile() { using (var testScope = new TestScope(scope)) { var store = new FileOptimisticDataStore(Path.GetTempPath()); Assert.IsFalse(File.Exists(testScope.FilePath)); } }
public void GetNextBatchShouldBlockFileAccess() { using (var testScope = new TestScope(scope)) { CancellationTokenSource cancelTokenSource1 = new CancellationTokenSource(); CancellationTokenSource cancelTokenSource2 = new CancellationTokenSource(); try { var store = new FileOptimisticDataStore(Path.GetTempPath()); store.GetNextBatch(scope, batch); // create the file CancellationToken cancelToken1 = cancelTokenSource1.Token; Task task1 = Task.Factory.StartNew(() => { do store.GetNextBatch(scope, batch); while (!cancelToken1.IsCancellationRequested); }, cancelToken1); CancellationToken cancelToken2 = cancelTokenSource2.Token; Task task2 = Task.Factory.StartNew(() => { do { try { testScope.ReadCurrentPersistedValue(); } catch (IOException e) { if (e.Message.Equals("The process cannot access the file '" + testScope.FilePath + "' because it is being used by another process.")) return; throw; } } while (!cancelToken2.IsCancellationRequested); }, cancelToken2); if (task2.Wait(3000) && !task2.IsFaulted) Assert.Pass(); else { if (task2.IsFaulted) Assert.Inconclusive("The second thread failed with error '" + task2.Exception.ToString() + "'."); else Assert.Inconclusive("The second thread was not blocked in an interval of 3000 ms."); } } catch { cancelTokenSource1.Cancel(); cancelTokenSource2.Cancel(); throw; } } }
public void TestAllfix() { IParseLineDelimiters pld = new TestDelims(); IScope scope = new TestScope(); { DelimiterList list = ParseLine.Do("triple 2 + 3 doubled", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(12, value.AsInt); } }
public void TestFunction() { IParseLineDelimiters pld = new TestDelims(); IScope scope = new TestScope(); { // 2 + 4 * 5 DelimiterList list = ParseLine.Do("2 + create-multiplier 4 5", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(22, value.AsInt); } }
public void ShouldInitializeBlobForFirstIdInNewScope() { // Arrange var account = CloudStorageAccount.DevelopmentStorageAccount; using (var testScope = new TestScope(account)) { var store = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator = new UniqueIdGenerator(store) {BatchSize = 3}; // Act generator.NextId(testScope.IdScopeName); //1 // Assert Assert.AreEqual("4", testScope.ReadCurrentBlobValue()); } }
public void TestDelimiterFunction() { ValueFunction function = new AddFunction(); ValueDelimiter delim = new ValueDelimiter(">", DelimiterType.AsArray, function); List<DelimiterNode> nodes = new List<DelimiterNode>(); nodes.Add(ToNode("3")); nodes.Add(ToNode("6")); nodes.Add(ToNode("9")); DelimiterList list = new DelimiterList(delim, nodes, 0, "<", "3 6 9", null); DelimiterNodeList nodelist = new DelimiterNodeList(list); IScope scope = new TestScope(); INodeRequestor values = new TestValueNodeRequestor(nodelist); Value result = EvalNode.Do(nodelist, scope, values, null); Assert.AreEqual(18, result.AsInt); }
public void TestNested() { IParseLineDelimiters pld = new TestDelims(); IScope scope = new TestScope(); { DelimiterList list = ParseLine.Do("2 * ( 3 + 4 )", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(14, value.AsInt); } { DelimiterList list = ParseLine.Do("2 * ( 3 + ( 2 * 4 ) doubled + triple ( 2 + 3 ) )", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(68, value.AsInt); } }
public void ComputeOnInsertPrincipal() { using (var scope = TestScope.Create("u1-r1 u1-r12 u2-r12 u2-r2")) { // Insert test data: var u1 = scope.NewPrincipal("u1"); var u2 = scope.NewPrincipal("u2"); var u3 = scope.NewPrincipal("u3"); var u5 = scope.NewPrincipal("u5", domain: false); var r1 = scope.NewRole("r1"); var r2 = scope.NewRole("r2"); var r25 = scope.NewRole("r25", domain: false); var roles = scope.Resolve <GenericRepository <Common.Role> >(); var principals = scope.Resolve <GenericRepository <IPrincipal> >(); var membership = scope.Resolve <GenericRepository <Common.PrincipalHasRole> >(); roles.Insert(r1, r2, r25); Assert.AreEqual(@"\r1, \r2, r25", scope.ReportRoles(roles.Load()), "roles created"); principals.Insert(u1, u2, u3, u5); Assert.AreEqual(@"\u1, \u2, \u3, u5", scope.ReportPrincipals(principals.Load()), "principals created"); // Recompute membership on insert domain users: Assert.AreEqual(@"\u1-\r1, \u2-\r2", scope.ReportMembership(), "auto-membership on insert"); // Inserting non-domain users and roles: membership.Insert(new[] { new Common.PrincipalHasRole { PrincipalID = u2.ID, RoleID = r25.ID }, new Common.PrincipalHasRole { PrincipalID = u5.ID, RoleID = r25.ID } }, checkUserPermissions: true); Assert.AreEqual(@"\u1-\r1, \u2-\r2, \u2-r25, u5-r25", scope.ReportMembership(), "non-domain users and roles"); } }
public void UniqueReference() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); var p = new TestBrowse.ParentBase { Name = "p" }; repository.TestBrowse.ParentBase.Insert(p); var pur = new TestBrowse.ParentUniqueReference { ID = p.ID, Name3 = "pur" }; repository.TestBrowse.ParentUniqueReference.Insert(pur); Assert.AreEqual("p-pur", repository.TestBrowse.ParentUniqueReferenceBrowse1.Query(item => item.ID == p.ID).Select(item => item.Name + "-" + item.Name3).Single()); Assert.AreEqual("p-pur", repository.TestBrowse.ParentUniqueReferenceBrowse2.Query(item => item.ID == p.ID).Select(item => item.Name + "-" + item.Name3).Single()); } }
private YoutubeSearchController GetController(TestScope scope) { switch (scope) { case TestScope.GoogleApiNotResponseScope: return(new YoutubeSearchController(GetMockYoutubeServiceError(), null, null)); case TestScope.ArgumentNullExcepionScope: return(new YoutubeSearchController(GetMockYoutubeService(), GetMockCanalServiceArgumentNull(), null)); case TestScope.ArgumentExceptionScope: return(new YoutubeSearchController(GetMockYoutubeService(), GetMockCanalServiceArgument(), null)); case TestScope.ServiceExceptionScope: return(new YoutubeSearchController(GetMockYoutubeService(), GetMockCanalServiceException(), null)); default: return(new YoutubeSearchController(GetMockYoutubeServiceError(), null, null)); } }
public async Task ValidInputsTests() { // arrange var generator = new GeneratorService(); using (var scope = new TestScope()) using (var context = scope.ConnectDb()) using ( var instance = new TrimmerService( context, generator, scope.Config ) ) { // act var urls = new List <string>(); foreach (var key in ValidInputs) { var val = await instance .TrimUrlAsync(key); urls.Add(val.Print()); } var list = await context .TrimUrls .ToListAsync(); var cast = list.Select(i => { var j = new TrimUriModel( i.Address, instance.UriPrefix + i.HashCode ); return(j.Print()); }).ToList(); var match = Enumerable.SequenceEqual(urls, cast); // assert Assert.True(match); } }
public static void Initialize(TestContext testContext) { listTitle = $"TempList {Guid.NewGuid()}"; var values = new Hashtable(); values.Add("Title", "Test Item"); TestScope.ExecuteCommand("New-PnPList", new CommandParameter("Title", listTitle), new CommandParameter("Template", ListTemplateType.GenericList) ); var results = TestScope.ExecuteCommand("Add-PnPListItem", new CommandParameter("List", listTitle), new CommandParameter("Values", values)); if (results.Count > 0) { itemId = ((ListItem)results[0].BaseObject).Id; } }
private async Task ReceiveEventsAsync(TestScope scope, TestScenario scenario, CancellationToken cancellationToken) { var receiveFunction = scope.GetService <ReceiveEntityEvent>(); for (var i = 0; i < scenario.Events.Length; i++) { var @event = scenario.Events[i]; try { var httpRequest = new DefaultHttpRequest(new DefaultHttpContext()) { Body = new MemoryStream(Encoding.UTF8.GetBytes(@event.Payload.ToString())), }; await receiveFunction.RunAsync(httpRequest, @event.EntityType, @event.SourceSystemName, cancellationToken); } catch (Exception ex) { throw new Exception($"Error receiving event {@event.Name} (index {i}): {ex.Message}", ex); } } }
public void RecomputeMembership() { using (var scope = TestScope.Create("u1-r1 u1-r12 u2-r12 u2-r2")) { // Insert test data: var u1 = scope.NewPrincipal("u1"); var u2 = scope.NewPrincipal("u2"); var u3 = scope.NewPrincipal("u3"); var u5 = scope.NewPrincipal("u5", domain: false); var r1 = scope.NewRole("r1"); var r2 = scope.NewRole("r2"); var r25 = scope.NewRole("r25", domain: false); var repository = scope.Resolve <Common.DomRepository>(); var roles = scope.Resolve <GenericRepository <Common.Role> >(); var principals = scope.Resolve <GenericRepository <IPrincipal> >(); var membership = repository.Common.PrincipalHasRole; roles.Insert(r1, r2, r25); principals.Insert(u1, u2, u3, u5); membership.Insert(new[] { // Non-domain users and roles. new Common.PrincipalHasRole { PrincipalID = u2.ID, RoleID = r25.ID }, new Common.PrincipalHasRole { PrincipalID = u5.ID, RoleID = r25.ID } }); // Recompute membership relations: var u1r1 = membership.Query(m => m.Principal.Name.Contains(@"\u1")).Single(); membership.Delete(new[] { u1r1 }, checkUserPermissions: false); Assert.AreEqual(@"\u2-\r2, \u2-r25, u5-r25", scope.ReportMembership(), "modified membership"); repository.Common.PrincipalHasRole.RecomputeFromActiveDirectoryPrincipalHasRole(); Assert.AreEqual(@"\u1-\r1, \u2-\r2, \u2-r25, u5-r25", scope.ReportMembership(), "recomputed membership"); } }
public void TestDelimitedString() { ValueDelimiter delim = new ValueDelimiter("'", DelimiterType.AsString); List<DelimiterNode> nodes = new List<DelimiterNode>(); string str = "this is a test"; nodes.Add(ToNode(str)); DelimiterList list = new DelimiterList(delim, nodes, 0, "'", str, null); DelimiterNodeList nodelist = new DelimiterNodeList(list); IScope scope = new TestScope(); INodeRequestor values = new TestValueNodeRequestor(nodelist); { // delimited string Value result = EvalNode.Do(nodelist, scope, values, null); Assert.AreEqual("this is a test", result.AsString); } { // function that takes a delimited string Value result = EvalNode.Do(ToNode("caps"), scope, values, null); Assert.AreEqual("THIS IS A TEST", result.AsString); } }
public void SimpleReference() { using (var scope = TestScope.Create()) { var repository = scope.Resolve <Common.DomRepository>(); Guid refID = Guid.NewGuid(); scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestBrowse.Source;", "DELETE FROM TestBrowse.Other;", "INSERT INTO TestBrowse.Other (ID, Name) SELECT '" + refID + "', 'abc';", "INSERT INTO TestBrowse.Source (RefID) SELECT '" + refID + "';", }); Assert.AreEqual("abc", repository.TestBrowse.Source.Query().ToArray().Select(item => item.Ref != null ? item.Ref.Name : null).Single(), "separated loading with null checking"); Assert.AreEqual("abc", repository.TestBrowse.Source.Query().Select(item => item.Ref != null ? item.Ref.Name : null).Single(), "all in one query with null checking"); Assert.AreEqual("abc", repository.TestBrowse.Source.Query().Select(item => item.Ref.Name).Single(), "all in one query"); Assert.AreEqual("abc", repository.TestBrowse.Source.Query().ToArray().Select(item => item.Ref.Name).Single(), "separated loading"); } }
public void TestIntTagDiscovery() { string exText = "TagI1 + TagI2.FinalValue"; var scope = new TestScope(); var ce = new CompiledExpression <double>(exText); var del = ce.ScopeCompile <TestScope>(); var r = del(scope); var result = ExpressionUtilities.FindMembers(ce.Expression, scope); var key1 = scope.TagI1 as INotifyPropertyChanged; var key2 = scope.TagI2 as INotifyPropertyChanged; var result1 = result[key1]; var result2 = result[key2]; Assert.True(result.ContainsKey(key1), "tag1 not found"); Assert.True(result.ContainsKey(key2), "tag2 not found"); Assert.True(result[key1].Contains("Value")); Assert.True(result[key2].Contains("FinalValue")); }
public static void Initialize(TestContext testContext) { fieldName = $"Field{Guid.NewGuid()}"; var listResults = TestScope.ExecuteCommand("Get-PnPList"); if (listResults.Count > 0) { list = listResults[0].BaseObject as Microsoft.SharePoint.Client.List; } TestScope.ExecuteCommand("Add-PnPField", new CommandParameter("DisplayName", fieldName), new CommandParameter("InternalName", fieldName), new CommandParameter("Type", Microsoft.SharePoint.Client.FieldType.Text)); TestScope.ExecuteCommand("Add-PnPField", new CommandParameter("List", list.Title), new CommandParameter("DisplayName", $"{fieldName}2"), new CommandParameter("InternalName", $"{fieldName}2"), new CommandParameter("Type", Microsoft.SharePoint.Client.FieldType.Text)); }
public void TestArray() { ValueDelimiter delim = new ValueDelimiter("]", DelimiterType.AsArray); List<DelimiterNode> nodes = new List<DelimiterNode>(); nodes.Add(ToNode("3")); nodes.Add(ToNode("7")); nodes.Add(ToNode("3")); DelimiterList list = new DelimiterList(delim, nodes, 0, "[", "3 7 3", null); DelimiterNodeList nodelist = new DelimiterNodeList(list); IScope scope = new TestScope(); INodeRequestor values = new TestValueNodeRequestor(nodelist); { // [3 7 3] Value result = EvalNode.Do(nodelist, scope, values, null); Assert.AreEqual(result.Type, ValueType.Array); List<Value> array = result.AsArray; Assert.AreEqual(3, array.Count); Assert.AreEqual(3, array[0].AsInt); Assert.AreEqual(7, array[1].AsInt); Assert.AreEqual(3, array[2].AsInt); } }
public void ParallelRequestsTryCreatePrincipal() { string u1Name = TestName + "U"; string r1Name = TestName + "P"; string commonTestSuffix = Guid.NewGuid().ToString().Replace("-", ""); IPrincipal u1Prototype; Common.Role r1; RhetosAppOptions rhetosAppOptions; using (var scope = TestScope.Create($"{u1Name}-{r1Name}", commonTestSuffix)) { rhetosAppOptions = scope.Resolve <RhetosAppOptions>(); u1Prototype = scope.NewPrincipal(u1Name); var roles = scope.Resolve <GenericRepository <Common.Role> >(); r1 = scope.NewRole(r1Name); roles.Insert(r1); scope.CommitAndClose(); } rhetosAppOptions.AuthorizationAddUnregisteredPrincipals = true; for (int test = 0; test < 5; test++) { Console.WriteLine("Test: " + test); // Test setup: PrincipalHasRole is deleted to make sure it is not up-to-date. // PrincipalHasRole will be recomputed when reading PrincipalHasRole. using (var scope = TestScope.Create($"{u1Name}-{r1Name}", commonTestSuffix)) { var principals = scope.Resolve <GenericRepository <IPrincipal> >(); principals.Delete(principals.Load(p => p.Name.Contains(TestName))); var membership = scope.Resolve <GenericRepository <Common.PrincipalHasRole> >(); membership.Delete(membership.Load()); Assert.AreEqual(@"", scope.ReportMembership(), "Initial empty membership."); AuthorizationDataCache.ClearCache(); scope.CommitAndClose(); } // Recompute membership on authorization with multiple parallel requests: Parallel.For(0, 4, thread => { using (var scope = TestScope.Create($"{u1Name}-{r1Name}", commonTestSuffix, builder => builder.RegisterInstance(rhetosAppOptions).ExternallyOwned())) { var authorizationData = scope.Resolve <IAuthorizationData>(); var authorizationProvider = scope.Resolve <CommonAuthorizationProvider>(); PrincipalInfo u1 = authorizationData.GetPrincipal(u1Prototype.Name); // First call will automatically create a new principal, see AuthorizationAddUnregisteredPrincipals above. var userRoles = authorizationProvider.GetUsersRoles(u1); Assert.AreEqual($@"\{r1Name}", scope.ReportRoles(userRoles), "User's roles should be recomputed."); Assert.AreEqual($@"\{u1Name}-\{r1Name}", scope.ReportMembership(), "Updated role membership"); scope.CommitAndClose(); } }); } }
private async Task ProcessEventsAsync(TestScope scope, CancellationToken cancellationToken) { var queue = scope.GetService <SyncQueueStub>(); await queue.DrainQueueAsync(cancellationToken); }
public void ComputeOnAuthorization() { using (var scope = TestScope.Create("u1-r1 u1-r12 u2-r12 u2-r2", null)) { // Insert test data: var u1 = scope.NewPrincipal("u1"); var u2 = scope.NewPrincipal("u2"); var u3 = scope.NewPrincipal("u3"); var u5 = scope.NewPrincipal("u5", domain: false); var r1 = scope.NewRole("r1"); var r2 = scope.NewRole("r2"); var r25 = scope.NewRole("r25", domain: false); var roles = scope.Resolve <GenericRepository <Common.Role> >(); var principals = scope.Resolve <GenericRepository <IPrincipal> >(); var membership = scope.Resolve <GenericRepository <Common.PrincipalHasRole> >(); roles.Insert(r1, r2, r25); principals.Insert(u1, u2, u3, u5); membership.Delete(membership.Load()); membership.Insert(new[] { // Non-domain users and roles. new Common.PrincipalHasRole { PrincipalID = u2.ID, RoleID = r25.ID }, new Common.PrincipalHasRole { PrincipalID = u5.ID, RoleID = r25.ID } }); // Recompute membership on authorization: var authorizationProvider = scope.Resolve <CommonAuthorizationProvider>(); Assert.AreEqual(@"\u2-r25, u5-r25", scope.ReportMembership()); { var userRoles = authorizationProvider.GetUsersRoles(u1); Assert.AreEqual(@"\r1", scope.ReportRoles(userRoles)); Assert.AreEqual(@"\u1-\r1, \u2-r25, u5-r25", scope.ReportMembership(), "membership recomputed on authorization u1"); } { var userRoles = authorizationProvider.GetUsersRoles(u2); Assert.AreEqual(@"\r2, r25", scope.ReportRoles(userRoles), "mixed membership"); Assert.AreEqual(@"\u1-\r1, \u2-\r2, \u2-r25, u5-r25", scope.ReportMembership(), "membership recomputed on authorization u2"); } AuthorizationDataCache.ClearCache(); membership.Delete(membership.Load()); Assert.AreEqual(@"", scope.ReportMembership(), "membership deleted"); { var userRoles = authorizationProvider.GetUsersRoles(u1); Assert.AreEqual(@"\r1", scope.ReportRoles(userRoles)); Assert.AreEqual(@"\u1-\r1", scope.ReportMembership(), "membership recomputed on authorization u1"); } { var userRoles = authorizationProvider.GetUsersRoles(u2); Assert.AreEqual(@"\r2", scope.ReportRoles(userRoles)); Assert.AreEqual(@"\u1-\r1, \u2-\r2", scope.ReportMembership(), "membership recomputed on authorization u2"); } } }
public void ShouldReturnOneForFirstIdInNewScope() { // Arrange var account = CloudStorageAccount.DevelopmentStorageAccount; using (var testScope = new TestScope(account)) { var store = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator = new UniqueIdGenerator(store) {BatchSize = 3}; // Act var generatedId = generator.NextId(testScope.IdScopeName); // Assert Assert.AreEqual(1, generatedId); } }
protected override IOptimisticDataStore BuildStore(TestScope scope) { return(new BlobOptimisticDataStore("UseDevelopmentStorage=true", scope.ContainerName)); }
public void TestPrefix() { IParseLineDelimiters pld = new TestDelims(); IScope scope = new TestScope(); { DelimiterList list = ParseLine.Do("triple 3", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(9, value.AsInt); } { DelimiterList list = ParseLine.Do("triple triple 2", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(18, value.AsInt); } { DelimiterList list = ParseLine.Do("triple x", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(18, value.AsInt); } }
public static void Cleanup() { TestScope.ExecuteCommand("Remove-PnPFile", new CommandParameter("SiteRelativeUrl", $"Shared Documents/{fileName}"), new CommandParameter("Force")); }
public void ShouldUpdateBlobWhenGeneratingNextIdAfterEndOfBatch() { // Arrange var account = CloudStorageAccount.DevelopmentStorageAccount; using (var testScope = new TestScope(account)) { var store = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator = new UniqueIdGenerator(store) { BatchSize = 3 }; // Act generator.NextId(testScope.IdScopeName); //1 generator.NextId(testScope.IdScopeName); //2 generator.NextId(testScope.IdScopeName); //3 generator.NextId(testScope.IdScopeName); //4 // Assert Assert.AreEqual("7", testScope.ReadCurrentBlobValue()); } }
public void ShouldCreateFileOnFirstAccess() { using (var testScope = new TestScope(scope)) { var store = new FileOptimisticDataStore(Path.GetTempPath()); store.GetNextBatch(scope, batch); Assert.IsTrue(File.Exists(testScope.FilePath)); Assert.AreEqual(testScope.ReadCurrentPersistedValue(), FileOptimisticDataStore.SeedValue + batch); } }
public void GetPnPListTest() { var results = TestScope.ExecuteCommand("Get-PnPList"); Assert.IsTrue(results.Count > 0); }
public CommentsSteps(TestScope testScope) { _testScope = testScope; }
public void ShouldReturnIdsFromThirdBatchIfSecondBatchTakenByAnotherGenerator() { // Arrange var account = CloudStorageAccount.DevelopmentStorageAccount; using (var testScope = new TestScope(account)) { var store1 = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator1 = new UniqueIdGenerator(store1) { BatchSize = 3 }; var store2 = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator2 = new UniqueIdGenerator(store2) { BatchSize = 3 }; // Act generator1.NextId(testScope.IdScopeName); //1 generator1.NextId(testScope.IdScopeName); //2 generator1.NextId(testScope.IdScopeName); //3 generator2.NextId(testScope.IdScopeName); //4 var lastId = generator1.NextId(testScope.IdScopeName); //7 // Assert Assert.AreEqual(7, lastId); } }
public void GetPnPSpecifiedListTest() { var results = TestScope.ExecuteCommand("Get-PnPList", new CommandParameter("Identity", listTitle)); Assert.AreEqual(results.Count, 1); }
public void ShouldSupportUsingOneGeneratorFromMultipleThreads() { // Arrange var account = CloudStorageAccount.DevelopmentStorageAccount; using (var testScope = new TestScope(account)) { var store = new BlobOptimisticDataStore(account, testScope.ContainerName); var generator = new UniqueIdGenerator(store) { BatchSize = 1000 }; const int testLength = 10000; // Act var generatedIds = new ConcurrentQueue<long>(); var threadIds = new ConcurrentQueue<int>(); var scopeName = testScope.IdScopeName; Parallel.For( 0, testLength, new ParallelOptions { MaxDegreeOfParallelism = 10 }, i => { generatedIds.Enqueue(generator.NextId(scopeName)); threadIds.Enqueue(Thread.CurrentThread.ManagedThreadId); }); // Assert we generated the right count of ids Assert.AreEqual(testLength, generatedIds.Count); // Assert there were no duplicates Assert.IsFalse(generatedIds.GroupBy(n => n).Where(g => g.Count() != 1).Any()); // Assert we used multiple threads var uniqueThreadsUsed = threadIds.Distinct().Count(); if (uniqueThreadsUsed == 1) Assert.Inconclusive("The test failed to actually utilize multiple threads"); } }
/// <summary> /// Specifies that the tests in the specified scope are parallelizable. /// </summary> /// <param name="scope">The test scope.</param> public ParallelizableAttribute(TestScope scope) { this.scope = scope; }
protected override async Task <IOptimisticDataStore> BuildStoreAsync(TestScope scope) { return(await BlobOptimisticDataStore.CreateAsync(storageAccount, scope.ContainerName)); }
public void GetNextBatchShouldReturnMinusOneWhenBlocked() { using (var testScope = new TestScope(scope)) { var store = new FileOptimisticDataStore(Path.GetTempPath()); store.GetNextBatch(scope, batch); using (FileStream stream = File.Open(testScope.FilePath, FileMode.Open, FileAccess.Read, FileShare.None)) Assert.AreEqual(-1, store.GetNextBatch(scope, batch)); } }
public void TestFunctions() { IScope scope = new TestScope(); INodeRequestor values = new TestValueIntRequestor(); // infix Value result = EvalNode.Do(ToNode("sum"), scope, values, null); Assert.AreEqual(10, result.AsInt); // only uses previous token result = EvalNode.Do(ToNode("prev1"), scope, values, null); Assert.AreEqual(4, result.AsInt); // only uses next token result = EvalNode.Do(ToNode("next1"), scope, values, null); Assert.AreEqual(8, result.AsInt); }
public void TestPostfix() { IParseLineDelimiters pld = new TestDelims(); IScope scope = new TestScope(); { DelimiterList list = ParseLine.Do("4 doubled", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(8, value.AsInt); } { // last doubled runs first, asks for the previous value & triggers first doubled DelimiterList list = ParseLine.Do("4 doubled doubled", pld); Value value = EvalList.Do(list.Nodes, scope); Assert.AreEqual(16, value.AsInt); } }
public void TestVariable() { IScope scope = new TestScope(); INodeRequestor values = new TestValueIntRequestor(); Value result = EvalNode.Do(ToNode("x"), scope, values, null); Assert.AreEqual(3.5, result.AsFloat); }
protected override IOptimisticDataStore BuildStore(TestScope scope) { return(new DebugOnlyFileDataStore(scope.DirectoryPath)); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously protected override async Task <IOptimisticDataStore> BuildStoreAsync(TestScope scope) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { return(new DebugOnlyFileDataStore(scope.DirectoryPath)); }
public void TestFailure() { IScope scope = new TestScope(); INodeRequestor values = new TestValueIntRequestor(); bool bCatch = false; try { Value result = EvalNode.Do(ToNode("qwer"), scope, values, null); } catch (Loki3Exception e) { Assert.True(e.Errors.ContainsKey(Loki3Exception.keyBadToken)); Assert.AreEqual("qwer", e.Errors[Loki3Exception.keyBadToken].AsString); bCatch = true; } Assert.True(bCatch); }
protected override IOptimisticDataStore BuildStore(TestScope scope) { return(new BlobOptimisticDataStore(storageAccount, scope.ContainerName)); }
public static void Cleanup() { TestScope.ExecuteCommand("Remove-PnPList", new CommandParameter("Identity", listTitle), new CommandParameter("Force")); }
public WebAPISteps(TestScope testScope, IObjectContainer objectContainer) { _testScope = testScope; _objectContainer = objectContainer; }