Test de toutes les classes de Model
continuous-integration/drone/push Build is passing Details

pull/44/head
Johnny RATTON 1 year ago
parent 4ea53b072e
commit 0a2aa5ea92

@ -34,28 +34,22 @@
return $"{Id}\t{Username}\t{Email}\t{IsAdmin}";
}
public override bool Equals(object obj)
public bool Equals(UserDto? other)
{
if (object.ReferenceEquals(obj, null))
if (object.ReferenceEquals(other, null))
{
return false;
}
if (object.ReferenceEquals(this, obj))
if (object.ReferenceEquals(this, other))
{
return true;
}
if (this.GetType() != obj.GetType())
if (this.GetType() != other.GetType())
{
return false;
}
return this.Equals(obj as UserDto);
}
public bool Equals(UserDto other)
{
return (this.Id == other.Id);
}

@ -7,30 +7,30 @@ public class Solution
public string MurdererLastName { get; set; }
public string MurderPlace { get; set; }
public string MurderWeapon { get; set; }
public string Explanation { get; set; }
public string Explaination { get; set; }
public Solution()
{
}
public Solution(int ownerId, string murdererFirstName, string murdererLastName, string murderPlace,
string murderWeapon, string explanation)
string murderWeapon, string explaination)
{
OwnerId = ownerId;
MurdererFirstName = murdererFirstName;
MurdererLastName = murdererLastName;
MurderPlace = murderPlace;
MurderWeapon = murderWeapon;
Explanation = explanation;
Explaination = explaination;
}
public Solution(string murdererFirstName, string murdererLastName, string murderPlace, string murderWeapon,
string explanation)
string explaination)
{
MurdererFirstName = murdererFirstName;
MurdererLastName = murdererLastName;
MurderPlace = murderPlace;
MurderWeapon = murderWeapon;
Explanation = explanation;
Explaination = explaination;
}
}

@ -21,7 +21,7 @@ public static class SolutionMapper
public static SolutionDto FromModelToDto(this Solution model)
{
return new SolutionDto(model.OwnerId, model.MurdererFirstName, model.MurdererLastName, model.MurderPlace,
model.MurderWeapon, model.Explanation);
model.MurderWeapon, model.Explaination);
}
public static SolutionDto FromEntityToDto(this SolutionEntity entity)
@ -43,7 +43,7 @@ public static class SolutionMapper
MurdererLastName = model.MurdererLastName,
MurderPlace = model.MurderPlace,
MurderWeapon = model.MurderWeapon,
Explaination = model.Explanation
Explaination = model.Explaination
};
}

@ -42,5 +42,48 @@ namespace TestEF.Dto
Assert.Equal(Password, user.Password);
Assert.True(user.IsAdmin);
}
[Fact]
public void TestToString()
{
UserDto user = new UserDto(Id, Username, Password, Email, IsAdmin);
Assert.Equal($"{Id}\t{Username}\t{Email}\t{IsAdmin}", user.ToString());
}
[Fact]
public void TestEqualsWithSameAttributesValues()
{
UserDto user1 = new UserDto(Id, Username, Password, Email, IsAdmin);
UserDto user2 = new UserDto(Id, Username, Password, Email, IsAdmin);
Assert.True(user1.Equals(user2));
}
[Fact]
public void TestEqualsWithNullReference()
{
UserDto user = new UserDto(Id, Username, Password, Email, IsAdmin);
Assert.False(user.Equals(null));
}
[Fact]
public void TestEqualsWithSameReference()
{
UserDto user = new UserDto(Id, Username, Password, Email, IsAdmin);
Assert.True(user.Equals(user));
}
[Fact]
public void TestEqualsWithDifferentType()
{
UserDto user = new UserDto(Id, Username, Password, Email, IsAdmin);
Assert.False(user.Equals("Tests"));
}
[Fact]
public void TestGetHashCode()
{
UserDto user = new UserDto(Id, Username, Password, Email, IsAdmin);
Assert.Equal(Id, user.GetHashCode());
}
}
}

