Merge pull request 'DevPF' (#38) from DevPF into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #38
master
Pierre FERREIRA 2 years ago
commit 3e605c9fec

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_LoL", "EF_LoL\EF_LoL.csproj", "{1AF6FE09-1ABF-4C51-8EC6-D2938876AAD2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{1A0B75E2-ECCE-47F3-A8FB-79F48F76E9A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1AF6FE09-1ABF-4C51-8EC6-D2938876AAD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AF6FE09-1ABF-4C51-8EC6-D2938876AAD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AF6FE09-1ABF-4C51-8EC6-D2938876AAD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AF6FE09-1ABF-4C51-8EC6-D2938876AAD2}.Release|Any CPU.Build.0 = Release|Any CPU
{1A0B75E2-ECCE-47F3-A8FB-79F48F76E9A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A0B75E2-ECCE-47F3-A8FB-79F48F76E9A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A0B75E2-ECCE-47F3-A8FB-79F48F76E9A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A0B75E2-ECCE-47F3-A8FB-79F48F76E9A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1EA5AF67-3A7C-4B6B-BE39-837D683F5AB3}
EndGlobalSection
EndGlobal

@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EF_LoL
{
public class ChampionDBContext : DbContext
{
public ChampionDBContext()
{ }
public ChampionDBContext(DbContextOptions<ChampionDBContext> options)
: base(options)
{ }
//ChampionEntity champ1 = new ChampionEntity("Bob");
//ChampionEntity champ2 = new ChampionEntity("Fanta");
public DbSet<ChampionEntity> ChampionEntity { get; set; }
//protected override void OnConfiguring(DbContextOptionsBuilder options)
// => options.UseSqlite("Data Source= EF_LoL.MyDataBase.db");
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
options.UseSqlite("Data Source= EF_LoL.MyDataBase.db");
}
}
}
}

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
namespace EF_LoL
{
public class ChampionEntity
{
//dotnet ef database update --context ChampionDBContext --project EF_LoL
[Key]
public string Name
{
get => name;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
name = "Unknown";
return;
}
name = value;
}
}
private readonly string name = null!;
public string Bio
{
get => bio;
set
{
if (value == null)
{
bio = "";
return;
}
bio = value;
}
}
private string bio = "";
public string Icon { get; set; }
public ChampionEntity(string name, string icon = "", string bio = "")
{
Name = name;
Icon = icon;
Bio = bio;
///Characteristics = new ReadOnlyDictionary<string, int>(characteristics);
}
///public ReadOnlyDictionary<string, int> Characteristics { get; private set; }
///private readonly Dictionary<string, int> characteristics = new Dictionary<string, int>();
// creer table avec db context et db set de champion
// puis ajout d'un nouveau champion
// pour ajouté un attribut : supprimer nos migrations et nos db
public override bool Equals(object? obj)
{
if (ReferenceEquals(obj, null)) return false;
if (ReferenceEquals(obj, this)) return true;
if (GetType() != obj.GetType()) return false;
return Equals(obj as ChampionEntity);
}
public override int GetHashCode()
=> Name.GetHashCode() % 997;
public bool Equals(ChampionEntity? other)
=> Name.Equals(other?.Name);
public override string ToString()
{
StringBuilder sb = new StringBuilder($"{Name}");
if (!string.IsNullOrWhiteSpace(bio))
{
sb.AppendLine($"\t{bio}");
}
return sb.ToString();
}
///// Characteristique
////public void AddCharacteristics(params Tuple<string, int>[] someCharacteristics)
////{
//// foreach (var c in someCharacteristics)
//// {
//// characteristics[c.Item1] = c.Item2;
//// }
////}
////public bool RemoveCharacteristics(string label)
//// => characteristics.Remove(label);
////public int? this[string label]
////{
//// get
//// {
//// if (!characteristics.TryGetValue(label, out int value)) return null;
//// else return value;
//// }
//// set
//// {
//// if (!value.HasValue)
//// {
//// RemoveCharacteristics(label);
//// return;
//// }
//// characteristics[label] = value.Value;
//// }
////}
}
}

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -0,0 +1,42 @@
// <auto-generated />
using EF_LoL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EFLoL.Migrations
{
[DbContext(typeof(ChampionDBContext))]
[Migration("20230204093038_MyMigration")]
partial class MyMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EF_LoL.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("ChampionEntity");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EFLoL.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChampionEntity",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Bio = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChampionEntity", x => x.Name);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChampionEntity");
}
}
}

@ -0,0 +1,39 @@
// <auto-generated />
using EF_LoL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EFLoL.Migrations
{
[DbContext(typeof(ChampionDBContext))]
partial class ChampionDBContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EF_LoL.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("ChampionEntity");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,28 @@
// See https://aka.ms/new-console-template for more information
using EF_LoL;
Console.WriteLine("Hello, World!");
ChampionEntity chewie = new ChampionEntity("Chewbacca");
ChampionEntity yoda = new ChampionEntity ("Yoda");
ChampionEntity ewok = new ChampionEntity ("Ewok");
using (var context = new ChampionDBContext())
{
// Crée des Champion et les insère dans la base
Console.WriteLine("Creates and inserts new Champion");
context.ChampionEntity.Add(chewie);
context.ChampionEntity.Add(yoda);
context.ChampionEntity.Add(ewok);
context.SaveChanges();
}
using (var context = new ChampionDBContext())
{
foreach (var n in context.ChampionEntity)
{
Console.WriteLine($"{n.Name} - {n.Bio} [ {n.Icon} ]");
}
context.SaveChanges();
}

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EF_LoL\EF_LoL.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,45 @@
using EF_LoL;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Xunit;
namespace TestProject
{
public class UnitTest1
{
[Fact]
public void Test1()
{
var options = new DbContextOptionsBuilder<ChampionDBContext>()
.UseInMemoryDatabase(databaseName: "Add_Test_database")
.Options;
//prepares the database with one instance of the context
using (var context = new ChampionDBContext(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.ChampionEntity.Add(chewie);
context.ChampionEntity.Add(yoda);
context.ChampionEntity.Add(ewok);
context.SaveChanges();
}
//prepares the database with one instance of the context
using (var context = new ChampionDBContext(options))
{
Assert.Equal(3, context.ChampionEntity.Count());
Assert.Equal("Chewbacca", context.ChampionEntity.First().Name);
}
}
}
}

@ -0,0 +1 @@
global using Xunit;
Loading…
Cancel
Save