public async Task Snapshot_SaveRemove_DataIsCommitted( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); var memoryDatabase = connection.GetMemoryDatabase( ); memoryDatabase.SaveSnapshot( ); var rows = memoryDatabase.Tables["dbo.application"].Rows; var currentRowCount = rows.Count; await connection.OpenAsync( ); var transaction = await connection.BeginTransactionAsync( ); await connection.ExecuteAsync(_SqlInsertApplication, new { Name = "Name string", User = "******", DefName = "DefName string" }, transaction); await connection.ExecuteAsync(_SqlInsertApplication, new { Name = "Name string", User = "******", DefName = "DefName string" }, transaction); await transaction.CommitAsync( ); memoryDatabase.RemoveSnapshot( ); var currentRows = memoryDatabase.Tables["dbo.application"].Rows; currentRows.Count.Should( ).Be(currentRowCount + 2); }
public async Task Insert_Select_RowsAreInserted( ) { await SqlScripts.InitDbAsync( ); using var connection = new MemoryDbConnection( ); connection.Execute("INSERT INTO TextTable ([Text]) SELECT [Name] FROM application_action WHERE [Order] = 2"); var texts = connection.Query <TextDto>($"SELECT [Text] FROM TextTable").ToList( ); texts.Count.Should( ).Be(3); }
public async Task Call_uspSelectApplications_ReturnsAllRows( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); await connection.ExecuteAsync(_SqlCreateUspSelectApplications); var applications = await connection.QueryAsync <ApplicationDto>("uspSelectApplications", commandType : CommandType.StoredProcedure); applications.Count( ).Should( ).Be(3); }
public async Task ExecuteCommandParameter_uspSelectApplicationById_ReturnsSingleRows( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); await connection.ExecuteAsync(_SqlCreateUspSelectApplicationById); var applications = await connection.QueryAsync <ApplicationDto>("EXECUTE uspSelectApplicationById @id", new { id = 2 }); applications.Count( ).Should( ).Be(1); applications.Single( ).Id.Should( ).Be(2); }
public async Task Call_uspSelectApplicationById_ReturnsSingleRows( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); await connection.ExecuteAsync(_SqlCreateUspSelectApplicationById); var applications = await connection.QueryAsync <ApplicationDto>("uspSelectApplicationById", new { id = 2 }, commandType : CommandType.StoredProcedure); applications.Count( ).Should( ).Be(1); applications.Single( ).Id.Should( ).Be(2); }
public async Task GetDate_Select_CurrentDateIsReturned( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); await connection.OpenAsync( ); var command = connection.CreateCommand( ); command.CommandText = "SELECT Id, GetDate() as CurrentDate FROM application_feature WHERE Id = 1"; await command.PrepareAsync( ); var reader = await command.ExecuteReaderAsync(); while (await reader.ReadAsync()) { reader["Id"].Should( ).Be(1); reader.GetDateTime(1).Should( ).BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(5)); } }
public async Task Transaction_RollbackUpdate_NoDataIsCommitted( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); await connection.OpenAsync( ); var transaction = await connection.BeginTransactionAsync( ); await connection.ExecuteAsync(_SqlUpdateApplication, transaction); await transaction.RollbackAsync( ); var applications = await connection.QueryAsync <ApplicationDto>(_SqlSelectApplication); foreach (var application in applications) { application.Name.Should().Be("Name String"); } }
public async Task Snapshot_SaveRestoreUpdate_NoDataIsCommitted( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); var memoryDatabase = connection.GetMemoryDatabase( ); memoryDatabase.SaveSnapshot( ); await connection.OpenAsync( ); await connection.ExecuteAsync(_SqlUpdateApplication); memoryDatabase.RestoreSnapshot( ); var applications = await connection.QueryAsync <ApplicationDto>(_SqlSelectApplication); foreach (var application in applications) { application.Name.Should().Be("Name String"); } }
public async Task Transaction_Rollback_NoDataIsCommitted( ) { await SqlScripts.InitDbAsync( ); await using var connection = new MemoryDbConnection( ); var rows = connection.GetMemoryDatabase( ).Tables["dbo.application"].Rows; var currentRowCount = rows.Count; await connection.OpenAsync( ); var transaction = await connection.BeginTransactionAsync( ); await connection.ExecuteAsync(_SqlInsertApplication, new { Name = "Name string", User = "******", DefName = "DefName string" }, transaction); await connection.ExecuteAsync(_SqlInsertApplication, new { Name = "Name string", User = "******", DefName = "DefName string" }, transaction); await transaction.RollbackAsync( ); var currentRows = connection.GetMemoryDatabase( ).Tables["dbo.application"].Rows; currentRows.Count.Should( ).Be(currentRowCount); }
public async Task InitializeDb( ) { await SqlScripts.InitDbAsync( ); }
public void InitDb( ) { SqlScripts.InitNorthWindDatabase( ); }