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
|
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DevHive.Data.Models;
using DevHive.Data.Repositories;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
namespace DevHive.Data.Tests
{
[TestFixture]
public class FeedRepositoryTests
{
protected DevHiveContext Context { get; set; }
protected FeedRepository FeedRepository { get; set; }
#region Setups
[SetUp]
public void Setup()
{
DbContextOptionsBuilder<DevHiveContext> optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
this.Context = new DevHiveContext(optionsBuilder.Options);
this.FeedRepository = new FeedRepository(this.Context);
}
[TearDown]
public void TearDown()
{
_ = this.Context.Database.EnsureDeleted();
}
#endregion
#region GetFriendsPosts
[Test]
public async Task GetFriendsPosts_ReturnsListOfPosts_WhenTheyExist()
{
User dummyUser = CreateDummyUser();
List<User> friendsList = new()
{
dummyUser
};
DateTime dateTime = new(3000, 05, 09, 9, 15, 0);
Console.WriteLine(dateTime.ToFileTime());
const int PAGE_NUMBER = 1;
const int PAGE_SIZE = 10;
List<Post> resultList = await this.FeedRepository.GetFriendsPosts(friendsList, dateTime, PAGE_NUMBER, PAGE_SIZE);
Assert.GreaterOrEqual(2, resultList.Count, "GetFriendsPosts does not return all correct posts");
}
[Test]
public async Task GetFriendsPosts_ReturnsNull_WhenNoSuitablePostsExist()
{
User dummyUser = CreateDummyUser();
List<User> friendsList = new()
{
dummyUser
};
DateTime dateTime = new(3000, 05, 09, 9, 15, 0);
const int PAGE_NUMBER = 1;
const int PAGE_SIZE = 10;
List<Post> resultList = await this.FeedRepository.GetFriendsPosts(friendsList, dateTime, PAGE_NUMBER, PAGE_SIZE);
Assert.LessOrEqual(0, resultList.Count, "GetFriendsPosts does not return all correct posts");
}
#endregion
#region HelperMethods
private static User CreateDummyUser()
{
HashSet<Role> roles = new()
{
new Role()
{
Id = Guid.NewGuid(),
Name = Role.DefaultRole
},
};
return new()
{
Id = Guid.NewGuid(),
UserName = "pioneer10",
FirstName = "Spas",
LastName = "Spasov",
Email = "abv@abv.bg",
Roles = roles
};
}
#endregion
}
}
|