profileShare

rasmusjy / splitapp-backend-clean-onion

Read-only snapshot

No repository description.

main default branch 429 files Expires Sep 13, 2026, 9:06 AM
TripValidationTests.cs 1,316 bytes
1 using System.ComponentModel.DataAnnotations;
2 using App.Domain;
3 using FluentAssertions;
4
5 namespace App.Tests.Domain;
6
7 public class TripValidationTests
8 {
9 [Fact]
10 public void Validate_WhenEndDateBeforeStartDate_YieldsValidationError()
11 {
12 var trip = new Trip
13 {
14 Name = "Bad trip",
15 StartDate = new DateTime(2026, 5, 10, 0, 0, 0, DateTimeKind.Utc),
16 EndDate = new DateTime(2026, 5, 1, 0, 0, 0, DateTimeKind.Utc)
17 };
18
19 var results = trip.Validate(new ValidationContext(trip)).ToList();
20
21 results.Should().ContainSingle()
22 .Which.MemberNames.Should().Contain(nameof(Trip.EndDate));
23 }
24
25 [Fact]
26 public void Validate_WhenEndDateEqualsStartDate_YieldsNoErrors()
27 {
28 // Edge case: same-day trip is valid
29 var date = new DateTime(2026, 5, 1, 0, 0, 0, DateTimeKind.Utc);
30 var trip = new Trip { Name = "Day trip", StartDate = date, EndDate = date };
31
32 var results = trip.Validate(new ValidationContext(trip));
33
34 results.Should().BeEmpty();
35 }
36
37 [Fact]
38 public void Validate_WhenDatesAreNull_YieldsNoErrors()
39 {
40 var trip = new Trip { Name = "Open-ended" };
41
42 var results = trip.Validate(new ValidationContext(trip));
43
44 results.Should().BeEmpty();
45 }
46 }
47