blob: 2a8bb1fa8e597d12fd5bf96c1c3a5907fd09fb04 (
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.Threading.Tasks;
using DevHive.Data.Models;
using DevHive.Data.Repositories;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
namespace DevHive.Data.Tests
{
[TestFixture]
public class CommentRepositoryTests
{
private const string COMMENT_MESSAGE = "Comment message";
protected DevHiveContext Context { get; set; }
protected CommentRepository CommentRepository { get; set; }
#region Setups
[SetUp]
public void Setup()
{
var optionsBuilder = new DbContextOptionsBuilder<DevHiveContext>()
.UseInMemoryDatabase(databaseName: "DevHive_Test_Database");
this.Context = new DevHiveContext(optionsBuilder.Options);
CommentRepository = new CommentRepository(Context);
}
[TearDown]
public void TearDown()
{
this.Context.Database.EnsureDeleted();
}
#endregion
#region GetCommentByIssuerAndTimeCreatedAsync
[Test]
public async Task GetCommentByCreatorAndTimeCreatedAsync_ReturnsTheCorrectComment_IfItExists()
{
Comment comment = await this.AddEntity();
Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(comment.CreatorId, comment.TimeCreated);
Assert.AreEqual(comment.Id, resultComment.Id, "GetCommentByIssuerAndTimeCreatedAsync does not return the corect comment when it exists");
}
[Test]
public async Task GetPostByCreatorAndTimeCreatedAsync_ReturnsNull_IfThePostDoesNotExist()
{
Comment comment = await this.AddEntity();
Comment resultComment = await this.CommentRepository.GetCommentByIssuerAndTimeCreatedAsync(Guid.Empty, DateTime.Now);
Assert.IsNull(resultComment, "GetCommentByIssuerAndTimeCreatedAsync does not return null when the comment does not exist");
}
#endregion
#region DoesCommentExist
[Test]
public async Task DoesCommentExist_ReturnsTrue_WhenTheCommentExists()
{
Comment comment = await this.AddEntity();
bool result = await this.CommentRepository.DoesCommentExist(comment.Id);
Assert.IsTrue(result, "DoesCommentExist does not return true whenm the Comment exists");
}
[Test]
public async Task DoesCommentExist_ReturnsFalse_WhenTheCommentDoesNotExist()
{
bool result = await this.CommentRepository.DoesCommentExist(Guid.Empty);
Assert.IsFalse(result, "DoesCommentExist does not return false whenm the Comment" +
" does not exist");
}
#endregion
#region HelperMethods
private async Task<Comment> AddEntity(string name = COMMENT_MESSAGE)
{
Comment comment = new Comment
{
Message = COMMENT_MESSAGE,
CreatorId = Guid.NewGuid(),
TimeCreated = DateTime.Now
};
this.Context.Comments.Add(comment);
await this.Context.SaveChangesAsync();
return comment;
}
#endregion
}
}
|