aboutsummaryrefslogtreecommitdiff
path: root/src/Data/DevHive.Data.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/DevHive.Data.Tests')
-rw-r--r--src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs24
-rw-r--r--src/Data/DevHive.Data.Tests/FeedRepository.Tests.cs15
-rw-r--r--src/Data/DevHive.Data.Tests/LenguageRepository.Tests.cs28
-rw-r--r--src/Data/DevHive.Data.Tests/PostRepository.Tests.cs35
-rw-r--r--src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs32
5 files changed, 63 insertions, 71 deletions
diff --git a/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs b/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
index 1fd8ad0..1e5390b 100644
--- a/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/CommentRepository.Tests.cs
@@ -11,10 +11,8 @@ namespace DevHive.Data.Tests
public class CommentRepositoryTests
{
private const string COMMENT_MESSAGE = "Comment message";
-
- protected DevHiveContext Context { get; set; }
-
- protected CommentRepository CommentRepository { get; set; }
+ private DevHiveContext _context;
+ private CommentRepository _commentRepository;
#region Setups
[SetUp]
@@ -23,15 +21,15 @@ namespace DevHive.Data.Tests
DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- this.CommentRepository = new CommentRepository(this.Context);
+ this._commentRepository = new CommentRepository(this._context);
}
[TearDown]
public void TearDown()
{
- _ = this.Context.Database.EnsureDeleted();
+ _ = this._context.Database.EnsureDeleted();
}
#endregion
@@ -41,7 +39,7 @@ namespace DevHive.Data.Tests
{
Comment comment = await this.AddEntity();
- Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(comment.Creator.Id, comment.TimeCreated);
+ Comment resultComment = await this._commentRepository.GetCommentByIssuerAndTimeCreatedAsync(comment.Creator.Id, comment.TimeCreated);
Assert.AreEqual(comment.Id, resultComment.Id, "GetCommentByIssuerAndTimeCreatedAsync does not return the corect comment when it exists");
}
@@ -51,7 +49,7 @@ namespace DevHive.Data.Tests
{
_ = await this.AddEntity();
- Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
+ Comment resultComment = await this._commentRepository.GetCommentByIssuerAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
Assert.IsNull(resultComment, "GetCommentByIssuerAndTimeCreatedAsync does not return null when the comment does not exist");
}
@@ -63,7 +61,7 @@ namespace DevHive.Data.Tests
{
Comment comment = await this.AddEntity();
- bool result = await this.CommentRepository.DoesCommentExist(comment.Id);
+ bool result = await this._commentRepository.DoesCommentExist(comment.Id);
Assert.IsTrue(result, "DoesCommentExist does not return true whenm the Comment exists");
}
@@ -71,7 +69,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesCommentExist_ReturnsFalse_WhenTheCommentDoesNotExist()
{
- bool result = await this.CommentRepository.DoesCommentExist(Guid.Empty);
+ bool result = await this._commentRepository.DoesCommentExist(Guid.Empty);
Assert.IsFalse(result, "DoesCommentExist does not return false whenm the Comment" +
" does not exist");
@@ -89,8 +87,8 @@ namespace DevHive.Data.Tests
TimeCreated = DateTime.Now
};
- _ = this.Context.Comments.Add(comment);
- _ = await this.Context.SaveChangesAsync();
+ _ = this._context.Comments.Add(comment);
+ _ = await this._context.SaveChangesAsync();
return comment;
}
diff --git a/src/Data/DevHive.Data.Tests/FeedRepository.Tests.cs b/src/Data/DevHive.Data.Tests/FeedRepository.Tests.cs
index eb5bce0..24fcb51 100644
--- a/src/Data/DevHive.Data.Tests/FeedRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/FeedRepository.Tests.cs
@@ -11,9 +11,8 @@ namespace DevHive.Data.Tests
[TestFixture]
public class FeedRepositoryTests
{
- protected DevHiveContext Context { get; set; }
-
- protected FeedRepository FeedRepository { get; set; }
+ private DevHiveContext _context;
+ private FeedRepository _feedRepository;
#region Setups
[SetUp]
@@ -22,15 +21,15 @@ namespace DevHive.Data.Tests
DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- this.FeedRepository = new FeedRepository(this.Context);
+ this._feedRepository = new FeedRepository(this._context);
}
[TearDown]
public void TearDown()
{
- _ = this.Context.Database.EnsureDeleted();
+ _ = this._context.Database.EnsureDeleted();
}
#endregion
@@ -50,7 +49,7 @@ namespace DevHive.Data.Tests
const int PAGE_NUMBER = 1;
const int PAGE_SIZE = 10;
- List<Post> resultList = await this.FeedRepository.GetFriendsPosts(friendsList, dateTime, PAGE_NUMBER, PAGE_SIZE);
+ List<Post> resultList = await this._feedRepository.GetFriendsPosts(friendsList, dateTime, PAGE_NUMBER, PAGE_SIZE);
Assert.GreaterOrEqual(2, resultList.Count, "GetFriendsPosts does not return all correct posts");
}
@@ -69,7 +68,7 @@ namespace DevHive.Data.Tests
const int PAGE_NUMBER = 1;
const int PAGE_SIZE = 10;
- List<Post> resultList = await this.FeedRepository.GetFriendsPosts(friendsList, dateTime, PAGE_NUMBER, PAGE_SIZE);
+ List<Post> resultList = await this._feedRepository.GetFriendsPosts(friendsList, dateTime, PAGE_NUMBER, PAGE_SIZE);
Assert.LessOrEqual(0, resultList.Count, "GetFriendsPosts does not return all correct posts");
}
diff --git a/src/Data/DevHive.Data.Tests/LenguageRepository.Tests.cs b/src/Data/DevHive.Data.Tests/LenguageRepository.Tests.cs
index 18d5959..b7bb2e3 100644
--- a/src/Data/DevHive.Data.Tests/LenguageRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/LenguageRepository.Tests.cs
@@ -12,8 +12,8 @@ namespace DevHive.Data.Tests
public class LenguageRepositoryTests
{
private const string LANGUAGE_NAME = "Language test name";
- protected DevHiveContext Context { get; set; }
- protected LanguageRepository LanguageRepository { get; set; }
+ private DevHiveContext _context;
+ private LanguageRepository _languageRepository;
#region Setups
[SetUp]
@@ -22,15 +22,15 @@ namespace DevHive.Data.Tests
DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- this.LanguageRepository = new LanguageRepository(this.Context);
+ this._languageRepository = new LanguageRepository(this._context);
}
[TearDown]
public void TearDown()
{
- _ = this.Context.Database.EnsureDeleted();
+ _ = this._context.Database.EnsureDeleted();
}
#endregion
@@ -40,9 +40,9 @@ namespace DevHive.Data.Tests
{
await this.AddEntity();
- Language language = this.Context.Languages.Where(x => x.Name == LANGUAGE_NAME).AsEnumerable().FirstOrDefault();
+ Language language = this._context.Languages.Where(x => x.Name == LANGUAGE_NAME).AsEnumerable().FirstOrDefault();
- Language languageResult = await this.LanguageRepository.GetByNameAsync(LANGUAGE_NAME);
+ Language languageResult = await this._languageRepository.GetByNameAsync(LANGUAGE_NAME);
Assert.AreEqual(language.Id, languageResult.Id);
}
@@ -50,7 +50,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task GetByNameAsync_ReturnsNull_IfTechnologyDoesNotExists()
{
- Language languageResult = await this.LanguageRepository.GetByNameAsync(LANGUAGE_NAME);
+ Language languageResult = await this._languageRepository.GetByNameAsync(LANGUAGE_NAME);
Assert.IsNull(languageResult);
}
@@ -61,11 +61,11 @@ namespace DevHive.Data.Tests
public async Task DoesLanguageExist_ReturnsTrue_IfIdExists()
{
await this.AddEntity();
- Language language = this.Context.Languages.Where(x => x.Name == LANGUAGE_NAME).AsEnumerable().FirstOrDefault();
+ Language language = this._context.Languages.Where(x => x.Name == LANGUAGE_NAME).AsEnumerable().FirstOrDefault();
Guid id = language.Id;
- bool result = await this.LanguageRepository.DoesLanguageExistAsync(id);
+ bool result = await this._languageRepository.DoesLanguageExistAsync(id);
Assert.IsTrue(result, "DoesLanguageExistAsync returns flase when language exists");
}
@@ -75,7 +75,7 @@ namespace DevHive.Data.Tests
{
Guid id = Guid.NewGuid();
- bool result = await this.LanguageRepository.DoesLanguageExistAsync(id);
+ bool result = await this._languageRepository.DoesLanguageExistAsync(id);
Assert.IsFalse(result, "DoesLanguageExistAsync returns true when language does not exist");
}
@@ -87,7 +87,7 @@ namespace DevHive.Data.Tests
{
await this.AddEntity();
- bool result = await this.LanguageRepository.DoesLanguageNameExistAsync(LANGUAGE_NAME);
+ bool result = await this._languageRepository.DoesLanguageNameExistAsync(LANGUAGE_NAME);
Assert.IsTrue(result, "DoesLanguageNameExists returns true when language name does not exist");
}
@@ -95,7 +95,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesLanguageNameExist_ReturnsFalse_IfLanguageDoesNotExists()
{
- bool result = await this.LanguageRepository.DoesLanguageNameExistAsync(LANGUAGE_NAME);
+ bool result = await this._languageRepository.DoesLanguageNameExistAsync(LANGUAGE_NAME);
Assert.False(result, "DoesTechnologyNameExistAsync returns true when language name does not exist");
}
@@ -109,7 +109,7 @@ namespace DevHive.Data.Tests
Name = name
};
- _ = await this.LanguageRepository.AddAsync(language);
+ _ = await this._languageRepository.AddAsync(language);
}
#endregion
}
diff --git a/src/Data/DevHive.Data.Tests/PostRepository.Tests.cs b/src/Data/DevHive.Data.Tests/PostRepository.Tests.cs
index c57844e..374befd 100644
--- a/src/Data/DevHive.Data.Tests/PostRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/PostRepository.Tests.cs
@@ -15,12 +15,9 @@ namespace DevHive.Data.Tests
public class PostRepositoryTests
{
private const string POST_MESSAGE = "Post test message";
-
- private DevHiveContext Context { get; set; }
-
- private Mock<IUserRepository> UserRepository { get; set; }
-
- private PostRepository PostRepository { get; set; }
+ private DevHiveContext _context;
+ private Mock<IUserRepository> _userRepository;
+ private PostRepository _postRepository;
#region Setups
[SetUp]
@@ -29,17 +26,17 @@ namespace DevHive.Data.Tests
DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- this.UserRepository = new Mock<IUserRepository>();
+ this._userRepository = new Mock<IUserRepository>();
- this.PostRepository = new PostRepository(this.Context, this.UserRepository.Object);
+ this._postRepository = new PostRepository(this._context, this._userRepository.Object);
}
[TearDown]
public void TearDown()
{
- _ = this.Context.Database.EnsureDeleted();
+ _ = this._context.Database.EnsureDeleted();
}
#endregion
@@ -64,7 +61,7 @@ namespace DevHive.Data.Tests
{
Post post = await this.AddEntity();
- Post resultTechnology = await this.PostRepository.GetByIdAsync(post.Id);
+ Post resultTechnology = await this._postRepository.GetByIdAsync(post.Id);
Assert.AreEqual(post.Id, resultTechnology.Id, "GetByIdAsync does not return the correct post");
}
@@ -72,7 +69,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task GetByIdAsync_ReturnsNull_IfTechnologyDoesNotExists()
{
- Post resultPost = await this.PostRepository.GetByIdAsync(Guid.NewGuid());
+ Post resultPost = await this._postRepository.GetByIdAsync(Guid.NewGuid());
Assert.IsNull(resultPost);
}
@@ -84,7 +81,7 @@ namespace DevHive.Data.Tests
{
Post post = await this.AddEntity();
- Post resultPost = await this.PostRepository.GetPostByCreatorAndTimeCreatedAsync(post.Creator.Id, post.TimeCreated);
+ Post resultPost = await this._postRepository.GetPostByCreatorAndTimeCreatedAsync(post.Creator.Id, post.TimeCreated);
Assert.AreEqual(post.Id, resultPost.Id, "GetPostByCreatorAndTimeCreatedAsync does not return the corect post when it exists");
}
@@ -94,7 +91,7 @@ namespace DevHive.Data.Tests
{
_ = await this.AddEntity();
- Post resutPost = await this.PostRepository.GetPostByCreatorAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
+ Post resutPost = await this._postRepository.GetPostByCreatorAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
Assert.IsNull(resutPost, "GetPostByCreatorAndTimeCreatedAsync does not return null when the post does not exist");
}
@@ -106,7 +103,7 @@ namespace DevHive.Data.Tests
{
Post post = await this.AddEntity();
- bool result = await this.PostRepository.DoesPostExist(post.Id);
+ bool result = await this._postRepository.DoesPostExist(post.Id);
Assert.IsTrue(result, "DoesPostExist does not return true whenm the Post exists");
}
@@ -114,7 +111,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesPostExist_ReturnsFalse_WhenThePostDoesNotExist()
{
- bool result = await this.PostRepository.DoesPostExist(Guid.Empty);
+ bool result = await this._postRepository.DoesPostExist(Guid.Empty);
Assert.IsFalse(result, "DoesPostExist does not return false whenm the Post does not exist");
}
@@ -124,7 +121,7 @@ namespace DevHive.Data.Tests
private async Task<Post> AddEntity()
{
User creator = new() { Id = Guid.NewGuid() };
- _ = await this.Context.Users.AddAsync(creator);
+ _ = await this._context.Users.AddAsync(creator);
Post post = new()
{
Message = POST_MESSAGE,
@@ -135,8 +132,8 @@ namespace DevHive.Data.Tests
Comments = new List<Comment>()
};
- _ = await this.Context.Posts.AddAsync(post);
- _ = await this.Context.SaveChangesAsync();
+ _ = await this._context.Posts.AddAsync(post);
+ _ = await this._context.SaveChangesAsync();
return post;
}
diff --git a/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs b/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
index f7fbacb..c12a38e 100644
--- a/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
+++ b/src/Data/DevHive.Data.Tests/TechnologyRepository.Tests.cs
@@ -12,10 +12,8 @@ namespace DevHive.Data.Tests
public class TechnologyRepositoryTests
{
private const string TECHNOLOGY_NAME = "Technology test name";
-
- protected DevHiveContext Context { get; set; }
-
- protected TechnologyRepository TechnologyRepository { get; set; }
+ private DevHiveContext _context;
+ private TechnologyRepository _technologyRepository;
#region Setups
[SetUp]
@@ -24,15 +22,15 @@ namespace DevHive.Data.Tests
DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
- this.Context = new DevHiveContext(optionsBuilder.Options);
+ this._context = new DevHiveContext(optionsBuilder.Options);
- this.TechnologyRepository = new TechnologyRepository(this.Context);
+ this._technologyRepository = new TechnologyRepository(this._context);
}
[TearDown]
public void TearDown()
{
- _ = this.Context.Database.EnsureDeleted();
+ _ = this._context.Database.EnsureDeleted();
}
#endregion
@@ -42,9 +40,9 @@ namespace DevHive.Data.Tests
{
await this.AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).AsEnumerable().FirstOrDefault();
+ Technology technology = this._context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).AsEnumerable().FirstOrDefault();
- Technology resultTechnology = await this.TechnologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
+ Technology resultTechnology = await this._technologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
Assert.AreEqual(technology.Id, resultTechnology.Id);
}
@@ -52,7 +50,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task GetByNameAsync_ReturnsNull_IfTechnologyDoesNotExists()
{
- Technology resultTechnology = await this.TechnologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
+ Technology resultTechnology = await this._technologyRepository.GetByNameAsync(TECHNOLOGY_NAME);
Assert.IsNull(resultTechnology);
}
@@ -63,10 +61,10 @@ namespace DevHive.Data.Tests
public async Task DoesTechnologyExist_ReturnsTrue_IfIdExists()
{
await this.AddEntity();
- Technology technology = this.Context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).AsEnumerable().FirstOrDefault();
+ Technology technology = this._context.Technologies.Where(x => x.Name == TECHNOLOGY_NAME).AsEnumerable().FirstOrDefault();
Guid id = technology.Id;
- bool result = await this.TechnologyRepository.DoesTechnologyExistAsync(id);
+ bool result = await this._technologyRepository.DoesTechnologyExistAsync(id);
Assert.IsTrue(result, "DoesTechnologyExistAsync returns flase hwen technology exists");
}
@@ -76,7 +74,7 @@ namespace DevHive.Data.Tests
{
Guid id = Guid.NewGuid();
- bool result = await this.TechnologyRepository.DoesTechnologyExistAsync(id);
+ bool result = await this._technologyRepository.DoesTechnologyExistAsync(id);
Assert.IsFalse(result, "DoesTechnologyExistAsync returns true when technology does not exist");
}
@@ -88,7 +86,7 @@ namespace DevHive.Data.Tests
{
await this.AddEntity();
- bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
+ bool result = await this._technologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
Assert.IsTrue(result, "DoesTechnologyNameExists returns true when technology name does not exist");
}
@@ -96,7 +94,7 @@ namespace DevHive.Data.Tests
[Test]
public async Task DoesTechnologyNameExist_ReturnsFalse_IfTechnologyDoesNotExists()
{
- bool result = await this.TechnologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
+ bool result = await this._technologyRepository.DoesTechnologyNameExistAsync(TECHNOLOGY_NAME);
Assert.False(result, "DoesTechnologyNameExistAsync returns true when technology name does not exist");
}
@@ -110,8 +108,8 @@ namespace DevHive.Data.Tests
Name = name
};
- _ = this.Context.Technologies.Add(technology);
- _ = await this.Context.SaveChangesAsync();
+ _ = this._context.Technologies.Add(technology);
+ _ = await this._context.SaveChangesAsync();
}
#endregion
}