diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/Properties/AssemblyInfo.cs b/Verax_API_EF/Verax_API_EF/TestsUnitaires/Properties/AssemblyInfo.cs deleted file mode 100644 index c3f33a7..0000000 --- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestsUnitaires")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TestsUnitaires")] -[assembly: AssemblyCopyright("Copyright © 2024")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("FF8AFA55-12FE-4856-A0A1-21344D366E12")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/Tests.cs b/Verax_API_EF/Verax_API_EF/TestsUnitaires/Tests.cs deleted file mode 100644 index f0b4fcb..0000000 --- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/Tests.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace TestsUnitaires -{ - public class Tests - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs b/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs new file mode 100644 index 0000000..fce41a3 --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs @@ -0,0 +1,103 @@ +using DbContextLib; +using Entities; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Xunit; + +namespace Tests; + +public class ArticleDB_Tests +{ + [Fact] + public void Add_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; + ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; + ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; + + context.Add(a1); + context.Add(a2); + context.Add(a3); + + context.SaveChanges(); + + Assert.Equal(3, context.ArticleSet.Count()); + Assert.Equal("Tom Smith", context.ArticleSet.First().Author); + connection.Close(); + } + } + + [Fact] + public void Modify_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; + ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; + ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; + context.Add(a1); + context.Add(a2); + context.Add(a3); + + context.SaveChanges(); + + var article = context.ArticleSet.First(a => a.Title.Equals("Breaking News Elisabeth 2 Died")); + article.Author = "Louis Laborie"; + context.SaveChanges(); + string persRemove = "Tom Smith"; + string persNew = "Louis Laborie"; + Assert.Equal(1, context.ArticleSet.Count(a => a.Author.Equals(persRemove))); + Assert.Equal(1, context.ArticleSet.Count(a => a.Author.Equals(persNew))); + connection.Close(); + } + } + + [Fact] + public void Remove_Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + using (var context = new LibraryContext(options)) + { + context.Database.EnsureCreated(); + ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" }; + ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" }; + ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" }; + + context.Add(a1); + context.Add(a2); + context.Add(a3); + + context.SaveChanges(); + + var article = context.ArticleSet.First(a => a.Title.Equals("Breaking News Elisabeth 2 Died")); + context.Remove(article); + context.SaveChanges(); + Assert.Equal(2, context.ArticleSet.Count()); + Assert.Equal(0, context.ArticleSet.Count(a => a.Title.Equals("Breaking News Elisabeth 2 Died"))); + connection.Close(); + } + } + +} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj b/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj index 6242cf4..d068dfd 100644 --- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj +++ b/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj @@ -1,66 +1,34 @@ - - - - - Debug - AnyCPU - {FF8AFA55-12FE-4856-A0A1-21344D366E12} - {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Properties - TestsUnitaires - TestsUnitaires - v4.8 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll - - - ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll - - - ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll - - - ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll - - - - - - - - + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/packages.config b/Verax_API_EF/Verax_API_EF/TestsUnitaires/packages.config deleted file mode 100644 index 69a4ec4..0000000 --- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/packages.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln b/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln index 2b1c5b3..6fdbffa 100644 --- a/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln +++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln @@ -1,24 +1,29 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Console_EF", "Test_Console_EF\Test_Console_EF.csproj", "{E27E2617-28A1-4675-B12B-89430582C05E}" +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34525.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Console_EF", "Test_Console_EF\Test_Console_EF.csproj", "{E27E2617-28A1-4675-B12B-89430582C05E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{40BD34D7-3F07-410A-BC04-2A5B09E758C0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{40BD34D7-3F07-410A-BC04-2A5B09E758C0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{F94BEE1F-302F-4654-8D85-AD41E0BACD03}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{F94BEE1F-302F-4654-8D85-AD41E0BACD03}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{F1B4BCE5-8DE7-4EFB-8BC1-D7E04EA75302}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_DbDataManager", "API_DbDataManager\API_DbDataManager.csproj", "{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_DbDataManager", "API_DbDataManager\API_DbDataManager.csproj", "{FBA0CF18-7488-4088-A7C5-5D2071D19CCB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Services", "API_Services\API_Services.csproj", "{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_Services", "API_Services\API_Services.csproj", "{4FB7D286-B583-44BC-BB79-4AE3058AFEDE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Model", "API_Model\API_Model.csproj", "{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_Model", "API_Model\API_Model.csproj", "{F09B566E-8D25-4D70-B9F0-99E6969D4D1F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Mapping", "API_Mapping\API_Mapping.csproj", "{BECFAD2C-E442-4300-8121-5AE6610B92DF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API_Mapping", "API_Mapping\API_Mapping.csproj", "{BECFAD2C-E442-4300-8121-5AE6610B92DF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{96FDB5DE-6707-4856-94CD-EFAF0C7CEB4B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{6AACD337-70A0-429B-979C-1B1E004BF2E0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{6AACD337-70A0-429B-979C-1B1E004BF2E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsUnitaires", "TestsUnitaires\TestsUnitaires.csproj", "{C1982C7C-AE09-4E96-B1A9-B6ADE4097452}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -66,5 +71,12 @@ Global {6AACD337-70A0-429B-979C-1B1E004BF2E0}.Debug|Any CPU.Build.0 = Debug|Any CPU {6AACD337-70A0-429B-979C-1B1E004BF2E0}.Release|Any CPU.ActiveCfg = Release|Any CPU {6AACD337-70A0-429B-979C-1B1E004BF2E0}.Release|Any CPU.Build.0 = Release|Any CPU + {C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection EndGlobal