Skip to content

Commit 690d0fe

Browse files
author
Brian Cummings
committed
Added validator tests
1 parent 410ee66 commit 690d0fe

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

PathfinderHonorManager.Tests/Validator/PathfinderValidatorTests.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,90 @@ public async Task Validate_AllRulesApplied_ValidationError()
271271
validationResult.ShouldHaveValidationErrorFor(p => p.ClubID);
272272
}
273273

274+
[Test]
275+
public async Task Validate_InvalidClubId_ValidationError()
276+
{
277+
using (var context = new PathfinderContext(ContextOptions))
278+
{
279+
var newPathfinder = new Incoming.PathfinderDtoInternal
280+
{
281+
FirstName = "Test",
282+
LastName = "User",
283+
Email = "test@example.com",
284+
ClubID = Guid.NewGuid()
285+
};
286+
287+
var validationResult = await _pathfinderValidator
288+
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));
289+
290+
validationResult.ShouldHaveValidationErrorFor(p => p.ClubID)
291+
.WithErrorMessage("New club ID must be valid if provided");
292+
}
293+
}
294+
295+
[Test]
296+
public async Task Validate_ValidClubIdInUpdate_ShouldPass()
297+
{
298+
using (var context = new PathfinderContext(ContextOptions))
299+
{
300+
var club = new Club
301+
{
302+
ClubID = Guid.NewGuid(),
303+
Name = "Test Club",
304+
ClubCode = "TEST"
305+
};
306+
await context.Clubs.AddAsync(club);
307+
await context.SaveChangesAsync();
308+
309+
var newPathfinder = new Incoming.PathfinderDtoInternal
310+
{
311+
FirstName = "Test",
312+
LastName = "User",
313+
Email = "test@example.com",
314+
ClubID = club.ClubID
315+
};
316+
317+
var validationResult = await _pathfinderValidator
318+
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));
319+
320+
validationResult.ShouldNotHaveValidationErrorFor(p => p.ClubID);
321+
}
322+
}
323+
324+
[Test]
325+
public async Task Validate_NullClubId_ShouldPass()
326+
{
327+
var newPathfinder = new Incoming.PathfinderDtoInternal
328+
{
329+
FirstName = "Test",
330+
LastName = "User",
331+
Email = "test@example.com",
332+
ClubID = null
333+
};
334+
335+
var validationResult = await _pathfinderValidator
336+
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));
337+
338+
validationResult.ShouldNotHaveValidationErrorFor(p => p.ClubID);
339+
}
340+
341+
[Test]
342+
public async Task Validate_EmptyGuidClubId_ShouldPass()
343+
{
344+
var newPathfinder = new Incoming.PathfinderDtoInternal
345+
{
346+
FirstName = "Test",
347+
LastName = "User",
348+
Email = "test@example.com",
349+
ClubID = Guid.Empty
350+
};
351+
352+
var validationResult = await _pathfinderValidator
353+
.TestValidateAsync(newPathfinder, options => options.IncludeRuleSets("update"));
354+
355+
validationResult.ShouldNotHaveValidationErrorFor(p => p.ClubID);
356+
}
357+
274358
public static void SeedDatabase(PathfinderContext context)
275359
{
276360
context.Database.EnsureDeleted();

0 commit comments

Comments
 (0)