Refactoring: Added interfaces, custom exceptions, UserManager unit tests, dependency injection/inversion; Regex match search by date, keywords

This commit is contained in:
Dimitar Byalkov
2023-06-06 17:52:36 +02:00
parent 180b261d37
commit 53c42a35d8
43 changed files with 668 additions and 211 deletions

View File

@@ -5,7 +5,7 @@ using System.Text;
namespace Models
{
public class Announcement : GenericMessage, IVotable
public class Announcement : GenericMessage
{
public Announcement(int id, User author, string description, string title, DateTime publishDate, bool isImportant, bool isSticky) : base(id, author, description, title, publishDate)
{
@@ -31,16 +31,6 @@ namespace Models
{
get; set;
}
public void DownVote()
{
throw new NotImplementedException();
}
public void UpVote()
{
throw new NotImplementedException();
}
public override string ToString()
{
return $"{Title} ({PublishDate.ToString("g")} - {Author.Name})";

View File

@@ -5,7 +5,7 @@ using System.Text;
namespace Models
{
public class Comment : GenericMessage, IVotable
public class Comment : GenericMessage
{
public Comment(int id, User author, string description, string title, DateTime publishDate) : base(id, author, description, title, publishDate)
{
@@ -13,15 +13,6 @@ namespace Models
}
public List<Comment> Responses { get; set; }
public void DownVote()
{
throw new NotImplementedException();
}
public void UpVote()
{
throw new NotImplementedException();
}
public override string ToString()
{
return $"{Author.Name} ({PublishDate.ToString("g")}) - {Description.PadRight(100).Trim()}";

View File

@@ -7,11 +7,6 @@ namespace Models
{
public abstract class GenericMessage
{
private User author;
private string description;
private string title;
private DateTime publishDate;
protected GenericMessage(int id, User author, string description, string title, DateTime publishDate)
{
ID = id;
@@ -31,23 +26,19 @@ namespace Models
public User Author
{
get => author;
set => author = value;
get;set;
}
public string Description
{
get => description;
set => description = value;
get;set;
}
public string Title
{
get => title;
set => title = value;
get;set;
}
public DateTime PublishDate
{
get => publishDate;
set => publishDate = value;
get; set;
}
}
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Models
{
public interface IVotable
{
void UpVote()
{
throw new NotImplementedException();
}
void DownVote()
{
throw new NotImplementedException();
}
}
}

View File

@@ -9,10 +9,6 @@ namespace Models
{
public class User
{
private int id;
private string name;
private string password;
private UserRole role;
public User(int id, string name, string password, UserRole role)
{
@@ -23,29 +19,26 @@ namespace Models
}
public User()
{
}
public int ID
{
get; private set;
get; set;
}
public string Name
{
get => name;
set => name = value;
get; set;
}
[DataType(DataType.Password)]
public string Password
{
get => password;
set => password = value;
get; set;
}
public UserRole Role
{
get => role;
set => role = value;
get; set;
}
public override string ToString()
{