optimisation des TU
continuous-integration/drone/push Build is passing Details

master
PATRICK 1 year ago
parent f4130e659a
commit 042e954a08

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -10,6 +11,7 @@ namespace Entities
{
public int Id { get; set; }
public string Name { get; set; }
[ConcurrencyCheck]
public ICollection<UserEntity> Users { get; set; } = new List<UserEntity>();
public string toString()

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
@ -17,10 +18,15 @@ namespace Entities
public string NickName { get; set; }
public string? image { get; set; } = null;
public long GroupId { get; set; }
[ConcurrencyCheck]
public GroupEntity? Group { get; set; } = null;
public long RoleId { get; set; }
[ConcurrencyCheck]
public RoleEntity? Role { get; set; } = null!;
public Boolean ExtraTime { get; set; }
[ConcurrencyCheck]
public ICollection<VocabularyListEntity> VocabularyList { get; set; } = new List<VocabularyListEntity>();

@ -97,6 +97,7 @@ namespace StubbedContextLib
VocabularyList = null
});
}
public StubbedContext() { }

@ -25,6 +25,11 @@ namespace TU
Assert.IsNotNull(groups);
Assert.AreEqual(1, groups.Count);
Assert.AreEqual("informatics", groups[0].sector);
Assert.AreEqual(1, groups[0].year);
Assert.AreEqual(1, groups[0].Id);
Assert.AreEqual(1, groups[0].Num);
Assert.AreEqual(0, groups[0].VocabularyList.Count());
Assert.AreEqual(0, groups[0].Users.Count());
}
}
@ -48,6 +53,9 @@ namespace TU
Assert.AreEqual("medecin", group1.sector);
Assert.AreEqual(2, group1.year);
Assert.AreEqual(2, group1.Id);
Assert.AreEqual(0, group1.Num);
Assert.AreEqual(0, group1.VocabularyList.Count());
Assert.AreEqual(0, group1.Users.Count());
}
}
@ -62,8 +70,9 @@ namespace TU
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newBook = new GroupEntity { Id = 2, year = 2, sector = "medecin" };
var VocabularyList = new VocabularyListEntity { Id = 1, Name = "name1", Image="image", UserId=4 };
var user = new UserEntity { Id = 4, Name = "name1", UserName = "username1", image="image", NickName = "nickname1", ExtraTime = true, GroupId = 2, Password = "1234", Email = "", RoleId = 3 };
var newBook = new GroupEntity { Id = 2, year = 2, sector = "medecin", Users = [user], VocabularyList = [VocabularyList] };
await context.Groups.AddAsync(newBook);
await context.SaveChangesAsync();
@ -72,7 +81,11 @@ namespace TU
Assert.AreEqual("medecin", group1.sector);
Assert.AreEqual(2, group1.year);
Assert.AreEqual(2, group1.Id);
Assert.AreEqual(0, group1.Num);
Assert.AreEqual(1, group1.VocabularyList.Count());
Assert.AreEqual("name1", group1.VocabularyList.First().Name);
Assert.AreEqual(1, group1.Users.Count());
Assert.AreEqual("name1", group1.Users.First().Name);
}
}
@ -87,8 +100,9 @@ namespace TU
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newBook = new GroupEntity { Id = 2, year = 2, sector = "medecin" };
var VocabularyList = new VocabularyListEntity { Id = 1, Name = "name1", Image = "image", UserId = 4 };
var user = new UserEntity { Id = 4, Name = "name1", UserName = "username1", image = "image", NickName = "nickname1", ExtraTime = true, GroupId = 2, Password = "1234", Email = "", RoleId = 3 };
var newBook = new GroupEntity { Id = 2, year = 2, sector = "medecin", Users = [user], VocabularyList = [VocabularyList] };
await context.Groups.AddAsync(newBook);
await context.SaveChangesAsync();
@ -116,7 +130,7 @@ namespace TU
{
context.Database.EnsureCreated();
var newBook = new GroupEntity { Id = 2, year = 2, sector = "medecin" };
var newBook = new GroupEntity { Id = 2, year = 2, sector = "medecin", Num=1 };
await context.Groups.AddAsync(newBook);
await context.SaveChangesAsync();
@ -125,6 +139,7 @@ namespace TU
Assert.AreEqual("medecin", group1.sector);
Assert.AreEqual(2, group1.year);
Assert.AreEqual(2, group1.Id);
Assert.AreEqual(1, group1.Num);
group1.sector = "informatique";
group1.year = 3;

@ -20,15 +20,15 @@ namespace TU
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newLangue = new LangueEntity { name = "français" };
var vocab = new VocabularyEntity { word = "test", Langue = null };
var newLangue = new LangueEntity { name = "français", vocabularys=[vocab] };
await context.Langues.AddAsync(newLangue);
await context.SaveChangesAsync();
var langue = await context.Langues.FirstOrDefaultAsync(b => b.name == "français");
Assert.IsNotNull(langue);
Assert.AreEqual("français", langue.name);
Assert.IsNull(langue.vocabularys);
Assert.AreEqual(vocab, langue.vocabularys.First());
}
@ -94,47 +94,5 @@ namespace TU
Assert.AreEqual(2, group2.Id);
}
}
[TestMethod]
public async Task TestGetLangues()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<LibraryContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var langues = await context.Langues.ToListAsync();
Assert.IsNotNull(langues);
Assert.AreEqual(2, langues.Count);
Assert.AreEqual("English", langues[0].name);
Assert.AreEqual("French", langues[1].name);
}
}
[TestMethod]
public async Task TestGetLangue()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<LibraryContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newLangue = new LangueEntity { name = "francais" };
await context.Langues.AddAsync(newLangue);
await context.SaveChangesAsync();
var langue = await context.Langues.FirstOrDefaultAsync(b => b.name == "francais");
Assert.IsNotNull(langue);
Assert.AreEqual("francais", langue.name);
}
}
}
}

