Help needed - stuck with ModelBuilder issues (class properties...)

Feb 21 at 12:48 PM
I can't get effort to build the database in my unit-test project.
The Entity Configurations work fine with Entity Framework.

My abstract class 'EventBase' contains a ValueObject 'Duration'.
Entity Framework accepts this setup without problems.
The solution builds fine, but when I run or debug my unit test, it fails

System.InvalidOperationException: Sequence contains no matching element

When I test with a real database, the tables get created fine.
SoccerTraining (
  Id int,
  Description nvarchar(max),
  Start datetime,
  Duration_Seconds bigint)
But Effort doesn't seem to handle the class property properly. Am I overseeing something, or is this a bug?
public class Duration : IEquatable<Duration>
{
    public TimeSpan? Length { get; set; }
    public long? Seconds { get; set; }
    public bool Equals(Duration other);
    public static implicit operator TimeSpan? (Duration duration);
    public static implicit operator Duration(TimeSpan timeSpan);
    public static implicit operator Duration(TimeSpan? timeSpan);
}

public abstract class EventBase : EntityBase
{
    public DateTime Start { get; set; }
    public Duration Duration {get; set; }
    public RecurrenceRule RecurrenceRule { get; set; }
}

public class SoccerTraining : EventBase
{
    public string Description { get; set; }
    //---
}


public class SoccerTrainingMap : EntityMapBase<SoccerTraining>
{
    public SoccerTrainingMap()
    {
        ToTable("SoccerTrainings");
        Ignore(st => st.RecurrenceRule);
        //---
    }
}

public class DurationMap: EntityMapBase<Duration>
{
    public DurationMap()
    {
        Ignore(d => d.Length);
    }
}

public class EfSoccerModelDbContext : BaseDbContext, ISoccerModelDbContext
{
    //---
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        modelBuilder.Configurations.Add(new SoccerTrainingMap());
    }
}

public abstract class BaseDbContext : DbContext, IDbContext
{
    private readonly List<Object> _objectSetCache = new List<Object>();
    
    protected BaseDbContext(string connectionString) : base(connectionString)
    { }

    protected BaseDbContext(DbConnection connection) :base(connection, true)
    { }
    
    public IDbSet<TEntity> GetDbSet<TEntity>() where TEntity : class
    {
        var set = _objectSetCache.OfType<DbSet<TEntity>>().FirstOrDefault();
        if (set == null)
        {
            set = Set<TEntity>();
            _objectSetCache.Add(set);
        }
        return set;
    }
    
    //---
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Configurations.Add(new DurationMap());     
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }
}

public class EffortDbContext : EfSoccerModelDbContext
{
    public EffortDbContext(DbConnection dbConnection) : base(dbConnection)
    {
    }

    public void ProvideData<TEntity>(IEnumerable<TEntity> data) where TEntity : class
    {
        var dbSet = this.GetDbSet<TEntity>();
        foreach (var item in data)
        {
            dbSet.Add(item);
        }
    }
}

[TestClass]
public class SoccerTrainingUnitTests
{
    private EffortDbContext _dbContext;
    private ISoccerTrainingRepository _soccerTrainingRepository;

    [TestInitialize]
    public void MyTestInitialize()
    {
        Effort.Provider.EffortProviderConfiguration.RegisterProvider();
        var connection = Effort.DbConnectionFactory.CreateTransient();
        using (var dbContext = new EffortDbContext(connection))
        {
            dbContext.Database.Initialize(true);
            var soccerTrainings = GetSoccerTrainingData();
            dbContext.ProvideData(soccerTrainings);
            dbContext.SaveChanges();
        }
        
        _dbContext = = new EffortDbContext(connection);
        
        var dbContextFactoryMock = new Mock<IDbContextFactory>();
        dbContextFactoryMock.Setup(x => x.Create<ISoccerModelDbContext>()).Returns(_dbContext);

        _soccerTrainingRepository = new SoccerTrainingRepository(dbContextFactoryMock.Object);
    }
    
    [TestMethod]
    public void SoccerTrainingDomainService_BlahBlahBlah()
    {
        var soccerTrainings = _soccerTrainingRepository.GetAllSoccerTrainings();
        
        Assert.AreEqual(3, soccerTrainings.Count());
    }
    
    private IEnumerable<SoccerTraining> GetSoccerTrainingData()
    {
        yield return SoccerTraining.CreateRandom();
        yield return SoccerTraining.CreateRandom();
        yield return SoccerTraining.CreateRandom();
    }
}
Feb 21 at 12:50 PM
Edited Feb 21 at 12:51 PM
I've also tried adding the following line inside the using statement
dbContext.Database.Initialize(true);
and also outside the using statement
_dbContext.Database.Initialize(true);
Same issue persists.