diff --git a/API_SQLuedo/EntityFramework/LessonEntity.cs b/API_SQLuedo/EntityFramework/LessonEntity.cs index 902465e..bf6e499 100644 --- a/API_SQLuedo/EntityFramework/LessonEntity.cs +++ b/API_SQLuedo/EntityFramework/LessonEntity.cs @@ -6,25 +6,8 @@ namespace Entities; public class LessonEntity { public int Id { get; set; } - public string? Title { get; set; } - public string? LastPublisher { get; set; } + public string Title { get; set; } + public string LastPublisher { get; set; } public DateOnly? LastEdit { get; set; } public ICollection Content { get; set; } = new List(); - - public LessonEntity() { } - - public LessonEntity(int id, string title, string lastPublisher, DateOnly? lastEdit) - { - Id = id; - Title = title; - LastPublisher = lastPublisher; - LastEdit = lastEdit; - } - - public LessonEntity(string title, string lastPublisher, DateOnly? lastEdit) - { - Title = title; - LastPublisher = lastPublisher; - LastEdit = lastEdit; - } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/LessonDataService.cs b/API_SQLuedo/Shared/LessonDataService.cs index e37b67e..da7713c 100644 --- a/API_SQLuedo/Shared/LessonDataService.cs +++ b/API_SQLuedo/Shared/LessonDataService.cs @@ -35,7 +35,7 @@ public class LessonDataService : ILessonDataService break; } var lessons = query.ToList(); - return lessons.Select(s => s.FromEntityToDTO()); + return lessons.Select(s => s.FromEntityToDto()); } public LessonDTO GetLessonById(int id) @@ -46,7 +46,7 @@ public class LessonDataService : ILessonDataService throw new ArgumentException("Impossible de trouver la leçon", nameof(id)); } - return lessonEntity.FromEntityToDTO(); + return lessonEntity.FromEntityToDto(); } public LessonDTO GetLessonByTitle(string title) @@ -57,7 +57,7 @@ public class LessonDataService : ILessonDataService throw new ArgumentException("Impossible de trouver la leçon", nameof(title)); } - return lessonEntity.FromEntityToDTO(); + return lessonEntity.FromEntityToDto(); } public bool DeleteLesson(int id) @@ -85,7 +85,7 @@ public class LessonDataService : ILessonDataService updatingLesson.LastPublisher = lesson.LastPublisher; updatingLesson.LastEdit = lesson.LastEdit; DbContext.SaveChangesAsync(); - return updatingLesson.FromEntityToDTO(); + return updatingLesson.FromEntityToDto(); } public LessonDTO CreateLesson(string title, string lastPublisher, DateOnly? lastEdit) @@ -96,7 +96,7 @@ public class LessonDataService : ILessonDataService LastPublisher = lastPublisher, LastEdit = lastEdit, }; - DbContext.Lessons.Add(newLessonEntity.FromDTOToEntity()); + DbContext.Lessons.Add(newLessonEntity.FromDtoToEntity()); DbContext.SaveChangesAsync(); return newLessonEntity; } diff --git a/API_SQLuedo/Shared/Mapper/LessonMapper.cs b/API_SQLuedo/Shared/Mapper/LessonMapper.cs index 80fdcb7..68380e1 100644 --- a/API_SQLuedo/Shared/Mapper/LessonMapper.cs +++ b/API_SQLuedo/Shared/Mapper/LessonMapper.cs @@ -6,27 +6,39 @@ namespace Shared.Mapper; public static class LessonMapper { - public static LessonDTO FromModelToDTO(this Lesson model) + public static LessonDTO FromModelToDto(this Lesson model) { return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit); } - public static LessonDTO FromEntityToDTO(this LessonEntity model) + public static LessonDTO FromEntityToDto(this LessonEntity model) { return new LessonDTO(model.Id, model.Title, model.LastPublisher, model.LastEdit); } public static LessonEntity FromModelToEntity(this Lesson model) { - return new LessonEntity(model.Id, model.Title, model.LastPublisher, model.LastEdit); + return new LessonEntity + { + Id = model.Id, + Title = model.Title, + LastPublisher = model.LastPublisher, + LastEdit = model.LastEdit + }; } - public static LessonEntity FromDTOToEntity(this LessonDTO dto) + public static LessonEntity FromDtoToEntity(this LessonDTO dto) { - return new LessonEntity(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); + return new LessonEntity + { + Id = dto.Id, + Title = dto.Title, + LastPublisher = dto.LastPublisher, + LastEdit = dto.LastEdit + }; } - public static Lesson FromDTOToModel(this LessonDTO dto) + public static Lesson FromDtoToModel(this LessonDTO dto) { return new Lesson(dto.Id, dto.Title, dto.LastPublisher, dto.LastEdit); } diff --git a/API_SQLuedo/TestEF/EntitiesTests/TestLessonEntity.cs b/API_SQLuedo/TestEF/EntitiesTests/TestLessonEntity.cs index 42a02d1..d77278b 100644 --- a/API_SQLuedo/TestEF/EntitiesTests/TestLessonEntity.cs +++ b/API_SQLuedo/TestEF/EntitiesTests/TestLessonEntity.cs @@ -1,14 +1,13 @@ using Entities; -using Microsoft.VisualBasic; -namespace TestEF; +namespace TestEF.EntitiesTests; public class TestLessonEntity { - private const int _id = 42; - private const string _title = "Title"; - private const string _lastPublisher = "Last Publisher"; - private static DateOnly _lastEdit = new DateOnly(); + private const int Id = 42; + private const string Title = "Title"; + private const string LastPublisher = "Last Publisher"; + private static readonly DateOnly LastEdit = new (); [Fact] public void TestDefaultConstructor() @@ -19,24 +18,35 @@ public class TestLessonEntity Assert.Null(lesson.LastPublisher); Assert.Null(lesson.LastEdit); } - + [Fact] public void TestConstructorWithoutId() { - LessonEntity lesson = new LessonEntity(_title,_lastPublisher,_lastEdit); + LessonEntity lesson = new LessonEntity + { + Title = Title, + LastPublisher = LastPublisher, + LastEdit = LastEdit + }; Assert.Equal(0, lesson.Id); - Assert.Equal(_title,lesson.Title); - Assert.Equal(_lastPublisher,lesson.LastPublisher); - Assert.Equal(_lastEdit,lesson.LastEdit); + Assert.Equal(Title, lesson.Title); + Assert.Equal(LastPublisher, lesson.LastPublisher); + Assert.Equal(LastEdit, lesson.LastEdit); } - + [Fact] public void TestConstructorWithAllAttributes() { - LessonEntity lesson = new LessonEntity(_id,_title,_lastPublisher,_lastEdit); - Assert.Equal(_id, lesson.Id); - Assert.Equal(_title,lesson.Title); - Assert.Equal(_lastPublisher,lesson.LastPublisher); - Assert.Equal(_lastEdit,lesson.LastEdit); + LessonEntity lesson = new LessonEntity + { + Id = Id, + Title = Title, + LastPublisher = LastPublisher, + LastEdit = LastEdit + }; + Assert.Equal(Id, lesson.Id); + Assert.Equal(Title, lesson.Title); + Assert.Equal(LastPublisher, lesson.LastPublisher); + Assert.Equal(LastEdit, lesson.LastEdit); } } \ No newline at end of file