JonPSmith / EfCore.TestSupport

Tools for helping in unit testing applications that use Entity Framework Core
https://www.thereformedprogrammer.net/new-features-for-unit-testing-your-entity-framework-core-5-code/
Other
352 stars 53 forks source link

Exception when same table name different schema #12

Closed h0wXD closed 5 years ago

h0wXD commented 5 years ago

Running this against our database we are getting an exception when running var hasErrors = comparer.CompareEfWithDb(context);

Exception:

System.ArgumentException: An item with the same key has already been added. Key: Job
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](List`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at TestSupport.EfSchemeCompare.Internal.Stage1Comparer.CompareModelToDatabase(DatabaseModel databaseModel)
   at TestSupport.EfSchemeCompare.CompareEfSql.FinishRestOfCompare(String configOrConnectionString, DbContext[] dbContexts, IDesignTimeServices designTimeService)
   at Gravity.EF.Test.DummyTestFixture.CompareViaContext()

After checking our database turns out we have two tables: HangFire.Job (external table) replication.Job (another external table)

Is there any way of ignoring some schemas? or specifying the default EF schema? Any suggestion on handling these are much appreciated.

Thanks for this amazing lib.

JonPSmith commented 5 years ago

Hi @h0wXD,

Yep. My bad - I took the Table name without the schema. I have just released a new version, 1.5.1, to NuGet with the fix in.