fix Tests
continuous-integration/drone/push Build is passing Details

pagination
Tony Fages 1 year ago
parent 9bf771b6ef
commit 80b429936f

@ -1,3 +1,4 @@
using API_Mapping;
using API_Services;
using Entities;
using Microsoft.AspNetCore.Mvc;
@ -24,7 +25,7 @@ public class ArticleUserController : ControllerBase
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), "");
try
{
var result = await _us.GetAllArticleUsers();
var result = (await _us.GetAllArticleUsers()).Select(u => u.ToDTO());
if (result == null)
{
return NoContent();

@ -39,8 +39,8 @@ app.MapControllers();
using var scoped = app.Services.CreateScope();
var libraryContext = scoped.ServiceProvider.GetService<LibraryContext>();
libraryContext.Database.EnsureCreated();
//libraryContext.Database.Migrate();
//libraryContext.Database.EnsureCreated();
libraryContext.Database.Migrate();
app.Run();

@ -1,6 +1,7 @@
using API_Services;
using DbContextLib;
using Entities;
using Microsoft.Extensions.Logging;
using Model;
namespace DbDataManager;
@ -14,11 +15,17 @@ public class DbManagerArticleUser : IArticleUserService
_context = context;
}
public async Task<IEnumerable<ArticleUserEntity?>> GetAllArticleUsers()
public async Task<IEnumerable<User?>> GetAllArticleUsers()
{
var entities = _context.ArticleUserSet.ToList();
if (entities == null) return await Task.FromResult<IEnumerable<ArticleUserEntity?>>(null);
return await Task.FromResult(entities.AsEnumerable());
List<UserEntity> users = new List<UserEntity>();
foreach( var articleUser in entities)
{
var user = _context.UserSet.FirstOrDefault(u => u.Pseudo.Equals(articleUser.UserEntityPseudo));
if (user != null) users.Add(user);
}
if (users == null) return await Task.FromResult<IEnumerable<User?>>(null);
return await Task.FromResult(users.Select(u => u.ToModel()).AsEnumerable());
}
public async Task<ArticleUserEntity?> GetArticleUser(string pseudo)

@ -1,10 +1,11 @@
using Entities;
using Model;
namespace API_Services;
public interface IArticleUserService
{
Task<IEnumerable<ArticleUserEntity>> GetAllArticleUsers();
Task<IEnumerable<User?>> GetAllArticleUsers();
Task<ArticleUserEntity?> GetArticleUser(string pseudo);
Task<ArticleUserEntity?> CreateArticleUser(ArticleUserEntity articleUser);

@ -0,0 +1,89 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class StubbedContext : LibraryContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ArticleEntity>().HasData(
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"
},
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"
},
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"
}
);
modelBuilder.Entity<UserEntity>().HasData(
new UserEntity
{
Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin"
},
new UserEntity
{
Nom = "Smith", Prenom = "Tom", Pseudo = "TomS", Mail = "tom@mail.com", Mdp = "1234",
Role = "User"
},
new UserEntity
{
Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator"
}
);
modelBuilder.Entity<ArticleUserEntity>().HasData(
new ArticleUserEntity
{
ArticleEntityId = 1,
UserEntityPseudo = "Sha"
},
new ArticleUserEntity
{
ArticleEntityId = 2,
UserEntityPseudo = "Sha"
},
new ArticleUserEntity
{
ArticleEntityId = 3,
UserEntityPseudo = "Sha"
},
new ArticleUserEntity
{
ArticleEntityId = 3,
UserEntityPseudo = "Sha"
},
new ArticleUserEntity
{
ArticleEntityId = 2,
UserEntityPseudo = "Sha"
}
);
}
}

@ -1,10 +1,13 @@
using Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace DbContextLib;
public class LibraryContext : DbContext
{
private static readonly StreamWriter LogFile = new StreamWriter("log.txt");
public LibraryContext()
: base()
{ }
@ -23,6 +26,7 @@ public class LibraryContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.LogTo( l => LogFile.WriteLine(l), LogLevel.Error).EnableDetailedErrors().EnableDetailedErrors();
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db");
@ -48,6 +52,7 @@ public class LibraryContext : DbContext
.WithMany(u => u.Forms)
.HasForeignKey(f => f.UserEntityPseudo);
/*
modelBuilder.Entity<ArticleEntity>().HasData(
new ArticleEntity
{
@ -155,5 +160,6 @@ public class LibraryContext : DbContext
UserEntityPseudo = "Sha"
}
);
*/
}
}

@ -21,13 +21,13 @@ public class ArticleDB_Tests
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" };
ArticleEntity a1 = new ArticleEntity { 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 { 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 { 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.ArticleSet.Add(a1);
context.ArticleSet.Add(a2);
context.ArticleSet.Add(a3);
context.SaveChanges();
@ -52,9 +52,9 @@ public class ArticleDB_Tests
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.ArticleSet.Add(a1);
context.ArticleSet.Add(a2);
context.ArticleSet.Add(a3);
context.SaveChanges();

@ -0,0 +1,15 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/projectSettingsUpdater.xml
/.idea.Verax_API_EF.iml
/contentModel.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# GitHub Copilot persisted chat sessions
/copilot/chatSessions

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
Loading…
Cancel
Save