aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-02-05 19:00:24 +0200
committertranstrike <transtrike@gmail.com>2021-02-05 19:00:24 +0200
commit75eeb4358e746d887677903052ed4bd5ca176f4d (patch)
tree9f9b9eb0103d61f488c08fa4b4b5f308ca9ab35a /src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs
parent51e157d1e1dc57ea2ba9c29b355fa7982a29bebe (diff)
parent4eb5ccdfc8ee4ac9795c48c701e565dbe2b641f9 (diff)
downloadDevHive-75eeb4358e746d887677903052ed4bd5ca176f4d.tar
DevHive-75eeb4358e746d887677903052ed4bd5ca176f4d.tar.gz
DevHive-75eeb4358e746d887677903052ed4bd5ca176f4d.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into dev
Diffstat (limited to 'src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs')
-rw-r--r--src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs b/src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs
new file mode 100644
index 0000000..01f67e5
--- /dev/null
+++ b/src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Services.Interfaces;
+using DevHive.Services.Models;
+using DevHive.Web.Controllers;
+using DevHive.Web.Models.Comment;
+using DevHive.Web.Models.Feed;
+using DevHive.Web.Models.Post;
+using Microsoft.AspNetCore.Mvc;
+using Moq;
+using NUnit.Framework;
+
+namespace DevHive.Web.Tests
+{
+ [TestFixture]
+ public class FeedControllerTests
+ {
+ private Mock<IFeedService> FeedServiceMock { get; set; }
+ private Mock<IMapper> MapperMock { get; set; }
+ private FeedController FeedController { get; set; }
+
+ #region SetUp
+ [SetUp]
+ public void SetUp()
+ {
+ this.FeedServiceMock = new Mock<IFeedService>();
+ this.MapperMock = new Mock<IMapper>();
+ this.FeedController = new FeedController(this.FeedServiceMock.Object, this.MapperMock.Object);
+ }
+ #endregion
+
+ #region GetPosts
+ [Test]
+ public async Task GetPosts_ReturnsOkObjectResultWithCorrectReadPageWebModel_WhenPostsExist()
+ {
+ GetPageWebModel getPageWebModel = new GetPageWebModel { };
+ GetPageServiceModel getPageServiceModel = new GetPageServiceModel { };
+ ReadPageServiceModel readPageServiceModel = new ReadPageServiceModel { };
+ ReadPageWebModel readPageWebModel = new ReadPageWebModel
+ {
+ Posts = new List<ReadPostWebModel>
+ {
+ new ReadPostWebModel(),
+ new ReadPostWebModel(),
+ new ReadPostWebModel()
+ }
+ };
+
+ this.FeedServiceMock.Setup(p => p.GetPage(It.IsAny<GetPageServiceModel>())).Returns(Task.FromResult(readPageServiceModel));
+ this.MapperMock.Setup(p => p.Map<GetPageServiceModel>(It.IsAny<GetPageWebModel>())).Returns(getPageServiceModel);
+ this.MapperMock.Setup(p => p.Map<ReadPageWebModel>(It.IsAny<ReadPageServiceModel>())).Returns(readPageWebModel);
+
+ IActionResult result = await this.FeedController.GetPosts(Guid.Empty, getPageWebModel);
+
+ Assert.IsInstanceOf<OkObjectResult>(result);
+
+ OkObjectResult okObjectResult = result as OkObjectResult;
+ ReadPageWebModel resultModel = okObjectResult.Value as Models.Comment.ReadPageWebModel;
+
+ Assert.AreEqual(3, resultModel.Posts.Count);
+ }
+ #endregion
+
+ #region GetUserPosts
+ [Test]
+ public async Task GetUserPosts_GetsPostsOfUser_WhenTheyExist()
+ {
+ GetPageWebModel getPageWebModel = new GetPageWebModel { };
+ GetPageServiceModel getPageServiceModel = new GetPageServiceModel { };
+ ReadPageServiceModel readPageServiceModel = new ReadPageServiceModel { };
+ ReadPageWebModel readPageWebModel = new ReadPageWebModel
+ {
+ Posts = new List<ReadPostWebModel>
+ {
+ new ReadPostWebModel(),
+ new ReadPostWebModel(),
+ new ReadPostWebModel()
+ }
+ };
+
+ this.FeedServiceMock.Setup(p => p.GetUserPage(It.IsAny<GetPageServiceModel>())).Returns(Task.FromResult(readPageServiceModel));
+ this.MapperMock.Setup(p => p.Map<GetPageServiceModel>(It.IsAny<GetPageWebModel>())).Returns(getPageServiceModel);
+ this.MapperMock.Setup(p => p.Map<ReadPageWebModel>(It.IsAny<ReadPageServiceModel>())).Returns(readPageWebModel);
+
+ IActionResult result = await this.FeedController.GetUserPosts(null, getPageWebModel);
+
+ Assert.IsInstanceOf<OkObjectResult>(result);
+
+ OkObjectResult okObjectResult = result as OkObjectResult;
+ ReadPageWebModel resultModel = okObjectResult.Value as Models.Comment.ReadPageWebModel;
+
+ Assert.AreEqual(3, resultModel.Posts.Count);
+ }
+ #endregion
+ }
+}