Skip to content

Commit fe86370

Browse files
committed
Add some additional tests
1 parent 68e97d4 commit fe86370

File tree

6 files changed

+206
-4
lines changed

6 files changed

+206
-4
lines changed

src/PokerTime.Application/Common/Models/UserStoryEstimation.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
// Project : PokerTime.Application
66
// ******************************************************************************
77

8-
namespace PokerTime.Application.Estimations.Queries {
8+
namespace PokerTime.Application.Common.Models {
99
using System;
1010
using System.Collections.Generic;
1111
using System.Linq;
12-
using Common.Mapping;
13-
using Common.Models;
1412
using Domain.Entities;
13+
using Mapping;
1514

1615
public sealed class UserStoryEstimation : IMapFrom<UserStory> {
1716
public int Id { get; }

src/PokerTime.Application/Estimations/Queries/GetEstimationsOverviewQueryHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace PokerTime.Application.Estimations.Queries {
1212
using System.Threading;
1313
using System.Threading.Tasks;
1414
using AutoMapper;
15-
using AutoMapper.QueryableExtensions;
1615
using Common;
1716
using Common.Abstractions;
17+
using Common.Models;
1818
using Domain.Entities;
1919
using MediatR;
2020
using Microsoft.EntityFrameworkCore;

src/PokerTime.Application/Estimations/Queries/GetEstimationsOverviewQueryResponse.cs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace PokerTime.Application.Estimations.Queries {
99
using System.Collections.Generic;
1010
using System.Linq;
11+
using Common.Models;
1112

1213
public sealed class GetEstimationsOverviewQueryResponse {
1314
public ICollection<UserStoryEstimation> UserStoryEstimations { get; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// ******************************************************************************
2+
// © 2020 Sebastiaan Dammann | damsteen.nl
3+
//
4+
// File: : GetEstimationsOverviewQueryHandlerTests.cs
5+
// Project : PokerTime.Application.Tests.Unit
6+
// ******************************************************************************
7+
8+
namespace PokerTime.Application.Tests.Unit.Estimations.Queries {
9+
using System.Drawing;
10+
using System.Linq;
11+
using System.Threading;
12+
using System.Threading.Tasks;
13+
using Application.Common;
14+
using Application.Estimations.Queries;
15+
using Domain.Entities;
16+
using NUnit.Framework;
17+
using Support;
18+
19+
[TestFixture]
20+
public sealed class GetEstimationsOverviewQueryHandlerTests : QueryTestBase {
21+
[Test]
22+
public void GetEstimationsOverviewQueryHandlerTests_ThrowsNotFoundException_WhenNotFound() {
23+
// Given
24+
const string sessionId = "surely-not-found";
25+
var query = new GetEstimationsOverviewQuery(sessionId);
26+
var handler = new GetEstimationsOverviewQueryHandler(this.Context, this.Mapper);
27+
28+
// When
29+
TestDelegate action = () => handler.Handle(query, CancellationToken.None).GetAwaiter().GetResult();
30+
31+
// Then
32+
Assert.That(action, Throws.InstanceOf<NotFoundException>());
33+
}
34+
35+
[Test]
36+
public async Task GetEstimationsOverviewQueryHandlerTests_ReturnsUserStoryEstimations() {
37+
// Given
38+
var session = new Session {
39+
Title = "Yet another test",
40+
Participants =
41+
{
42+
new Participant { Name = "John", Color = Color.BlueViolet },
43+
new Participant { Name = "Jane", Color = Color.Aqua },
44+
},
45+
HashedPassphrase = "abef",
46+
CurrentStage = SessionStage.Discussion
47+
};
48+
string sessionId = session.UrlId.StringId;
49+
this.Context.Sessions.Add(session);
50+
await this.Context.SaveChangesAsync(CancellationToken.None);
51+
52+
this.Context.UserStories.Add(new UserStory {
53+
Title = "First",
54+
Estimations =
55+
{
56+
new Estimation {Participant = session.Participants.First(), Symbol = this.Context.Symbols.First()},
57+
new Estimation {Participant = session.Participants.Last(), Symbol = this.Context.Symbols.Skip(1).First()}
58+
},
59+
Session = session
60+
});
61+
62+
this.Context.UserStories.Add(new UserStory {
63+
Title = "First",
64+
Estimations =
65+
{
66+
new Estimation
67+
{Participant = session.Participants.First(), Symbol = this.Context.Symbols.Skip(1).First()},
68+
new Estimation {Participant = session.Participants.Last(), Symbol = this.Context.Symbols.First()}
69+
},
70+
Session = session
71+
});
72+
await this.Context.SaveChangesAsync(CancellationToken.None);
73+
74+
var query = new GetEstimationsOverviewQuery(sessionId);
75+
var handler = new GetEstimationsOverviewQueryHandler(this.Context, this.Mapper);
76+
77+
// When
78+
GetEstimationsOverviewQueryResponse result = await handler.Handle(query, CancellationToken.None);
79+
80+
// Then
81+
Assert.That(result, Is.Not.Null);
82+
83+
Assert.That(result.UserStoryEstimations, Has.Count.EqualTo(2));
84+
}
85+
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// ******************************************************************************
2+
// © 2020 Sebastiaan Dammann | damsteen.nl
3+
//
4+
// File: : GetEstimationsQueryHandlerTests.cs
5+
// Project : PokerTime.Application.Tests.Unit
6+
// ******************************************************************************
7+
8+
namespace PokerTime.Application.Tests.Unit.Estimations.Queries {
9+
using System.Drawing;
10+
using System.Linq;
11+
using System.Threading;
12+
using System.Threading.Tasks;
13+
using Application.Common;
14+
using Application.Estimations.Queries;
15+
using Domain.Entities;
16+
using NUnit.Framework;
17+
using Support;
18+
19+
[TestFixture]
20+
public sealed class GetEstimationsQueryHandlerTests : QueryTestBase {
21+
[Test]
22+
public void GetEstimationsQueryHandlerTests_ThrowsNotFoundException_WhenSessionNotFound() {
23+
// Given
24+
const string sessionId = "surely-not-found";
25+
var query = new GetEstimationsQuery(sessionId, 3);
26+
var handler = new GetEstimationsQueryHandler(this.Context, this.Mapper);
27+
28+
// When
29+
TestDelegate action = () => handler.Handle(query, CancellationToken.None).GetAwaiter().GetResult();
30+
31+
// Then
32+
Assert.That(action, Throws.InstanceOf<NotFoundException>());
33+
}
34+
35+
[Test]
36+
public async Task GetEstimationsQueryHandlerTests_ThrowsNotFoundException_WhenUserStoryNotFound() {
37+
// Given
38+
var session = new Session {
39+
Title = "Yet another test",
40+
Participants =
41+
{
42+
new Participant { Name = "John", Color = Color.BlueViolet },
43+
new Participant { Name = "Jane", Color = Color.Aqua },
44+
},
45+
HashedPassphrase = "abef",
46+
CurrentStage = SessionStage.Discussion
47+
};
48+
string sessionId = session.UrlId.StringId;
49+
this.Context.Sessions.Add(session);
50+
await this.Context.SaveChangesAsync(CancellationToken.None);
51+
52+
var query = new GetEstimationsQuery(sessionId, -1);
53+
var handler = new GetEstimationsQueryHandler(this.Context, this.Mapper);
54+
55+
// When
56+
TestDelegate action = () => handler.Handle(query, CancellationToken.None).GetAwaiter().GetResult();
57+
58+
// Then
59+
Assert.That(action, Throws.InstanceOf<NotFoundException>());
60+
}
61+
62+
[Test]
63+
public async Task GetEstimationsQueryHandlerTests_ReturnsUserStoryEstimations() {
64+
// Given
65+
var session = new Session {
66+
Title = "Yet another test",
67+
Participants =
68+
{
69+
new Participant { Name = "John", Color = Color.BlueViolet },
70+
new Participant { Name = "Jane", Color = Color.Aqua },
71+
},
72+
HashedPassphrase = "abef",
73+
CurrentStage = SessionStage.Discussion
74+
};
75+
string sessionId = session.UrlId.StringId;
76+
this.Context.Sessions.Add(session);
77+
await this.Context.SaveChangesAsync(CancellationToken.None);
78+
79+
this.Context.UserStories.Add(new UserStory {
80+
Title = "First",
81+
Estimations =
82+
{
83+
new Estimation {Participant = session.Participants.First(), Symbol = this.Context.Symbols.First()},
84+
new Estimation {Participant = session.Participants.Last(), Symbol = this.Context.Symbols.Skip(1).First()}
85+
},
86+
Session = session
87+
});
88+
89+
UserStory lastUserStory = this.Context.UserStories.Add(new UserStory {
90+
Title = "First",
91+
Estimations =
92+
{
93+
new Estimation
94+
{Participant = session.Participants.First(), Symbol = this.Context.Symbols.Skip(1).First()},
95+
new Estimation {Participant = session.Participants.Last(), Symbol = this.Context.Symbols.First()}
96+
},
97+
Session = session
98+
}).Entity;
99+
await this.Context.SaveChangesAsync(CancellationToken.None);
100+
101+
var query = new GetEstimationsQuery(sessionId, lastUserStory.Id);
102+
var handler = new GetEstimationsQueryHandler(this.Context, this.Mapper);
103+
104+
// When
105+
GetEstimationsQueryResponse result = await handler.Handle(query, CancellationToken.None);
106+
107+
// Then
108+
Assert.That(result, Is.Not.Null);
109+
110+
Assert.That(result.Estimations, Has.Count.EqualTo(2));
111+
}
112+
113+
}
114+
}

tests/PokerTime.Application.Tests.Unit/MappingTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace PokerTime.Application.Tests.Unit {
99
using System.Drawing;
1010
using System.Linq;
1111
using Application.Common.Models;
12+
using Application.Estimations.Queries;
1213
using Application.PredefinedParticipantColors.Queries.GetAvailablePredefinedParticipantColors;
1314
using Application.Sessions.Queries.GetParticipantsInfo;
1415
using Domain.Entities;

0 commit comments

Comments
 (0)