@ -52,7 +52,7 @@ namespace TestEF.Mapper
Assert.Equal(_murdererLastName, solutionMod.MurdererLastName);
Assert.Equal(_murderPlace, solutionMod.MurderPlace);
Assert.Equal(_murderWeapon, solutionMod.MurderWeapon);
Assert.Equal(_explanation, solutionMod.Explanation);
Assert.Equal(_explanation, solutionMod.Explaination);
}
@ -85,7 +85,7 @@ namespace TestEF.Mapper
Assert.Equal(_murdererLastName, solutionMod.MurdererLastName);
Assert.Equal(_murderPlace, solutionMod.MurderPlace);
Assert.Equal(_murderWeapon, solutionMod.MurderWeapon);
Assert.Equal(_explanation, solutionMod.Explanation);
Assert.Equal(_explanation, solutionMod.Explaination);
}

@ -0,0 +1,32 @@
using Model;
namespace TestEF.Model;
public class BlackListTest
{
[Fact]
void TestConstructorWithRightParameters()
{
BlackList blackList = new BlackList("example@email.com", DateOnly.FromDateTime(DateTime.Now));
Assert.Equal("example@email.com", blackList.Email);
Assert.Equal(DateOnly.FromDateTime(DateTime.Now), blackList.ExpirationDate);
}
[Fact]
void TestConstructorWithNullEmail()
{
Assert.Throws<ArgumentException>(() =>
{
BlackList blackList = new BlackList(null, DateOnly.FromDateTime(DateTime.Now));
});
}
[Fact]
void TestConstructorWithAnteriorDate()
{
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
BlackList blackList = new BlackList("example@email.com", DateOnly.FromDateTime(DateTime.Parse("2024/01/01 00:00:00")));
});
}
}

@ -0,0 +1,24 @@
using Model;
namespace TestEF.Model;
public class InquiryTableTest
{
[Fact]
void TestEmptyContructor()
{
InquiryTable inquiry = new InquiryTable();
Assert.Equal(0,inquiry.OwnerId);
Assert.Null(inquiry.ConnectionInfo);
Assert.Null(inquiry.DatabaseName);
}
[Fact]
void TestFullContructor()
{
InquiryTable inquiry = new InquiryTable(1,"Database","Connection");
Assert.Equal(1,inquiry.OwnerId);
Assert.Equal("Connection",inquiry.ConnectionInfo);
Assert.Equal("Database",inquiry.DatabaseName);
}
}

@ -0,0 +1,26 @@
using Model;
namespace TestEF.Model;
public class InquiryTest
{
[Fact]
void TestEmptyContructor()
{
Inquiry inquiry = new Inquiry();
Assert.Equal(0,inquiry.Id);
Assert.Null(inquiry.Title);
Assert.Null(inquiry.Description);
Assert.False(inquiry.IsUser);
}
[Fact]
void TestFullContructor()
{
Inquiry inquiry = new Inquiry(1,"Title","Description",true);
Assert.Equal(1,inquiry.Id);
Assert.Equal("Title",inquiry.Title);
Assert.Equal("Description",inquiry.Description);
Assert.True(inquiry.IsUser);
}
}

@ -0,0 +1,26 @@
using Model;
namespace TestEF.Model;
public class LessonTest
{
[Fact]
void TestConstructorWithoutId()
{
Lesson lesson = new Lesson("Title", "JohnDoe", DateOnly.FromDateTime(DateTime.Now));
Assert.Equal(0, lesson.Id);
Assert.Equal("Title", lesson.Title);
Assert.Equal("JohnDoe", lesson.LastPublisher);
Assert.Equal(DateOnly.FromDateTime(DateTime.Now), lesson.LastEdit);
}
[Fact]
void TestConstructorWithId()
{
Lesson lesson = new Lesson(42,"Title", "JohnDoe", DateOnly.FromDateTime(DateTime.Now));
Assert.Equal(42, lesson.Id);
Assert.Equal("Title", lesson.Title);
Assert.Equal("JohnDoe", lesson.LastPublisher);
Assert.Equal(DateOnly.FromDateTime(DateTime.Now), lesson.LastEdit);
}
}

@ -0,0 +1,36 @@
using Model;
namespace TestEF.Model;
public class NotepadTest
{
[Fact]
void TestEmptyConstructor()
{
Notepad notepad = new Notepad();
Assert.Equal(0, notepad.Id);
Assert.Equal(0, notepad.UserId);
Assert.Equal(0, notepad.InquiryId);
Assert.Null(notepad.Notes);
}
[Fact]
void TestConstructorWithoutId()
{
Notepad notepad = new Notepad(42,42,"Notes");
Assert.Equal(0, notepad.Id);
Assert.Equal(42, notepad.UserId);
Assert.Equal(42, notepad.InquiryId);
Assert.Equal("Notes",notepad.Notes);
}
[Fact]
void TestConstructorWithId()
{
Notepad notepad = new Notepad(42,42,42,"Notes");
Assert.Equal(42, notepad.Id);
Assert.Equal(42, notepad.UserId);
Assert.Equal(42, notepad.InquiryId);
Assert.Equal("Notes",notepad.Notes);
}
}

