Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support THEN RETURN clauses #443

Merged
merged 13 commits into from
Oct 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,13 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
}
}

internal class FullNameGenerator : ValueGenerator<string>
{
public override bool GeneratesTemporaryValues => false;

public override string Next(EntityEntry entry)
{
var singer = entry.Entity as Singers;
return (singer.FirstName ?? "") + " " + (singer.LastName ?? "");
}
}

/// <summary>
/// Base classes for test fixtures using the sample data model.
/// If TEST_SPANNER_DATABASE is set to an existing database, that database will be used and the
/// fixture assumes that the database already contains the sample data model. Any data in the
/// existing database will be deleted.
///
/// Otherwise a new database with the sample data model is automatically created and used. The
/// Otherwise, a new database with the sample data model is automatically created and used. The
/// generated database is dropped when the fixture is disposed.
/// </summary>
public class SpannerSampleFixture : SpannerFixtureBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,53 @@ private async Task InsertRandomSinger(bool disableInternalRetries)
}
await transaction.CommitAsync();
}

private async Task InsertRandomVenue(bool disableInternalRetries)
{
var rnd = new Random(Guid.NewGuid().GetHashCode());
using var context = new TestSpannerSampleDbContext(_fixture.DatabaseName);
using var transaction = await context.Database.BeginTransactionAsync();
if (disableInternalRetries)
{
transaction.DisableInternalRetries();
}

var rows = rnd.Next(1, 10);
for (var row = 0; row < rows; row++)
{
// This test assumes that this is random enough and that the id's
// will never overlap during a test run.
var id = Guid.NewGuid().ToString()[..10];
var prefix = id;
// Name contains the same value as the primary key with a random suffix.
// This makes it possible to search for a venue using the name and knowing
// that the search will at most deliver one row (and it will be the same row each time).
var name = prefix + "-" + rnd.Next(10000).ToString("D4");

// Yes, this is highly inefficient, but that is intentional. This
// will cause a large number of the transactions to be aborted.
var existing = await context
.Venues
.Where(v => EF.Functions.Like(v.Name, prefix + "%"))
.OrderBy(v => v.Name)
.FirstOrDefaultAsync();

if (existing == null)
{
context.Venues.Add(new Venues
{
Code = id,
Name = name,
Active = _fixture.RandomLong(rnd) % 2 == 1
});
}
else
{
existing.Name = name;
}
await context.SaveChangesAsync();
}
await transaction.CommitAsync();
}
}
}
Loading
Loading