From 6ed4eb34bd9cc37f915f0b1cfa75b1fb587a83ec Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Thu, 6 May 2021 11:53:40 -0400 Subject: [PATCH] update references. move db scratch pad into test --- .../ApplicationServices.csproj | 4 +- DataLayer/DataLayer.csproj | 7 +- DataLayer/UNTESTED/LibationContext.cs | 7 +- DataLayer/UNTESTED/LibationContextFactory.cs | 5 +- DataLayer/UNTESTED/_scratch pad/ScratchPad.cs | 122 ------------------ DataLayer/appsettings.json | 10 +- FileManager/FileManager.csproj | 4 +- Libation.sln | 9 +- LibationLauncher/LibationLauncher.csproj | 2 +- .../InternalUtilities.Tests.csproj | 8 +- 10 files changed, 27 insertions(+), 151 deletions(-) delete mode 100644 DataLayer/UNTESTED/_scratch pad/ScratchPad.cs diff --git a/ApplicationServices/ApplicationServices.csproj b/ApplicationServices/ApplicationServices.csproj index 9cb3e0b9..e40dd992 100644 --- a/ApplicationServices/ApplicationServices.csproj +++ b/ApplicationServices/ApplicationServices.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/DataLayer/DataLayer.csproj b/DataLayer/DataLayer.csproj index 4fba0eb2..ef9ba5bc 100644 --- a/DataLayer/DataLayer.csproj +++ b/DataLayer/DataLayer.csproj @@ -12,13 +12,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/DataLayer/UNTESTED/LibationContext.cs b/DataLayer/UNTESTED/LibationContext.cs index 16a46627..db80bfce 100644 --- a/DataLayer/UNTESTED/LibationContext.cs +++ b/DataLayer/UNTESTED/LibationContext.cs @@ -56,9 +56,10 @@ namespace DataLayer modelBuilder.ApplyConfiguration(new SeriesBookConfig()); modelBuilder.ApplyConfiguration(new CategoryConfig()); - // seeds go here. examples in scratch pad - modelBuilder - .Entity() + // seeds go here. examples in Dinah.EntityFrameworkCore.Tests\DbContextFactoryExample.cs + + modelBuilder + .Entity() .HasData(Category.GetEmpty()); modelBuilder .Entity() diff --git a/DataLayer/UNTESTED/LibationContextFactory.cs b/DataLayer/UNTESTED/LibationContextFactory.cs index 73fad17f..abf9b656 100644 --- a/DataLayer/UNTESTED/LibationContextFactory.cs +++ b/DataLayer/UNTESTED/LibationContextFactory.cs @@ -6,9 +6,6 @@ namespace DataLayer public class LibationContextFactory : DesignTimeDbContextFactoryBase { protected override LibationContext CreateNewInstance(DbContextOptions options) => new LibationContext(options); - protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder - //.UseSqlServer - .UseSqlite - (connectionString); + protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder.UseSqlite(connectionString); } } diff --git a/DataLayer/UNTESTED/_scratch pad/ScratchPad.cs b/DataLayer/UNTESTED/_scratch pad/ScratchPad.cs deleted file mode 100644 index 05fae390..00000000 --- a/DataLayer/UNTESTED/_scratch pad/ScratchPad.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using Dinah.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; - -namespace _scratch_pad -{ - ////// to use this as a console, open properties and change from class library => console - //// DON'T FORGET TO REVERT IT - //public class Program - //{ - // public static void Main(string[] args) - // { - // var user = new Student() { Name = "Dinah Cheshire" }; - // var udi = new UserDef { UserDefId = 1, TagsRaw = "my,tags" }; - - // using var context = new MyTestContextDesignTimeDbContextFactory().Create(); - // context.Add(user); - // //context.Add(udi); - // context.Update(udi); - // context.SaveChanges(); - - // Console.WriteLine($"Student was saved in the database with id: {user.Id}"); - // } - //} - - public class MyTestContextDesignTimeDbContextFactory : DesignTimeDbContextFactoryBase - { - protected override MyTestContext CreateNewInstance(DbContextOptions options) => new MyTestContext(options); - protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder.UseSqlite(connectionString); - } - - public class MyTestContext : DbContext - { - // see DesignTimeDbContextFactoryBase for info about ctors and connection strings/OnConfiguring() - public MyTestContext(DbContextOptions options) : base(options) { } - - #region classes for OnModelCreating() seed example - class Blog - { - public int BlogId { get; set; } - public string Url { get; set; } - public System.Collections.Generic.ICollection Posts { get; set; } - } - class Post - { - public int PostId { get; set; } - public string Content { get; set; } - public string Title { get; set; } - public int BlogId { get; set; } - public Blog Blog { get; set; } - public Name AuthorName { get; set; } - } - class Name - { - public string First { get; set; } - public string Last { get; set; } - } - #endregion - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - - // config - modelBuilder.Entity(entity => entity.Property(e => e.Url).IsRequired()); - modelBuilder.Entity().OwnsOne(p => p.OrderDetails, cb => - { - cb.OwnsOne(c => c.BillingAddress); - cb.OwnsOne(c => c.ShippingAddress); - }); - modelBuilder.Entity(entity => - entity - .HasOne(d => d.Blog) - .WithMany(p => p.Posts) - .HasForeignKey("BlogId")); - - // BlogSeed - modelBuilder.Entity().HasData(new Blog { BlogId = 1, Url = "http://sample.com" }); - - // PostSeed - modelBuilder.Entity().HasData(new Post() { BlogId = 1, PostId = 1, Title = "First post", Content = "Test 1" }); - - // AnonymousPostSeed - modelBuilder.Entity().HasData(new { BlogId = 1, PostId = 2, Title = "Second post", Content = "Test 2" }); - - // OwnedTypeSeed - modelBuilder.Entity().OwnsOne(p => p.AuthorName).HasData( - new { PostId = 1, First = "Andriy", Last = "Svyryd" }, - new { PostId = 2, First = "Diego", Last = "Vega" }); - } - - public DbSet Students { get; set; } - public DbSet UserDefs { get; set; } - public DbSet Orders { get; set; } - } - - public class Student - { - public int Id { get; set; } - public string Name { get; set; } - } - public class UserDef - { - public int UserDefId { get; set; } - public string TagsRaw { get; set; } - } - - public class Order - { - public int Id { get; set; } - public OrderDetails OrderDetails { get; set; } - } - public class OrderDetails - { - public StreetAddress BillingAddress { get; set; } - public StreetAddress ShippingAddress { get; set; } - } - public class StreetAddress - { - public string Street { get; set; } - public string City { get; set; } - } -} diff --git a/DataLayer/appsettings.json b/DataLayer/appsettings.json index d2f5ab9c..c5fe32d4 100644 --- a/DataLayer/appsettings.json +++ b/DataLayer/appsettings.json @@ -1,14 +1,6 @@ { "ConnectionStrings": { - "LibationContext_sqlserver": "Server=(LocalDb)\\MSSQLLocalDB;Database=DataLayer.LibationContext;Integrated Security=true;", - "// this connection string is ONLY used for DataLayer's Migrations. this appsettings.json file is NOT used at all by application; it is overwritten": "", - "LibationContext": "Data Source=LibationContext.db;Foreign Keys=False;", - - "// sqlite notes": "", - "// absolute path example": "Data Source=C:/foo/bar/sample.db", - "// relative path example": "Data Source=sample.db", - "// on windows: sqlite paths accept windows and/or unix slashes": "", - "MyTestContext": "Data Source=%DESKTOP%/sample.db" + "LibationContext": "Data Source=LibationContext.db;Foreign Keys=False;" } } \ No newline at end of file diff --git a/FileManager/FileManager.csproj b/FileManager/FileManager.csproj index 54a5efe3..013ff58b 100644 --- a/FileManager/FileManager.csproj +++ b/FileManager/FileManager.csproj @@ -5,7 +5,9 @@ - + + + diff --git a/Libation.sln b/Libation.sln index 52c0673f..2afaee22 100644 --- a/Libation.sln +++ b/Libation.sln @@ -86,7 +86,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0 Libation Tests", "0 Libat EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InternalUtilities.Tests", "_Tests\InternalUtilities.Tests\InternalUtilities.Tests.csproj", "{8447C956-B03E-4F59-9DD4-877793B849D9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibationSearchEngine.Tests", "_Tests\LibationSearchEngine.Tests\LibationSearchEngine.Tests.csproj", "{C5B21768-C7C9-4FCB-AC1E-187B223D5A98}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibationSearchEngine.Tests", "_Tests\LibationSearchEngine.Tests\LibationSearchEngine.Tests.csproj", "{C5B21768-C7C9-4FCB-AC1E-187B223D5A98}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.EntityFrameworkCore.Tests", "..\Dinah.Core\_Tests\Dinah.EntityFrameworkCore.Tests\Dinah.EntityFrameworkCore.Tests.csproj", "{6F5131A0-09AE-4707-B82B-5E53CB74688E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -214,6 +216,10 @@ Global {C5B21768-C7C9-4FCB-AC1E-187B223D5A98}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5B21768-C7C9-4FCB-AC1E-187B223D5A98}.Release|Any CPU.ActiveCfg = Release|Any CPU {C5B21768-C7C9-4FCB-AC1E-187B223D5A98}.Release|Any CPU.Build.0 = Release|Any CPU + {6F5131A0-09AE-4707-B82B-5E53CB74688E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6F5131A0-09AE-4707-B82B-5E53CB74688E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6F5131A0-09AE-4707-B82B-5E53CB74688E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6F5131A0-09AE-4707-B82B-5E53CB74688E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -249,6 +255,7 @@ Global {F3B04A3A-20C8-4582-A54A-715AF6A5D859} = {8679CAC8-9164-4007-BDD2-F004810EDA14} {8447C956-B03E-4F59-9DD4-877793B849D9} = {67E66E82-5532-4440-AFB3-9FB1DF9DEF53} {C5B21768-C7C9-4FCB-AC1E-187B223D5A98} = {67E66E82-5532-4440-AFB3-9FB1DF9DEF53} + {6F5131A0-09AE-4707-B82B-5E53CB74688E} = {38E6C6D9-963A-4C5B-89F4-F2F14885ADFD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {615E00ED-BAEF-4E8E-A92A-9B82D87942A9} diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index a022d679..e97f27d2 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -21,7 +21,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/_Tests/InternalUtilities.Tests/InternalUtilities.Tests.csproj b/_Tests/InternalUtilities.Tests/InternalUtilities.Tests.csproj index 75c0e63c..b414257c 100644 --- a/_Tests/InternalUtilities.Tests/InternalUtilities.Tests.csproj +++ b/_Tests/InternalUtilities.Tests/InternalUtilities.Tests.csproj @@ -7,10 +7,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive