Skip to content

Commit 9e9e9a0

Browse files
committed
Adding more functional tests
1 parent 314bdf8 commit 9e9e9a0

File tree

4 files changed

+447
-22
lines changed

4 files changed

+447
-22
lines changed

sample/src/NimblePros.SampleToDo.Web/Projects/CreateToDoItem.CreateToDoItemValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using FastEndpoints;
2-
using FluentValidation;
1+
using FluentValidation;
32
using NimblePros.SampleToDo.Infrastructure.Data.Config;
43

54
namespace NimblePros.SampleToDo.Web.Projects;
@@ -18,6 +17,7 @@ public CreateToDoItemValidator()
1817
.MinimumLength(2)
1918
.MaximumLength(DataSchemaConstants.DEFAULT_NAME_LENGTH);
2019
RuleFor(x => x.Description)
20+
.MaximumLength(200) // TODO: Move to constant
2121
.NotEmpty();
2222
}
2323
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using NimblePros.SampleToDo.Web;
2+
using NimblePros.SampleToDo.Web.Projects;
3+
4+
namespace NimblePros.SampleToDo.FunctionalTests.Projects;
5+
6+
/// <summary>
7+
/// Fluent builder for CreateToDoItemRequest to make tests more readable and maintainable
8+
/// </summary>
9+
public class CreateToDoItemRequestBuilder
10+
{
11+
private readonly CreateToDoItemRequest _request = new();
12+
13+
public CreateToDoItemRequestBuilder WithProjectId(int projectId)
14+
{
15+
_request.ProjectId = projectId;
16+
return this;
17+
}
18+
19+
public CreateToDoItemRequestBuilder WithTitle(string title)
20+
{
21+
_request.Title = title;
22+
return this;
23+
}
24+
25+
public CreateToDoItemRequestBuilder WithDescription(string description)
26+
{
27+
_request.Description = description;
28+
return this;
29+
}
30+
31+
public CreateToDoItemRequestBuilder WithContributorId(int? contributorId)
32+
{
33+
_request.ContributorId = contributorId;
34+
return this;
35+
}
36+
37+
public CreateToDoItemRequestBuilder WithValidDefaults()
38+
{
39+
var uniqueId = Guid.NewGuid().ToString()[..8];
40+
var timestamp = DateTimeOffset.UtcNow.Ticks.ToString()[^8..]; // Last 8 digits of ticks
41+
return WithProjectId(SeedData.TestProject1.Id.Value)
42+
.WithTitle($"Test Todo {uniqueId}-{timestamp}")
43+
.WithDescription($"Test Description {uniqueId}-{timestamp}");
44+
}
45+
46+
public CreateToDoItemRequest Build() => _request;
47+
48+
public static CreateToDoItemRequestBuilder Create() => new();
49+
}

0 commit comments

Comments
 (0)