diff --git a/LuminousSales/Business/Business/Sales/ProductController.cs b/LuminousSales/Business/Business/Sales/ProductController.cs
index c3228d7..69e951c 100644
--- a/LuminousSales/Business/Business/Sales/ProductController.cs
+++ b/LuminousSales/Business/Business/Sales/ProductController.cs
@@ -44,7 +44,7 @@ namespace Business.Business.Sales
/// Gets All Roles
///
///
- /// Requires no special roles
+ /// Requires no special roles.
///
///
/// Returns a ICollection of all roles.
@@ -56,12 +56,13 @@ namespace Business.Business.Sales
}
///
- /// Searches the role by given Id
+ /// Searches the role by given Id.
///
+ ///
+ /// Requires no special roles.
+ ///
///
/// Returns an object of the role with the given Id.
- ///
- /// Requires no special roles
///
public Product Get(int id)
@@ -80,10 +81,11 @@ namespace Business.Business.Sales
///
/// Searches the role by given name
///
+ ///
+ /// Requires no special roles.
+ ///
///
/// Returns an object of the role with the given name.
- ///
- /// Requires no special roles
///
public Product Get(string name)
@@ -102,10 +104,11 @@ namespace Business.Business.Sales
///
/// Searches the role by a given substring
///
+ ///
+ /// Requires no special roles.
+ ///
///
/// Returns an ICollection of all roles that contain the given substring in their name.
- ///
- /// Requires no special roles
///
public ICollection GetByApproximateName(string name)
diff --git a/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs b/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs
index b52a432..7e25ce0 100644
--- a/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs
+++ b/LuminousSales/Business/Business/UserManagment/Controllers/RoleController.cs
@@ -51,14 +51,17 @@ namespace Business.Business.UserManagment.Controllers
this.context = context;
this.currentUser = currentUser;
}
-
+
///
/// Creates the roles
///
///
+ /// Requires no special roles. Not even an registered user.
+ ///
+ ///
/// Almost every method of each class checks if the user has suffficient roles for the task
///
-
+
public void CreateInitialRoles()
{
var Cashier = new Role("Cashier");
diff --git a/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs b/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs
index e9462d0..9f35f86 100644
--- a/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs
+++ b/LuminousSales/Business/Business/UserManagment/Controllers/UserController.cs
@@ -161,10 +161,13 @@ namespace Business.Business.UserManagment
/// Checks if the password is valid
///
///
- /// Password is used to log in the user
+ /// Requires no special roles.
+ ///
+ ///
+ /// Password is used to log in the user.
///
///
- /// Returns an object of the found user
+ /// Returns an object of the found user.
///
public User ValidatePassword(string password)
@@ -181,7 +184,10 @@ namespace Business.Business.UserManagment
/// Registers an user
///
///
- /// Used for the creation of the initial user, so it assigns admin role by default
+ /// Requires no special roles.
+ ///
+ ///
+ /// Used for the creation of the initial user, so it assigns admin role by default.
///
public void RegisterItem(string name, string password)
diff --git a/LuminousSales/LuminousSales.sln b/LuminousSales/LuminousSales.sln
index da15b65..fd797a7 100644
--- a/LuminousSales/LuminousSales.sln
+++ b/LuminousSales/LuminousSales.sln
@@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Models\Data.csproj"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{E1661853-3081-4C40-8E68-C063B3BC88A4}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Display", "Display\Display.csproj", "{61E060C5-4360-4880-9ED7-6A139C988F0F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Display", "Display\Display.csproj", "{61E060C5-4360-4880-9ED7-6A139C988F0F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuminousTests", "LuminousTests\LuminousTests.csproj", "{8475489D-3593-43D0-A6E2-006A732B982A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +29,10 @@ Global
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61E060C5-4360-4880-9ED7-6A139C988F0F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8475489D-3593-43D0-A6E2-006A732B982A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8475489D-3593-43D0-A6E2-006A732B982A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8475489D-3593-43D0-A6E2-006A732B982A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8475489D-3593-43D0-A6E2-006A732B982A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/LuminousSales/LuminousTests/LuminousTests.csproj b/LuminousSales/LuminousTests/LuminousTests.csproj
new file mode 100644
index 0000000..a2310ab
--- /dev/null
+++ b/LuminousSales/LuminousTests/LuminousTests.csproj
@@ -0,0 +1,20 @@
+
+
+
+ netcoreapp3.1
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/LuminousSales/LuminousTests/UnitTest1.cs b/LuminousSales/LuminousTests/UnitTest1.cs
new file mode 100644
index 0000000..4adf9a9
--- /dev/null
+++ b/LuminousSales/LuminousTests/UnitTest1.cs
@@ -0,0 +1,61 @@
+using NUnit.Framework;
+using Moq;
+using Models.Models;
+using Microsoft.EntityFrameworkCore;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Models;
+using Business.Business.UserManagment;
+using Business.Business.UserManagment.Controllers;
+
+namespace LuminousUnitTests
+{
+ public class Tests
+ {
+ private UserController userctrl;
+ private RoleController rolectrl;
+ private IQueryable testUsers;
+ [SetUp]
+ public void Setup()
+ {
+ var mock = new Mock>();
+ var mocka = new Mock>();
+ testUsers = new List
+ {
+ new User(){ Name = "Admin", Password = "adm123", RoleId = 1},
+ new User(){ Name = "Goso", Password = "goso123", RoleId = 2},
+ new User(){ Name = "Pesho", Password = "peso123", RoleId = 3},
+ }.AsQueryable();
+ mock.As>().Setup(m => m.Provider).Returns(testUsers.Provider);
+ mock.As>().Setup(m => m.Expression).Returns(testUsers.Expression);
+ mock.As>().Setup(m => m.ElementType).Returns(testUsers.ElementType);
+ mock.As>().Setup(m => m.GetEnumerator()).Returns(testUsers.GetEnumerator());
+ var testContext = new Mock();
+ testContext.Setup(s => s.User).Returns(mock.Object);
+
+ userctrl = new UserController(testUsers.ToList()[0], testContext.Object);
+ }
+
+ [Test]
+ public void UsersController_GetAll()
+ {
+ List users = userctrl.GetAll().ToList();
+ List testUsersList = testUsers.ToList();
+ Assert.AreEqual(users.Count, testUsers.Count());
+ for (int i = 0; i < users.Count; i++)
+ {
+ Assert.AreEqual(users[i].Name, testUsersList[i].Name);
+ Assert.AreEqual(users[i].Password, testUsersList[i].Password);
+ Assert.AreEqual(users[i].RoleId, testUsersList[i].RoleId);
+ }
+ }
+ [Test]
+ public void UserController_AddItem()
+ {
+ userctrl.RegisterItem("Penka", "penka123", 3);
+ List users = userctrl.GetAll().ToList();
+ Assert.AreEqual(users.Count, 4);
+ }
+ }
+}
\ No newline at end of file
diff --git a/LuminousSales/Models/LuminousContext.cs b/LuminousSales/Models/LuminousContext.cs
index 20278c7..1fab72d 100644
--- a/LuminousSales/Models/LuminousContext.cs
+++ b/LuminousSales/Models/LuminousContext.cs
@@ -16,11 +16,11 @@ namespace Models
}
- public DbSet User { get; set; }
- public DbSet Role { get; set; }
- public DbSet Product { get; set; }
- public DbSet Deal { get; set; }
- public DbSet Stock { get; set; }
+ public virtual DbSet User { get; set; }
+ public virtual DbSet Role { get; set; }
+ public virtual DbSet Product { get; set; }
+ public virtual DbSet Deal { get; set; }
+ public virtual DbSet Stock { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{