diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..b773b1b --- /dev/null +++ b/.drone.yml @@ -0,0 +1,32 @@ +kind: pipeline +type: docker +name: EfCsLoL + +trigger: + event: + - push + +steps: +# docker image build + - name: docker-build-and-push + image: plugins/docker + settings: + dockerfile: Sources/API_LoL/Dockerfile + context: Sources/ + registry: hub.codefirst.iut.uca.fr + repo: hub.codefirst.iut.uca.fr/corentin.richard/entityframework_consodeservices_tp + + username: + from_secret: SECRET_REGISTRY_USERNAME + password: + from_secret: SECRET_REGISTRY_PASSWORD + +# docker test + - name: tests + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet test LeagueOfLegends.sln --no-restore + depends_on: [docker-build-and-push] + diff --git a/Sources/API_LoL/API_LoL.csproj b/Sources/API_LoL/API_LoL.csproj index 8902068..5ada54d 100644 --- a/Sources/API_LoL/API_LoL.csproj +++ b/Sources/API_LoL/API_LoL.csproj @@ -5,7 +5,7 @@ enable enable 1c8da478-3029-41d1-b936-853a71a8b812 - Windows + Linux diff --git a/Sources/API_LoL/Dockerfile b/Sources/API_LoL/Dockerfile index 5634a24..7ff2075 100644 --- a/Sources/API_LoL/Dockerfile +++ b/Sources/API_LoL/Dockerfile @@ -1,8 +1,5 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed. -#For more information, please see https://aka.ms/containercompat - FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base WORKDIR /app EXPOSE 80 @@ -11,6 +8,10 @@ EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["API_LoL/API_LoL.csproj", "API_LoL/"] +COPY ["DTO/DTO.csproj", "DTO/"] +COPY ["Model/Model.csproj", "Model/"] +COPY ["Shared/Shared.csproj", "Shared/"] +COPY ["StubLib/StubLib.csproj", "StubLib/"] RUN dotnet restore "API_LoL/API_LoL.csproj" COPY . . WORKDIR "/src/API_LoL" diff --git a/Sources/API_LoL/Dockerfile.original b/Sources/API_LoL/Dockerfile.original new file mode 100644 index 0000000..5634a24 --- /dev/null +++ b/Sources/API_LoL/Dockerfile.original @@ -0,0 +1,25 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed. +#For more information, please see https://aka.ms/containercompat + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["API_LoL/API_LoL.csproj", "API_LoL/"] +RUN dotnet restore "API_LoL/API_LoL.csproj" +COPY . . +WORKDIR "/src/API_LoL" +RUN dotnet build "API_LoL.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "API_LoL.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "API_LoL.dll"] \ No newline at end of file diff --git a/Sources/Api_UT/Api_UT.csproj b/Sources/Api_UT/Api_UT.csproj index 06ae488..efdc9e5 100644 --- a/Sources/Api_UT/Api_UT.csproj +++ b/Sources/Api_UT/Api_UT.csproj @@ -9,6 +9,7 @@ + diff --git a/Sources/Api_UT/EntityTest.cs b/Sources/Api_UT/EntityTest.cs deleted file mode 100644 index b2623fa..0000000 --- a/Sources/Api_UT/EntityTest.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using EntityFramework; -using System.Threading.Tasks; - - -namespace Api_UT -{ - [TestClass] - public class EntityTest - { - [TestMethod] - public void TestAdd() - { - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName: "Add_Test_database").Options; - - - //prepares the database with one instance of the context - using (var context = new LoLDbContext(options)) - { - - ChampionEntity chewie = new ChampionEntity("Chewbacca","bio","icon"); - ChampionEntity yoda = new ChampionEntity("Yoda", "bio", "icon"); - ChampionEntity ewok = new ChampionEntity("Ewok", "bio", "icon"); - - - Console.WriteLine("Creates and inserts new Champion for tests"); - context.Add(chewie); - context.Add(yoda); - context.Add(ewok); - context.SaveChanges(); - } - - //prepares the database with one instance of the context - using (var context = new LoLDbContext(options)) - { - Assert.AreEqual(3, context.Champions.Count()); - Assert.AreEqual("Chewbacca", context.Champions.First().name); - } - } - } -} diff --git a/Sources/Api_UT/UnitTest1.cs b/Sources/Api_UT/UnitTest1.cs index 5fba47b..4c934b2 100644 --- a/Sources/Api_UT/UnitTest1.cs +++ b/Sources/Api_UT/UnitTest1.cs @@ -1,5 +1,6 @@ using API_LoL.Controllers; using DTO; +using FluentAssertions; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Query; using Model; @@ -18,9 +19,16 @@ namespace Api_UT { List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") }; ChampionsController api = new ChampionsController(new StubData()); - IEnumerable a = ((OkObjectResult)await api.Get()).Value as IEnumerable; - Assert.IsNotNull(a); - Assert.IsTrue(list.SequenceEqual(a)); + IActionResult a = await api.Get(); + + /// utilisation du nuggets fluentAssertion + //Assert.IsNotNull(a); + a.Should().NotBeNull(); + //Assert.AreEqual(list,((OkObjectResult)a).Value); + var aObject = a as OkObjectResult; + aObject.Should().NotBeNull(); + var championresult = aObject.Value as IEnumerable; + list.Should().BeEquivalentTo(championresult); } [TestMethod] diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj index ac52241..dd77eab 100644 --- a/Sources/DTO/DTO.csproj +++ b/Sources/DTO/DTO.csproj @@ -8,6 +8,7 @@ + diff --git a/Sources/DTO/Program.cs b/Sources/DTO/Program.cs new file mode 100644 index 0000000..8133fe8 --- /dev/null +++ b/Sources/DTO/Program.cs @@ -0,0 +1,30 @@ +//using Model; +//using StubLib; + +//var builder = WebApplication.CreateBuilder(args); + +//// Add services to the container. + +//builder.Services.AddControllers(); +//// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +//builder.Services.AddEndpointsApiExplorer(); +//builder.Services.AddSwaggerGen(); + +//builder.Services.AddScoped(); + +//var app = builder.Build(); + +//// Configure the HTTP request pipeline. +//if (app.Environment.IsDevelopment()) +//{ +// app.UseSwagger(); +// app.UseSwaggerUI(); +//} + +//app.UseHttpsRedirection(); + +//app.UseAuthorization(); + +//app.MapControllers(); + +//app.Run(); diff --git a/Sources/EF_UT/EF_UT.csproj b/Sources/EF_UT/EF_UT.csproj new file mode 100644 index 0000000..eadf5a3 --- /dev/null +++ b/Sources/EF_UT/EF_UT.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + + + + + + diff --git a/Sources/EF_UT/EntityTest.cs b/Sources/EF_UT/EntityTest.cs new file mode 100644 index 0000000..45716d8 --- /dev/null +++ b/Sources/EF_UT/EntityTest.cs @@ -0,0 +1,87 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using EntityFramework; +using System.Threading.Tasks; + + +namespace EF_UT +{ + [TestClass] + public class EntityTest + { + [TestMethod] + public void TestAdd() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Add_Test_database").Options; + + + //prepares the database with one instance of the context + using (var context = new LoLDbContext(options)) + { + + ChampionEntity chewie = new ChampionEntity("Chewbacca"); + ChampionEntity yoda = new ChampionEntity("Yoda"); + ChampionEntity ewok = new ChampionEntity("Ewok"); + + + Console.WriteLine("Creates and inserts new Champion for tests"); + context.Add(chewie); + context.Add(yoda); + context.Add(ewok); + context.SaveChanges(); + } + + //prepares the database with one instance of the context + using (var context = new LoLDbContext(options)) + { + Assert.AreEqual(3, context.Champions.Count()); + Assert.AreEqual("Chewbacca", context.Champions.First().name); + } + } + [TestMethod] + public void TestUpdate() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Modify_Test_database") + .Options; + + //prepares the database with one instance of the context + using (var context = new LoLDbContext(options)) + { + ChampionEntity chewie = new ChampionEntity ("Chewbacca"); + ChampionEntity yoda = new ChampionEntity ("Yoda"); + ChampionEntity ewok = new ChampionEntity("Ewok"); + + context.Add(chewie); + context.Add(yoda); + context.Add(ewok); + context.SaveChanges(); + } + + //prepares the database with one instance of the context + using (var context = new LoLDbContext(options)) + { + string nameToFind = "ew"; + Assert.AreEqual(2, context.Champions.Where(n => n.name.ToLower().Contains(nameToFind)).Count()); + nameToFind = "ewo"; + Assert.AreEqual(1, context.Champions.Where(n => n.name.ToLower().Contains(nameToFind)).Count()); + var ewok = context.Champions.Where(n => n.name.ToLower().Contains(nameToFind)).First(); + ewok.name = "Wicket"; + context.SaveChanges(); + } + + //prepares the database with one instance of the context + using (var context = new LoLDbContext(options)) + { + string nameToFind = "ew"; + Assert.AreEqual(1, context.Champions.Where(n => n.name.ToLower().Contains(nameToFind)).Count()); + nameToFind = "wick"; + Assert.AreEqual(1, context.Champions.Where(n => n.name.ToLower().Contains(nameToFind)).Count()); + } + } + } +} diff --git a/Sources/EF_UT/Usings.cs b/Sources/EF_UT/Usings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/Sources/EF_UT/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/Sources/EntityFramework/EnumChampionClass.cs b/Sources/EntityFramework/EnumChampionClass.cs new file mode 100644 index 0000000..b8a039f --- /dev/null +++ b/Sources/EntityFramework/EnumChampionClass.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + public enum ChampionClass + { + Unknown, + Assassin, + Fighter, + Mage, + Marksman, + Support, + Tank + } +} diff --git a/Sources/EntityFramework/Migrations/20230222160559_myMigration.Designer.cs b/Sources/EntityFramework/Migrations/20230222160559_myMigration.Designer.cs deleted file mode 100644 index 75a6b54..0000000 --- a/Sources/EntityFramework/Migrations/20230222160559_myMigration.Designer.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDbContext))] - [Migration("20230222160559_myMigration")] - partial class myMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champion", (string)null); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/Migrations/20230222160559_myMigration.cs b/Sources/EntityFramework/Migrations/20230222160559_myMigration.cs deleted file mode 100644 index fc395ae..0000000 --- a/Sources/EntityFramework/Migrations/20230222160559_myMigration.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramework.Migrations -{ - /// - public partial class myMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champion", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), - Bio = table.Column(type: "string", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champion", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Champion"); - } - } -} diff --git a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs deleted file mode 100644 index 9c51e74..0000000 --- a/Sources/EntityFramework/Migrations/LoLDbContextModelSnapshot.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDbContext))] - partial class LoLDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champion", (string)null); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db deleted file mode 100644 index 393af3d..0000000 Binary files a/Sources/EntityFramework/champion.db and /dev/null differ diff --git a/Sources/EntityFramework/champion.db-shm b/Sources/EntityFramework/champion.db-shm deleted file mode 100644 index a58b0f7..0000000 Binary files a/Sources/EntityFramework/champion.db-shm and /dev/null differ diff --git a/Sources/EntityFramework/champion.db-wal b/Sources/EntityFramework/champion.db-wal deleted file mode 100644 index 347bec9..0000000 Binary files a/Sources/EntityFramework/champion.db-wal and /dev/null differ diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 76449b6..6415543 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -23,7 +23,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFramework", "EntityFr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csproj", "{20A1A7DC-1E93-4506-BD32-8597A5DADD7B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTestAPI", "ConsoleTestAPI\ConsoleTestAPI.csproj", "{04114DB7-8427-4141-930D-73E430DD1D99}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -63,10 +63,10 @@ Global {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Debug|Any CPU.Build.0 = Debug|Any CPU {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Release|Any CPU.ActiveCfg = Release|Any CPU {20A1A7DC-1E93-4506-BD32-8597A5DADD7B}.Release|Any CPU.Build.0 = Release|Any CPU - {04114DB7-8427-4141-930D-73E430DD1D99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {04114DB7-8427-4141-930D-73E430DD1D99}.Debug|Any CPU.Build.0 = Debug|Any CPU - {04114DB7-8427-4141-930D-73E430DD1D99}.Release|Any CPU.ActiveCfg = Release|Any CPU - {04114DB7-8427-4141-930D-73E430DD1D99}.Release|Any CPU.Build.0 = Release|Any CPU + {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -75,7 +75,7 @@ Global {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} {20A1A7DC-1E93-4506-BD32-8597A5DADD7B} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} - {04114DB7-8427-4141-930D-73E430DD1D99} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} + {74F469C3-A94A-4507-9DC7-7DBADCD18173} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}