Skip to content

Commit

Permalink
Enable optimistic concurrency tests
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
roji committed Jul 7, 2016
1 parent 9c8ce2e commit 8d21176
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class F1NpgsqlFixture : F1RelationalFixture<NpgsqlTestStore>
{
public static readonly string DatabaseName = "OptimisticConcurrencyTest";

private readonly IServiceProvider _serviceProvider;
readonly IServiceProvider _serviceProvider;

private readonly string _connectionString = NpgsqlTestStore.CreateConnectionString(DatabaseName);
readonly string _connectionString = NpgsqlTestStore.CreateConnectionString(DatabaseName);

public F1NpgsqlFixture()
{
Expand Down Expand Up @@ -61,5 +61,48 @@ public override F1Context CreateContext(NpgsqlTestStore testStore)
context.Database.UseTransaction(testStore.Transaction);
return context;
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Chassis>(b =>
{
b.Property<uint>("xmin")
.HasColumnType("xid")
.ValueGeneratedOnAddOrUpdate()
.IsConcurrencyToken();
});

modelBuilder.Entity<Driver>(b =>
{
b.Property<uint>("xmin")
.HasColumnType("xid")
.ValueGeneratedOnAddOrUpdate()
.IsConcurrencyToken();
});

modelBuilder.Entity<Engine>(b =>
{
b.Property(e => e.EngineSupplierId).IsConcurrencyToken();
b.Property(e => e.Name).IsConcurrencyToken();
});

modelBuilder.Entity<Sponsor>(b =>
{
b.Property<int?>(Sponsor.ClientTokenPropertyName)
.IsConcurrencyToken();
});

modelBuilder.Ignore<SponsorDetails>();

modelBuilder.Entity<Team>(b =>
{
b.Property<uint>("xmin")
.HasColumnType("xid")
.ValueGeneratedOnAddOrUpdate()
.IsConcurrencyToken();
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,43 @@

namespace Npgsql.EntityFrameworkCore.PostgreSQL.FunctionalTests
{
/*
public class OptimisticConcurrencyNpgsqlTest : OptimisticConcurrencyTestBase<NpgsqlTestStore, F1NpgsqlFixture>
{
public OptimisticConcurrencyNpgsqlTest(F1NpgsqlFixture fixture) : base(fixture) {}

const int StorePodiums = 20;

[Fact]
public override async Task Modifying_concurrency_token_only_is_noop()
{
uint firstVersion;
using (var context = CreateF1Context())
{
var driver = context.Drivers.Single(d => d.CarNumber == 1);
driver.Podiums = StorePodiums;
firstVersion = context.Entry(driver).Property<uint>("xmin").CurrentValue;
await context.SaveChangesAsync();
}

uint secondVersion;
using (var context = CreateF1Context())
{
var driver = context.Drivers.Single(d => d.CarNumber == 1);
Assert.NotEqual(firstVersion, context.Entry(driver).Property<uint>("xmin").CurrentValue);
Assert.Equal(StorePodiums, driver.Podiums);

secondVersion = context.Entry(driver).Property<uint>("xmin").CurrentValue;
context.Entry(driver).Property<uint>("xmin").CurrentValue = firstVersion;
await context.SaveChangesAsync();
}

using (var validationContext = CreateF1Context())
{
var driver = validationContext.Drivers.Single(d => d.CarNumber == 1);
Assert.Equal(secondVersion, validationContext.Entry(driver).Property<uint>("xmin").CurrentValue);
Assert.Equal(StorePodiums, driver.Podiums);
}
}

}
*/
}

0 comments on commit 8d21176

Please sign in to comment.