@ -9,46 +9,6 @@ namespace TU
[TestClass]
public class RoleTU
{
[TestMethod]
public async Task TestGetRoles()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<LibraryContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var roles = await context.Roles.ToListAsync();
Assert.IsNotNull(roles);
Assert.AreEqual(3, roles.Count);
Assert.AreEqual("Admin", roles[0].Name);
}
}
[TestMethod]
public async Task TestGetRole()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<LibraryContext>()
.UseSqlite(connection)
.Options;
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newRole = new RoleEntity { Id = 4, Name = "user" };
await context.Roles.AddAsync(newRole);
await context.SaveChangesAsync();
var role1 = await context.Roles.FirstOrDefaultAsync(b => b.Name == "user");
Assert.IsNotNull(role1);
Assert.AreEqual("user", role1.Name);
Assert.AreEqual(4, role1.Id);
}
}
[TestMethod]
public async Task TestAddRole()
{
@ -60,14 +20,15 @@ namespace TU
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newRole = new RoleEntity { Name = "user" };
var user = new UserEntity { Id = 1, Name = "name", UserName = "username", NickName = "nickname", ExtraTime = true, GroupId = 1, Password = "1234", Email = "" };
var newRole = new RoleEntity { Id=4, Name = "user" , Users = [user] };
await context.Roles.AddAsync(newRole);
await context.SaveChangesAsync();
var role = await context.Roles.FirstOrDefaultAsync(b => b.Name == "user");
Assert.IsNotNull(role);
Assert.AreEqual("user", role.Name);
Assert.AreEqual(user, role.Users.First());
}
}
[TestMethod]
@ -81,18 +42,23 @@ namespace TU
using (var context = new StubbedContext(options))
{
context.Database.EnsureCreated();
var newRole = new RoleEntity { Name = "user" };
var user = new UserEntity { Id = 4, Name = "name", UserName = "username", NickName = "nickname", ExtraTime = true, GroupId = 1, Password = "1234", Email = "", RoleId=5 };
var user1 = new UserEntity { Id = 5, Name = "name2", UserName = "username2", NickName = "nickname2", ExtraTime = true, GroupId = 2, Password = "1234", Email = "", RoleId=5 };
var newRole = new RoleEntity { Id=5,Name = "user" };
newRole.Users.Add(user);
await context.Roles.AddAsync(newRole);
await context.SaveChangesAsync();
var role = await context.Roles.FirstOrDefaultAsync(b => b.Name == "user");
Assert.AreEqual(newRole, role);
role.Name = "admin";
context.Roles.Update(role);
await context.SaveChangesAsync();
var role1 = await context.Roles.FirstOrDefaultAsync(b => b. Name == "admin");
Assert.IsNotNull(role1);
Assert.AreEqual("admin", role1.Name);
Assert.AreEqual(user, role1.Users.First());
}
}

Loading…
Cancel
Save