blob: 01f67e5ecc028ab3ad1054db9922648e0a9ce2b2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
}
}
|