public void RollbackTransaction_Forced_IsPassedToContext() { var testable = new SqlDatabaseSession(_sqlContext.Object, _logger); testable.RollbackTransaction(); _sqlContext.Verify(m => m.RollbackTransaction(false), Times.Once); }
static void Main(string[] args) { var sess = new SqlDatabaseSession("Testo"); // AddHeaps(sess); // AddRec(sess); Top(sess); }
private static void Top(SqlDatabaseSession sess) { var cmdQueueMap = new CommandQueueMap(sess); var rec = cmdQueueMap.Load().FirstOrDefault(); if (rec != null) { cmdQueueMap.Delete(rec); } }
public void Execute_Normally_AllHappens() { var testable = new SqlDatabaseSession(_sqlContext.Object, _logger); testable.Execute("DELETE FROM Cable WHERE Id = @id", new { id = 12 }); testable.ExecutionTime.Should().Be(new TimeSpan(0, 0, 0, 0, 386)); // Gets passed from internal dependency. _sqlContext.Verify(m => m.ExecuteSql(It.IsAny <Func <IDbTransaction, int> >()), Times.Once); _logger.LoggedMessages.Should().HaveCount(1); _logger.LoggedMessages[0].Should().Be("TRACE: Execute(DELETE FROM Cable WHERE Id = @id) issued for SqlDatabaseSession."); }
public async Task QueryAsync_NoCancellationToken_Waits() { var sessionLogger = new XUnitLogger <SqlDatabaseSession>(_output); var sess = new SqlDatabaseSession(_sut, sessionLogger); var cqrs = new CommandQueryContext(sess); var result = await cqrs.QueryAsync(new LongQuery()); result.Should().Be(1); _sut.ExecutionTime.Should().BeGreaterThan(TimeSpan.FromSeconds(9)); _sut.Dispose(); }
public async Task QueryFirstOrDefaultAsync_Normally_AllHappens() { var testable = new SqlDatabaseSession(_sqlContext.Object, _logger); await testable.QueryFirstOrDefaultAsync <int>("SELECT Label FROM Cable WHERE Id = @id", new { id = 12 }); testable.ExecutionTime.Should().Be(new TimeSpan(0, 0, 0, 0, 386)); // Gets passed from internal dependency. _sqlContext.Verify(m => m.ExecuteSql(It.IsAny <Func <IDbTransaction, Task <int> > >()), Times.Once); _logger.LoggedMessages.Should().HaveCount(1); _logger.LoggedMessages[0] .Should() .Be("TRACE: QueryFirstOrDefaultAsync<T>(SELECT Label FROM Cable WHERE Id = @id) called with expected return of type Int32."); }
public void Query_Normally_AllHappens() { var testable = new SqlDatabaseSession(_sqlContext.Object, _logger); testable.Query <int>("SELECT Ids FROM Cable WHERE Name = @name", new { name = "Yop" }); testable.ExecutionTime.Should().Be(new TimeSpan(0, 0, 0, 0, 386)); // Gets passed from internal dependency. _sqlContext.Verify(m => m.ExecuteSql(It.IsAny <Func <IDbTransaction, IEnumerable <int> > >()), Times.Once); _logger.LoggedMessages.Should().HaveCount(1); _logger.LoggedMessages[0] .Should() .Be("TRACE: Query<T>(SELECT Ids FROM Cable WHERE Name = @name) called with expected return of type IEnumerable<Int32>."); }
public async Task ExecuteAsync_Typed_AllHappens() { var testable = new SqlDatabaseSession(_sqlContext.Object, _logger); string result = await testable.ExecuteAsync <string>("SELECT label FROM Somewhere WHERE Id = @id", new { id = 12 }); testable.ExecutionTime.Should().Be(new TimeSpan(0, 0, 0, 0, 386)); // Gets passed from internal dependency. _sqlContext.Verify(m => m.ExecuteSql(It.IsAny <Func <IDbTransaction, Task <string> > >()), Times.Once); _logger.LoggedMessages.Should().HaveCount(1); _logger.LoggedMessages[0] .Should() .Be("TRACE: Execute<T>(SELECT label FROM Somewhere WHERE Id = @id) called with expected return of type String."); }
private static void AddHeaps(SqlDatabaseSession sess) { var cmdQueueMap = new CommandQueueMap(sess); for (var idx = 0; idx < 100000; idx++) { var rec = new CommandQueueRec { Id = Guid.NewGuid(), TimeQueued = DateTime.UtcNow, CommandType = "Test", TemplateName = "TemplateName", TemplateFields = "fields" + idx.ToString("000000") }; cmdQueueMap.Insert(rec); } }
public async Task QueryAsync_CancellationToken_GetsCancelled() { var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3)); var sessionLogger = new XUnitLogger <SqlDatabaseSession>(_output); var sess = new SqlDatabaseSession(_sut, sessionLogger); var cqrs = new CommandQueryContext(sess); var resultTask = cqrs.QueryAsync(new LongQuery(), cancellationTokenSource.Token); try { if (!resultTask.Wait(TimeSpan.FromSeconds(5))) { throw new TimeoutException("Async Query Cancellation did not happen."); // should have cancelled } } catch (AggregateException agg) { Assert.True(agg.InnerException.GetType().Name == "SqlException"); } _sut.Dispose(); }