aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests/DevHive.Data.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Tests/DevHive.Data.Tests')
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs5
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/FeedRepository.Tests.cs9
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs5
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs22
4 files changed, 30 insertions, 11 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
index 2a8bb1f..9cbb43b 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/CommentRepository.Tests.cs
@@ -41,7 +41,7 @@ namespace DevHive.Data.Tests
{
Comment comment = await this.AddEntity();
- Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(comment.CreatorId, 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");
}
@@ -81,10 +81,11 @@ namespace DevHive.Data.Tests
#region HelperMethods
private async Task<Comment> AddEntity(string name = COMMENT_MESSAGE)
{
+ User creator = new User { Id = Guid.NewGuid() };
Comment comment = new Comment
{
Message = COMMENT_MESSAGE,
- CreatorId = Guid.NewGuid(),
+ Creator = creator,
TimeCreated = DateTime.Now
};
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/FeedRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/FeedRepository.Tests.cs
index e38b31c..62d6455 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/FeedRepository.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/FeedRepository.Tests.cs
@@ -44,8 +44,8 @@ namespace DevHive.Data.Tests
DateTime dateTime = new DateTime(3000, 05, 09, 9, 15, 0);
- Post dummyPost = this.CreateDummyPost(dummyUser.Id);
- Post anotherDummnyPost = this.CreateDummyPost(dummyUser.Id);
+ Post dummyPost = this.CreateDummyPost(dummyUser);
+ Post anotherDummnyPost = this.CreateDummyPost(dummyUser);
const int PAGE_NUMBER = 1;
const int PAGE_SIZE = 10;
@@ -96,16 +96,15 @@ namespace DevHive.Data.Tests
};
}
- private Post CreateDummyPost(Guid posterId)
+ private Post CreateDummyPost(User poster)
{
const string POST_MESSAGE = "random message";
Guid id = Guid.NewGuid();
-
Post post = new Post
{
Id = id,
Message = POST_MESSAGE,
- CreatorId = posterId
+ Creator = poster
};
this.Context.Posts.Add(post);
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
index 27b7c32..113780b 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
@@ -62,7 +62,7 @@ namespace DevHive.Data.Tests
{
Post post = await this.AddEntity();
- Post resultPost = await this.PostRepository.GetPostByCreatorAndTimeCreatedAsync(post.CreatorId, 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");
}
@@ -101,11 +101,12 @@ namespace DevHive.Data.Tests
#region HelperMethods
private async Task<Post> AddEntity(string name = POST_MESSAGE)
{
+ User creator = new User { Id = Guid.NewGuid() };
Post post = new Post
{
Message = POST_MESSAGE,
Id = Guid.NewGuid(),
- CreatorId = Guid.NewGuid(),
+ Creator = creator,
TimeCreated = DateTime.Now
};
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
index 6cc7b87..0d262f5 100644
--- a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
+++ b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs
@@ -60,6 +60,22 @@ namespace DevHive.Data.Tests
}
#endregion
+ #region EditAsync
+ [Test]
+ public async Task EditAsync_ReturnsTrue_WhenUserIsUpdatedSuccessfully()
+ {
+ User oldUser = this.CreateDummyUser();
+ this._context.Users.Add(oldUser);
+ await this._context.SaveChangesAsync();
+
+ oldUser.UserName = "SuperSecretUserName";
+ bool result = await this._userRepository.EditAsync(oldUser.Id, oldUser);
+
+ Assert.IsTrue(result, "EditAsync does not return true when User is updated successfully");
+ Assert.Fail("Docurshi drugite");
+ }
+ #endregion
+
#region GetByIdAsync
[Test]
public async Task GetByIdAsync_ReturnsTheUse_WhenItExists()
@@ -188,8 +204,10 @@ namespace DevHive.Data.Tests
{
User dummyUser = this.CreateDummyUser();
User anotherDummyUser = this.CreateAnotherDummyUser();
- HashSet<User> friends = new HashSet<User>();
- friends.Add(anotherDummyUser);
+ HashSet<User> friends = new HashSet<User>
+ {
+ anotherDummyUser
+ };
dummyUser.Friends = friends;
this._context.Users.Add(dummyUser);