protected void ProvisionSampleTable(bool withSeed = false) { var provisioner = new SqlProvisioner(provider); provisioner.AddStep("DROP TABLE IF EXISTS SampleEntities"); provisioner.AddStep("CREATE TABLE SampleEntities (Id INT NOT NULL DEFAULT 0, Name NVARCHAR(50), Description NVARCHAR(50))"); if (withSeed) { provisioner.AddStep("INSERT INTO SampleEntities VALUES (1, 'Test', 'Test Description')"); } provisioner.Provision(); }
public void CanProvisionFromString() { var provisioner = new SqlProvisioner(provider); provisioner.AddStep("DROP TABLE IF EXISTS Sample"); provisioner.AddStep("CREATE TABLE Sample (Id INT)"); provisioner.AddStep("INSERT INTO Sample VALUES (1)"); provisioner.Provision(); var db = provider.GetRequiredService <IDbConnection>(); var results = db.Query <int>("SELECT Id FROM Sample"); Assert.Single(results); Assert.Equal(1, results.First()); }
public async Task InsertionWithReturnedId() { var provisioner = new SqlProvisioner(provider); provisioner.AddStep("DROP TABLE IF EXISTS SampleEntities"); provisioner.AddStep("CREATE TABLE SampleEntities (Id INT NOT NULL IDENTITY(1, 1), Name NVARCHAR(50), Description NVARCHAR(50))"); provisioner.Provision(); var db = provider.GetRequiredService <IDbConnection>(); var repo = new Repository <SampleEntity>(db); var firstId = await repo.InsertAsync(new SampleEntity { Name = "Test 1", Description = "Test Description" }); var secondId = await repo.InsertAsync(new SampleEntity { Name = "Test 2", Description = "Test Description" }); Assert.Equal(1, firstId); Assert.Equal(2, secondId); }
public async Task CanInsertAndSelectFromRepositoryWithComplex() { var provisioner = new SqlProvisioner(provider); provisioner.AddStep("DROP TABLE IF EXISTS ComplexEntities"); provisioner.AddStep("CREATE TABLE ComplexEntities (RandomNameId INT NOT NULL DEFAULT 0, Name NVARCHAR(50), Description NVARCHAR(50))"); provisioner.Provision(); var db = provider.GetRequiredService <IDbConnection>(); var repo = new Repository <ComplexEntity>(db); await repo.InsertAsync(new ComplexEntity { RandomNameId = 0, Name = "Test", Description = "Test Description" }); var result = await repo.GetByIdAsync(0); Assert.NotNull(result); Assert.Equal(0, result.RandomNameId); Assert.Equal("Test", result.Name); Assert.Equal("Test Description", result.Description); }