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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
//using System;
//using System.Collections.Generic;
//using System.Threading.Tasks;
//using AutoMapper;
//using DevHive.Data.Interfaces.Repositories;
//using DevHive.Data.Models;
//using DevHive.Services.Models;
//using DevHive.Services.Models.Post;
//using DevHive.Services.Services;
//using Moq;
//using NUnit.Framework;
//namespace DevHive.Services.Tests
//{
// [TestFixture]
// public class FeedServiceTests
// {
// private Mock<IFeedRepository> FeedRepositoryMock { get; set; }
// private Mock<IUserRepository> UserRepositoryMock { get; set; }
// private Mock<IMapper> MapperMock { get; set; }
// private FeedService FeedService { get; set; }
// #region SetUps
// [SetUp]
// public void Setup()
// {
// this.FeedRepositoryMock = new Mock<IFeedRepository>();
// this.UserRepositoryMock = new Mock<IUserRepository>();
// this.MapperMock = new Mock<IMapper>();
// this.FeedService = new FeedService(this.FeedRepositoryMock.Object, this.UserRepositoryMock.Object, this.MapperMock.Object);
// }
// #endregion
// #region GetPage
// [Test]
// public async Task GetPage_ReturnsReadPageServiceModel_WhenSuitablePostsExist()
// {
// GetPageServiceModel getPageServiceModel = new GetPageServiceModel
// {
// UserId = Guid.NewGuid()
// };
// User dummyUser = CreateDummyUser();
// User anotherDummyUser = CreateAnotherDummyUser();
// HashSet<User> friends = new HashSet<User>();
// friends.Add(anotherDummyUser);
// dummyUser.Friends = friends;
// List<Post> posts = new List<Post>
// {
// new Post{ Message = "Message"}
// };
// ReadPostServiceModel readPostServiceModel = new ReadPostServiceModel
// {
// PostId = Guid.NewGuid(),
// Message = "Message"
// };
// List<ReadPostServiceModel> readPostServiceModels = new List<ReadPostServiceModel>();
// readPostServiceModels.Add(readPostServiceModel);
// ReadPageServiceModel readPageServiceModel = new ReadPageServiceModel
// {
// Posts = readPostServiceModels
// };
// this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(dummyUser));
// this.FeedRepositoryMock.Setup(p => p.GetFriendsPosts(It.IsAny<List<User>>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>())).Returns(Task.FromResult(posts));
// this.MapperMock.Setup(p => p.Map<ReadPostServiceModel>(It.IsAny<Post>())).Returns(readPostServiceModel);
// ReadPageServiceModel result = await this.FeedService.GetPage(getPageServiceModel);
// Assert.GreaterOrEqual(1, result.Posts.Count, "GetPage does not correctly return the posts");
// }
// [Test]
// public void GetPage_ThrowsException_WhenNoSuitablePostsExist()
// {
// const string EXCEPTION_MESSAGE = "No friends of user have posted anything yet!";
// GetPageServiceModel getPageServiceModel = new GetPageServiceModel
// {
// UserId = Guid.NewGuid()
// };
// User dummyUser = CreateDummyUser();
// User anotherDummyUser = CreateAnotherDummyUser();
// HashSet<User> friends = new HashSet<User>();
// friends.Add(anotherDummyUser);
// dummyUser.Friends = friends;
// ReadPostServiceModel readPostServiceModel = new ReadPostServiceModel
// {
// PostId = Guid.NewGuid(),
// Message = "Message"
// };
// List<ReadPostServiceModel> readPostServiceModels = new List<ReadPostServiceModel>();
// readPostServiceModels.Add(readPostServiceModel);
// ReadPageServiceModel readPageServiceModel = new ReadPageServiceModel
// {
// Posts = readPostServiceModels
// };
// this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(dummyUser));
// this.FeedRepositoryMock.Setup(p => p.GetFriendsPosts(It.IsAny<List<User>>(), It.IsAny<DateTime>(), It.IsAny<int>(), It.IsAny<int>())).Returns(Task.FromResult(new List<Post>()));
// Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.FeedService.GetPage(getPageServiceModel));
// Assert.AreEqual(EXCEPTION_MESSAGE, ex.Message, "Wrong exception message");
// }
// [Test]
// public void GetPage_ThrowsException_WhenUserHasNoFriendsToGetPostsFrom()
// {
// const string EXCEPTION_MESSAGE = "User has no friends to get feed from!";
// GetPageServiceModel getPageServiceModel = new GetPageServiceModel
// {
// UserId = Guid.NewGuid()
// };
// User dummyUser = CreateDummyUser();
// this.UserRepositoryMock.Setup(p => p.GetByIdAsync(It.IsAny<Guid>())).Returns(Task.FromResult(dummyUser));
// Exception ex = Assert.ThrowsAsync<ArgumentException>(() => this.FeedService.GetPage(getPageServiceModel));
// Assert.AreEqual(EXCEPTION_MESSAGE, ex.Message, "Wrong exception message");
// }
// #endregion
// #region HelperMethods
// private User CreateDummyUser()
// {
// return new()
// {
// Id = Guid.NewGuid(),
// UserName = "dummyUser",
// FirstName = "Spas",
// LastName = "Spasov",
// Email = "abv@abv.bg",
// };
// }
// private User CreateAnotherDummyUser()
// {
// return new()
// {
// Id = Guid.NewGuid(),
// UserName = "anotherDummyUser",
// FirstName = "Alex",
// LastName = "Spiridonov",
// Email = "a_spiridonov@abv.bg",
// };
// }
// #endregion
// }
//}
|