aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
diff options
context:
space:
mode:
authorVictor S <57849063+transtrike@users.noreply.github.com>2021-02-05 10:54:49 -0800
committerGitHub <noreply@github.com>2021-02-05 10:54:49 -0800
commitf4a70c6430db923af9fa9958a11c2d6612cb52cc (patch)
treeca0ea403ba5500df20bc8854ec50529a25c64245 /src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
parent1ccdefdac025b1b986ad2bd0bc3eda7505d6e7c3 (diff)
parent2269b5aa6c8d3dcb407c34fa256200bdc573585a (diff)
downloadDevHive-0.1.tar
DevHive-0.1.tar.gz
DevHive-0.1.zip
Merge pull request #18 from Team-Kaleidoscope/devv0.1
First stage: Complete. Awaiting further progress...
Diffstat (limited to 'src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs')
-rw-r--r--src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs145
1 files changed, 145 insertions, 0 deletions
diff --git a/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs b/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
new file mode 100644
index 0000000..6dacf0b
--- /dev/null
+++ b/src/DevHive.Tests/DevHive.Data.Tests/PostRepository.Tests.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using DevHive.Data.Interfaces.Repositories;
+using DevHive.Data.Models;
+using DevHive.Data.RelationModels;
+using DevHive.Data.Repositories;
+using Microsoft.EntityFrameworkCore;
+using Moq;
+using NUnit.Framework;
+
+namespace DevHive.Data.Tests
+{
+ [TestFixture]
+ 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; }
+
+ #region Setups
+ [SetUp]
+ public void Setup()
+ {
+ var optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
+ .UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
+
+ this.Context = new DevHiveContext(optionsBuilder.Options);
+
+ this.UserRepository = new Mock<IUserRepository>();
+
+ PostRepository = new PostRepository(Context, this.UserRepository.Object);
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ this.Context.Database.EnsureDeleted();
+ }
+ #endregion
+
+ #region AddNewPostToCreator
+ // [Test]
+ // public async Task AddNewPostToCreator_ReturnsTrue_WhenNewPostIsAddedToCreator()
+ // {
+ // Post post = await this.AddEntity();
+ // User user = new User { Id = Guid.NewGuid() };
+ //
+ // this.UserRepository.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(user));
+ //
+ // bool result = await this.PostRepository.AddNewPostToCreator(user.Id, post);
+ //
+ // Assert.IsTrue(result, "AddNewPostToCreator does not return true when Post Is Added To Creator successfully");
+ // }
+ #endregion
+
+ #region GetByIdAsync
+ [Test]
+ public async Task GetByNameAsync_ReturnsTheCorrectPost_IfItExists()
+ {
+ Post post = await AddEntity();
+
+ Post resultTechnology = await this.PostRepository.GetByIdAsync(post.Id);
+
+ Assert.AreEqual(post.Id, resultTechnology.Id, "GetByIdAsync does not return the correct post");
+ }
+
+ [Test]
+ public async Task GetByIdAsync_ReturnsNull_IfTechnologyDoesNotExists()
+ {
+ Post resultPost = await this.PostRepository.GetByIdAsync(Guid.NewGuid());
+
+ Assert.IsNull(resultPost);
+ }
+ #endregion
+
+ #region GetPostByCreatorAndTimeCreatedAsync
+ [Test]
+ public async Task GetPostByCreatorAndTimeCreatedAsync_ReturnsTheCorrectPost_IfItExists()
+ {
+ Post post = await this.AddEntity();
+
+ 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");
+ }
+
+ [Test]
+ public async Task GetPostByCreatorAndTimeCreatedAsync_ReturnsNull_IfThePostDoesNotExist()
+ {
+ Post post = await this.AddEntity();
+
+ Post resutPost = await this.PostRepository.GetPostByCreatorAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
+
+ Assert.IsNull(resutPost, "GetPostByCreatorAndTimeCreatedAsync does not return null when the post does not exist");
+ }
+ #endregion
+
+ #region DoesPostExist
+ [Test]
+ public async Task DoesPostExist_ReturnsTrue_WhenThePostExists()
+ {
+ Post post = await this.AddEntity();
+
+ bool result = await this.PostRepository.DoesPostExist(post.Id);
+
+ Assert.IsTrue(result, "DoesPostExist does not return true whenm the Post exists");
+ }
+
+ [Test]
+ public async Task DoesPostExist_ReturnsFalse_WhenThePostDoesNotExist()
+ {
+ bool result = await this.PostRepository.DoesPostExist(Guid.Empty);
+
+ Assert.IsFalse(result, "DoesPostExist does not return false whenm the Post does not exist");
+ }
+ #endregion
+
+ #region HelperMethods
+ private async Task<Post> AddEntity(string name = POST_MESSAGE)
+ {
+ User creator = new User { Id = Guid.NewGuid() };
+ await this.Context.Users.AddAsync(creator);
+ Post post = new Post
+ {
+ Message = POST_MESSAGE,
+ Id = Guid.NewGuid(),
+ Creator = creator,
+ TimeCreated = DateTime.Now,
+ Attachments = new List<PostAttachments> { new PostAttachments { FileUrl = "kur" }, new PostAttachments { FileUrl = "za" }, new PostAttachments { FileUrl = "tva" } },
+ Comments = new List<Comment>()
+ };
+
+ await this.Context.Posts.AddAsync(post);
+ await this.Context.SaveChangesAsync();
+
+ return post;
+ }
+ #endregion
+ }
+}