diff options
| author | Victor S <57849063+transtrike@users.noreply.github.com> | 2021-02-05 10:54:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-05 10:54:49 -0800 |
| commit | f4a70c6430db923af9fa9958a11c2d6612cb52cc (patch) | |
| tree | ca0ea403ba5500df20bc8854ec50529a25c64245 /src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs | |
| parent | 1ccdefdac025b1b986ad2bd0bc3eda7505d6e7c3 (diff) | |
| parent | 2269b5aa6c8d3dcb407c34fa256200bdc573585a (diff) | |
| download | DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.tar DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.tar.gz DevHive-f4a70c6430db923af9fa9958a11c2d6612cb52cc.zip | |
Merge pull request #18 from Team-Kaleidoscope/devv0.1
First stage: Complete. Awaiting further progress...
Diffstat (limited to 'src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs')
| -rw-r--r-- | src/DevHive.Tests/DevHive.Web.Tests/FeedController.Tests.cs | 98 |
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 + } +} |
