|
|
|
@ -27,9 +27,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetUsers_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test10", Email = "example1@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test12", Email = "example2@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test13", Email = "example3@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetUsers(1, 2, UserOrderCriteria.None);
|
|
|
|
|
Assert.Equal(2, result.Count());
|
|
|
|
@ -38,9 +38,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test14", Email = "example4@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test15", Email = "example5@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test16", Email = "example6@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(1, 2, UserOrderCriteria.None);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -49,9 +49,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_BadPage_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test17", Email = "example7@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test18", Email = "example8@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test19", Email = "example9@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(-42, 2, UserOrderCriteria.None);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -60,9 +60,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_BadNumber_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test20", Email = "example10@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test21", Email = "example11@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test22", Email = "example12@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(1, -42, UserOrderCriteria.None);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -71,9 +71,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_OrderedById_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test23", Email = "example13@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test24", Email = "example14@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test51", Email = "example15@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(1, 2, UserOrderCriteria.ById);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -82,9 +82,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_OrderedByUsername_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test25", Email = "example16@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test26", Email = "example17@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test27", Email = "example18@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(1, 2, UserOrderCriteria.ByUsername);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -93,9 +93,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_OrderedByEmail_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test52", Email = "example45@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test53", Email = "example46@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test54", Email = "example17@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(1, 2, UserOrderCriteria.ByEmail);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -104,9 +104,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNotAdminUsers_OrderedByIsAdmin_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test28", Email = "example19@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test29", Email = "example20@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test30", Email = "example21@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNotAdminUsers(1, 2, UserOrderCriteria.ByIsAdmin);
|
|
|
|
|
Assert.Equal(1, result.Count());
|
|
|
|
@ -115,9 +115,9 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetNumberOfUsers_ReturnsCorrectNumberOfUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test3", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test31", Email = "example22@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test32", Email = "example23@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 3, Username = "Test33", Email = "example24@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetNumberOfUsers();
|
|
|
|
|
Assert.Equal(3, result);
|
|
|
|
@ -126,29 +126,29 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetUserById_ReturnsCorrectUser()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test34", Email = "example25@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test35", Email = "example26@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetUserById(1);
|
|
|
|
|
Assert.Equal("Test1", result.Username);
|
|
|
|
|
Assert.Equal("Test34", result.Username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetUserByUsername_ReturnsCorrectUser()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test36", Email = "example27@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test37", Email = "example28@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetUserByUsername("Test1");
|
|
|
|
|
var result = _userDataService.GetUserByUsername("Test36");
|
|
|
|
|
Assert.Equal(1, result.Id);
|
|
|
|
|
}
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetUserByEmail_ReturnsCorrectUser()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test38", Email = "example29@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test39", Email = "example30@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
var result = _userDataService.GetUserByEmail("example@email.com");
|
|
|
|
|
var result = _userDataService.GetUserByEmail("example29@email.com");
|
|
|
|
|
Assert.Equal(1, result.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -196,8 +196,8 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetUsers_WithBadPage_ReturnsClassicUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test40", Email = "example31@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test41", Email = "example32@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
var result = _userDataService.GetUsers(-1, 2, UserOrderCriteria.None);
|
|
|
|
@ -208,8 +208,8 @@ public class TestUserDataService
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetUsers_WithBadNumber_ReturnsClassicUsers()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test1", Email = "example@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test2", Email = "example@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test43", Email = "example33@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 2, Username = "Test44", Email = "example34@email.com", Password = "password", IsAdmin = false });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
var result = _userDataService.GetUsers(1, -42, UserOrderCriteria.None);
|
|
|
|
@ -253,6 +253,26 @@ public class TestUserDataService
|
|
|
|
|
|
|
|
|
|
Assert.False(result);
|
|
|
|
|
}
|
|
|
|
|
[Fact]
|
|
|
|
|
public void isEmailTaken_ReturnFalse()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test81", Email = "example81@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
var result = _userDataService.IsEmailTaken("example895@email.com");
|
|
|
|
|
|
|
|
|
|
Assert.False(result);
|
|
|
|
|
}
|
|
|
|
|
[Fact]
|
|
|
|
|
public void isEmailTaken_ReturnTrue()
|
|
|
|
|
{
|
|
|
|
|
_dbContext.Users.Add(new UserEntity() { Id = 1, Username = "Test82", Email = "example82@email.com", Password = "password", IsAdmin = true });
|
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
var result = _userDataService.IsEmailTaken("example82@email.com");
|
|
|
|
|
|
|
|
|
|
Assert.True(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DeleteUserByUsername_WithoutExisting_ReturnsFalse()
|
|
|
|
|