@ -0,0 +1,32 @@
using Model;
namespace TestEF.Model;
public class ParagraphTest
{
[Fact]
void TestConstructorWithoutId()
{
Paragraph paragraph = new Paragraph("Title", "Content","Info","Query","Comment");
Assert.Equal(0, paragraph.Id);
Assert.Equal(0, paragraph.LessonId);
Assert.Equal("Title", paragraph.ContentTitle);
Assert.Equal("Content", paragraph.ContentContent);
Assert.Equal("Info", paragraph.Info);
Assert.Equal("Query", paragraph.Query);
Assert.Equal("Comment", paragraph.Comment);
}
[Fact]
void TestConstructorWithId()
{
Paragraph paragraph = new Paragraph(42,"Title", "Content","Info","Query","Comment",42);
Assert.Equal(42, paragraph.Id);
Assert.Equal(42, paragraph.LessonId);
Assert.Equal("Title", paragraph.ContentTitle);
Assert.Equal("Content", paragraph.ContentContent);
Assert.Equal("Info", paragraph.Info);
Assert.Equal("Query", paragraph.Query);
Assert.Equal("Comment", paragraph.Comment);
}
}

@ -0,0 +1,42 @@
using Model;
namespace TestEF.Model;
public class SolutionTest
{
[Fact]
void TestEmptyConstructor()
{
Solution solution = new Solution();
Assert.Equal(0,solution.OwnerId);
Assert.Null(solution.MurdererFirstName);
Assert.Null(solution.MurdererLastName);
Assert.Null(solution.MurderPlace);
Assert.Null(solution.MurderWeapon);
Assert.Null(solution.Explaination);
}
[Fact]
void TestConstructorWithoutId()
{
Solution solution = new Solution("John","Doe","Bedroom","Knife","Because");
Assert.Equal(0,solution.OwnerId);
Assert.Equal("John",solution.MurdererFirstName);
Assert.Equal("Doe",solution.MurdererLastName);
Assert.Equal("Bedroom",solution.MurderPlace);
Assert.Equal("Knife",solution.MurderWeapon);
Assert.Equal("Because",solution.Explaination);
}
[Fact]
void TestConstructorWithId()
{
Solution solution = new Solution(42,"John","Doe","Bedroom","Knife","Because");
Assert.Equal(42,solution.OwnerId);
Assert.Equal("John",solution.MurdererFirstName);
Assert.Equal("Doe",solution.MurdererLastName);
Assert.Equal("Bedroom",solution.MurderPlace);
Assert.Equal("Knife",solution.MurderWeapon);
Assert.Equal("Because",solution.Explaination);
}
}

@ -0,0 +1,24 @@
using Model;
namespace TestEF.Model;
public class SuccessTest
{
[Fact]
void TestEmptyConstructor()
{
Success success = new Success();
Assert.Equal(0,success.UserId);
Assert.Equal(0,success.InquiryId);
Assert.False(success.IsFinished);
}
[Fact]
void TestFullConstructor()
{
Success success = new Success(42,42,true);
Assert.Equal(42,success.UserId);
Assert.Equal(42,success.InquiryId);
Assert.True(success.IsFinished);
}
}

@ -0,0 +1,28 @@
using Model;
namespace TestEF.Model;
public class UserTest
{
[Fact]
void TestEmptyConstructor()
{
User user = new User();
Assert.Equal(0,user.Id);
Assert.Null(user.Username);
Assert.Null(user.Email);
Assert.Null(user.Password);
Assert.False(user.IsAdmin);
}
[Fact]
void TestFullConstructor()
{
User user = new User(42,"Username","Password","Email",true);
Assert.Equal(42,user.Id);
Assert.Equal("Username",user.Username);
Assert.Equal("Email",user.Email);
Assert.Equal("Password",user.Password);
Assert.True(user.IsAdmin);
}
}
Loading…
Cancel
Save