public void TestEndedTransaction() { using (ProgressTracker tracker = new ProgressTracker()) { IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); // Step 1 { Expect.Once.On(mockedSubscriber). Method("IdleStateChanged"). WithAnyArguments(); Expect.Between(0, 1).On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) } ); tracker.Track(test1); } // Step 2 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f)) } ); tracker.Track(Transaction.EndedDummy); } // Step 3 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) } ); Expect.Once.On(mockedSubscriber). Method("IdleStateChanged"). WithAnyArguments(); test1.End(); } } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { var transaction = new TestTransaction(this); _transactions.Add(transaction); return(transaction); }
public void DC_Dispose() { SnDataContext dataContext = null; TestConnection testConnection = null; TestTransaction testTransaction = null; try { using (dataContext = new TestDataContext(CancellationToken.None)) { Assert.IsFalse(dataContext.IsDisposed); using (var transaction = dataContext.BeginTransaction(IsolationLevel.ReadCommitted, TimeSpan.FromMinutes(10))) { testConnection = (TestConnection)dataContext.Connection; testTransaction = (TestTransaction)dataContext.Transaction.Transaction; throw new SnNotSupportedException(); } } } catch (SnNotSupportedException) { // do nothing } Assert.IsTrue(testConnection.State == ConnectionState.Closed); Assert.IsTrue(testTransaction.IsRollbackCalled); Assert.IsTrue(dataContext.IsDisposed); }
private static void SendTxn(IServiceProvider sp, KeyPair keys, string address, int amount) { var node = sp.GetService <INodeHost>(); var sigService = sp.GetService <ISignatureService>(); var addressEncoder = sp.GetService <IAddressEncoder>(); var origin = addressEncoder.EncodeAddress(keys.PublicKey, 0); var txn1 = new TestTransaction() { Message = "hello", Amount = amount, Destination = address }; var txn1env = new NBlockchain.Models.Transaction(txn1) { OriginKey = Guid.NewGuid(), TransactionType = "txn-v1", Originator = origin }; sigService.SignTransaction(txn1env, keys.PrivateKey); node.SendTransaction(txn1env); }
[InlineValue(100.0, 100.00001, -0.00001)] // fails here with System.FormatException : Input string was not in a correct format. public void Query_should_return_list_of_transaction_balances(decimal debit, decimal credit, decimal expected) { // Arrange var transaction = new TestTransaction { Debit = debit, Credit = credit }; using (var store = Store()) { using (var session = store.OpenSession()) { // Arrange session.Store(transaction); session.SaveChanges(); } using (var session = store.OpenSession()) { // Act var query = session.Query <TransactionBalances_ByYear.Result, TransactionBalances_ByYear>() .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.Year <= 2011).ToList(); // Assert Assert.Equal(expected, query.First().Balance); } } }
private TestTransaction.Response TestTransactionHandler(TestTransaction command) { try { var command1 = new CreatePerson { Age = 11, Birthday = DateTimeOffset.Now, FirstName = "Hengdeyang", IsActive = true, LastName = "Oliv", Sex = 0 }; var command2 = new CreateTeam { }; platform.CallCommand <CreatePerson, CreatePerson.Response>(command1); platform.CallCommand <CreateTeam, CreateTeam.Response>(command2); } catch (Exception ex) { throw ex; } }
public static async Task <TestTransaction> SendAsync(this TestServer server, HttpRequestMessage request, string cookieHeader) { if (!string.IsNullOrEmpty(cookieHeader)) { request.Headers.Add("Cookie", cookieHeader); } var transaction = new TestTransaction { Request = request, Response = await server.CreateClient().SendAsync(request), }; if (transaction.Response.Headers.Contains("Set-Cookie")) { transaction.SetCookie = transaction.Response.Headers.GetValues("Set-Cookie").ToList(); } transaction.ResponseText = await transaction.Response.Content.ReadAsStringAsync(); if (transaction.Response.Content != null && transaction.Response.Content.Headers.ContentType != null && transaction.Response.Content.Headers.ContentType.MediaType == "text/xml") { transaction.ResponseElement = XElement.Parse(transaction.ResponseText); } return(transaction); }
public void TestWeightStorage() { TestTransaction transaction = new TestTransaction(); WeightedTransaction<Transaction> testWrapper = new WeightedTransaction<Transaction>( transaction, 12.0f ); Assert.AreEqual(12.0f, testWrapper.Weight); }
public void TestDefaultWeight() { TestTransaction transaction = new TestTransaction(); WeightedTransaction<Transaction> testWrapper = new WeightedTransaction<Transaction>( transaction ); Assert.AreEqual(1.0f, testWrapper.Weight); }
public void TestTransactionStorage() { TestTransaction transaction = new TestTransaction(); WeightedTransaction<Transaction> testWrapper = new WeightedTransaction<Transaction>( transaction ); Assert.AreSame(transaction, testWrapper.Transaction); }
public async Task StressTest() { // this test adds the integers min..max to the dictionary // then, in multiple threads (ratio * max tasks), // creates transactions that (in the given ratio) // either updates the value to its negative or removes it const int min = 1; const int max = 10000; const int ratio = 10; var rng = new ThreadLocal <Random>(() => new Random()); using (var tx = new TestTransaction()) { for (var i = min; i <= max; i++) { await _dictionary.AddAsync(tx, i, i); } await tx.CommitAsync(); } var tasks = Enumerable.Range(1, max * ratio).OrderBy(x => rng.Value.Next()).Select(async x => { using (var tx = new TestTransaction()) { var key = x / ratio; if (rng.Value.Next(ratio) == 0) { await _dictionary.TryRemoveAsync(tx, key); } else { await _dictionary.TryUpdateAsync(tx, key, -key, key); } await tx.CommitAsync(); } }).ToArray(); await Task.WhenAll(tasks); using (var tx = new TestTransaction()) { var enumerable = await _dictionary.CreateEnumerableAsync(tx); using (var enumerator = enumerable.GetAsyncEnumerator()) { while (await enumerator.MoveNextAsync(CancellationToken.None)) { var x = enumerator.Current.Value; Assert.IsTrue(x >= -max); Assert.IsTrue(x <= -min); } } } }
public void TestThrowOnRepeatedlyEndedTransaction() { TestTransaction test = new TestTransaction(); test.End(); Assert.Throws <InvalidOperationException>( delegate() { test.End(); } ); }
public void TestWeightStorage() { TestTransaction transaction = new TestTransaction(); WeightedTransaction <Transaction> testWrapper = new WeightedTransaction <Transaction>( transaction, 12.0f ); Assert.AreEqual(12.0f, testWrapper.Weight); }
public void TestTransactionStorage() { TestTransaction transaction = new TestTransaction(); WeightedTransaction <Transaction> testWrapper = new WeightedTransaction <Transaction>( transaction ); Assert.AreSame(transaction, testWrapper.Transaction); }
public void TestDefaultWeight() { TestTransaction transaction = new TestTransaction(); WeightedTransaction <Transaction> testWrapper = new WeightedTransaction <Transaction>( transaction ); Assert.AreEqual(1.0f, testWrapper.Weight); }
public void TestThrowOnUntrackNonTrackedTransaction() { using (ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); Assert.Throws <ArgumentException>( delegate() { tracker.Untrack(test1); } ); } }
public void TestWaitUnlimited() { TestTransaction test = new TestTransaction(); // We can only do a positive test here without slowing down the unit test ThreadPool.QueueUserWorkItem( (WaitCallback) delegate(object state) { Thread.Sleep(1); test.End(); } ); test.Wait(); }
public async Task SingleValueWithinTransaction() { using (var tx = new TestTransaction()) { await _dictionary.AddAsync(tx, 1, 1); var value = await _dictionary.TryGetValueAsync(tx, 1); Assert.AreEqual(1, value.Value); } }
public async Task StressTest() { // this test adds the integers min..max to the queue // then, in multiple threads (ratio * max tasks), // creates transactions that (in the given ratio) // either enqueues or dequeues const int min = 1; const int max = 1000; const int ratio = 10; var rng = new ThreadLocal <Random>(() => new Random()); using (var tx = new TestTransaction()) { for (var i = min; i <= max; i++) { await _queue.EnqueueAsync(tx, i); } await tx.CommitAsync(); } var added = 0; var tasks = Enumerable.Range(1, max * ratio).Select(async x => { using (var tx = new TestTransaction()) { var key = x / ratio; if (rng.Value.Next(ratio) == 0) { await _queue.TryDequeueAsync(tx); Interlocked.Decrement(ref added); } else { await _queue.EnqueueAsync(tx, key); Interlocked.Increment(ref added); } await tx.CommitAsync(); } }).ToArray(); await Task.WhenAll(tasks); using (var tx = new TestTransaction()) { var count = await _queue.GetCountAsync(tx); Assert.AreEqual(max + added, count); } }
public async Task SingleValueWithinTransaction() { using (var tx = new TestTransaction()) { await _queue.EnqueueAsync(tx, 1); var value = await _queue.TryDequeueAsync(tx); Assert.AreEqual(1, value.Value); } }
public void TestMultiTrackedTransaction() { using (ProgressTracker tracker = new ProgressTracker()) { TestTransaction test = new TestTransaction(); tracker.Track(test); tracker.Track(test); tracker.Track(test); tracker.Untrack(test); tracker.Untrack(test); tracker.Untrack(test); } }
public void TestEndedEventAfterSubscription() { TestTransaction test = new TestTransaction(); Mock <ITransactionSubscriber> mockedSubscriber = mockSubscriber(test); mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments(); test.End(); this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public async Task TwoConcurrentTransactionsTimeout() { using (var tx1 = new TestTransaction()) using (var tx2 = new TestTransaction()) { await _queue.EnqueueAsync(tx1, 1); await Assert.ThrowsExceptionAsync <TimeoutException>(async() => // ReSharper disable once AccessToDisposedClosure await _queue.EnqueueAsync(tx2, 2)); } }
public async Task SameKeyTwoTransactionsTimeout() { using (var tx1 = new TestTransaction()) using (var tx2 = new TestTransaction()) { await _dictionary.AddAsync(tx1, 1, 1); await Assert.ThrowsExceptionAsync <TimeoutException>(async() => // ReSharper disable once AccessToDisposedClosure await _dictionary.AddAsync(tx2, 1, 1)); } }
public void SetTransaction() { SetupAndAssert(dbCmd => { TestTransaction trans = new TestTransaction(); Assert.Null(dbCmd.Transaction); IDbCmd dbCmd2 = dbCmd.Transaction(trans); Assert.Same(dbCmd, dbCmd2); Assert.Same(trans, dbCmd.Transaction); dbCmd.Transaction(null); Assert.Null(dbCmd.Transaction); }); }
public void SetTransaction() { SetupConnection(dbCon => { Assert.Equal(ConnectionState.Closed, dbCon.State); var trans = new TestTransaction(); IDbCmd cmd = dbCon.Transaction(trans); Assert.NotNull(cmd); Assert.Same(trans, cmd.Transaction); Assert.Same(dbCon, cmd.Connection); Assert.Equal(ConnectionState.Closed, dbCon.State); }); }
public void TestWaitTimeSpan() { TestTransaction test = new TestTransaction(); // Wait 0 milliseconds for the transaction to end. Of course, this will not happen, // so a timeout occurs and false is returned Assert.IsFalse(test.Wait(TimeSpan.Zero)); test.End(); // Wait another 0 milliseconds for the transaction to end. Now it has already ended // and no timeout will occur, even with a wait time of 0 milliseconds. Assert.IsTrue(test.Wait(TimeSpan.Zero)); }
public async Task SingleValueTransactionAborted() { using (var tx = new TestTransaction()) { await _dictionary.AddAsync(tx, 1, 1); } using (var tx = new TestTransaction()) { var value = await _dictionary.TryGetValueAsync(tx, 1); Assert.IsFalse(value.HasValue); } }
public void TestEndedEventAfterSubscription() { TestTransaction test = new TestTransaction(); ITransactionSubscriber mockedSubscriber = mockSubscriber(test); Expect.Once.On(mockedSubscriber). Method("Ended"). WithAnyArguments(); test.End(); this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestProvokedDeadlock() { using (ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); tracker.Track(test1); tracker.AsyncIdleStateChanged += (EventHandler <IdleStateEventArgs>) delegate(object sender, IdleStateEventArgs arguments) { tracker.Track(Transaction.EndedDummy); }; test1.End(); } }
public async Task SingleValueTransactionAborted() { using (var tx = new TestTransaction()) { await _queue.EnqueueAsync(tx, 1); } using (var tx = new TestTransaction()) { var value = await _queue.TryDequeueAsync(tx); Assert.IsFalse(value.HasValue); } }
public void TestEndedEventDuingSubscription() { TestTransaction test = new TestTransaction(); test.End(); Mock <ITransactionSubscriber> mockedSubscriber = this.mockery.CreateMock <ITransactionSubscriber>(); mockedSubscriber.Expects.One.Method(m => m.Ended(null, null)).WithAnyArguments(); test.AsyncEnded += new EventHandler(mockedSubscriber.MockObject.Ended); this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestEndedTransaction() { using (ProgressTracker tracker = new ProgressTracker()) { Mock <IProgressTrackerSubscriber> mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); // Step 1 { mockedSubscriber.Expects.One.Method( m => m.IdleStateChanged(null, null) ).WithAnyArguments(); mockedSubscriber.Expects.AtMost(1).Method(m => m.ProgressChanged(null, null)).With( new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) ); tracker.Track(test1); } // Step 2 { mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f)) ); tracker.Track(Transaction.EndedDummy); } // Step 3 { mockedSubscriber.Expects.One.Method(m => m.ProgressChanged(null, null)).With( new NMock.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) ); mockedSubscriber.Expects.One.Method( m => m.IdleStateChanged(null, null) ).WithAnyArguments(); test1.End(); } } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestThrowOnRepeatedlyEndedTransaction() { TestTransaction test = new TestTransaction(); test.End(); Assert.Throws<InvalidOperationException>( delegate() { test.End(); } ); }
public void TestEndedEventDuingSubscription() { TestTransaction test = new TestTransaction(); test.End(); ITransactionSubscriber mockedSubscriber = this.mockery.NewMock<ITransactionSubscriber>(); Expect.Once.On(mockedSubscriber). Method("Ended"). WithAnyArguments(); test.AsyncEnded += new EventHandler(mockedSubscriber.Ended); this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestWaitUnlimited() { TestTransaction test = new TestTransaction(); // We can only do a positive test here without slowing down the unit test ThreadPool.QueueUserWorkItem( (WaitCallback)delegate(object state) { Thread.Sleep(1); test.End(); } ); test.Wait(); }
public void TestMultiTrackedTransaction() { using(ProgressTracker tracker = new ProgressTracker()) { TestTransaction test = new TestTransaction(); tracker.Track(test); tracker.Track(test); tracker.Track(test); tracker.Untrack(test); tracker.Untrack(test); tracker.Untrack(test); } }
public void TestUnsubscribeInEndedCallback() { TestTransaction monitored = new TestTransaction(); UnsubscribingTransaction test = new UnsubscribingTransaction(monitored); ITransactionSubscriber mockedSubscriber = mockSubscriber(monitored); try { Expect.Once.On(mockedSubscriber).Method("Ended").WithAnyArguments(); monitored.End(); this.mockery.VerifyAllExpectationsHaveBeenMet(); } finally { test.End(); } }
public void TestSummedProgress() { using(ProgressTracker tracker = new ProgressTracker()) { IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); TestTransaction test2 = new TestTransaction(); // Step 1 { Expect.Once.On(mockedSubscriber).Method("IdleStateChanged").WithAnyArguments(); // Since the progress is already at 0, these redundant reports are optional Expect.Between(0, 2).On(mockedSubscriber).Method("ProgressChanged").With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) } ); tracker.Track(test1); tracker.Track(test2); } // Step 2 { Expect.Once.On(mockedSubscriber).Method("ProgressChanged").With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) } ); test1.ChangeProgress(0.5f); } } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestDelayedRemoval() { using(ProgressTracker tracker = new ProgressTracker()) { IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); TestTransaction test2 = new TestTransaction(); // Step 1 { Expect.Once.On(mockedSubscriber). Method("IdleStateChanged"). WithAnyArguments(); // This is optional. The tracker's progress is currently 0, so there's no need // to send out superfluous progress reports. Expect.Between(0, 2).On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) } ); tracker.Track(test1); tracker.Track(test2); } // Step 2 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.25f)) } ); // Total progress should be 0.25 after this call (two transactions, one with // 0% progress and one with 50% progress) test1.ChangeProgress(0.5f); } // Step 3 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.75f)) } ); // Total progress should be 0.75 after this call (one transaction at 100%, // the other one at 50%). If the second transaction would be removed by the tracker, // (which would be inappropriate!) the progress would falsely jump to 0.5 instead. test2.End(); } // Step 4 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) } ); Expect.Once.On(mockedSubscriber). Method("IdleStateChanged"). WithAnyArguments(); test1.End(); } } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestEndedTransaction() { using(ProgressTracker tracker = new ProgressTracker()) { IProgressTrackerSubscriber mockedSubscriber = mockSubscriber(tracker); TestTransaction test1 = new TestTransaction(); // Step 1 { Expect.Once.On(mockedSubscriber). Method("IdleStateChanged"). WithAnyArguments(); Expect.Between(0, 1).On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.0f)) } ); tracker.Track(test1); } // Step 2 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(0.5f)) } ); tracker.Track(Transaction.EndedDummy); } // Step 3 { Expect.Once.On(mockedSubscriber). Method("ProgressChanged"). With( new Matcher[] { new NMock2.Matchers.TypeMatcher(typeof(ProgressTracker)), new ProgressReportEventArgsMatcher(new ProgressReportEventArgs(1.0f)) } ); Expect.Once.On(mockedSubscriber). Method("IdleStateChanged"). WithAnyArguments(); test1.End(); } } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestIdleWithAutoRemoval() { using(ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); Assert.IsTrue(tracker.Idle); tracker.Track(test1); Assert.IsFalse(tracker.Idle); test1.End(); Assert.IsTrue(tracker.Idle); } }
public void TestProgressWithUntrack() { using(ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); TestTransaction test2 = new TestTransaction(); tracker.Track(test1); tracker.Track(test2); Assert.AreEqual(0.0f, tracker.Progress); test1.ChangeProgress(0.5f); Assert.AreEqual(0.25f, tracker.Progress); tracker.Untrack(test2); Assert.AreEqual(0.5f, tracker.Progress); } }
public void TestThrowOnUntrackNonTrackedTransaction() { using(ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); Assert.Throws<ArgumentException>( delegate() { tracker.Untrack(test1); } ); } }
public void TestProvokedDeadlock() { using(ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); tracker.Track(test1); tracker.AsyncIdleStateChanged += (EventHandler<IdleStateEventArgs>)delegate(object sender, IdleStateEventArgs arguments) { tracker.Track(Transaction.EndedDummy); }; test1.End(); } }