예제 #1
0
        public async Task CheckReservation_WithValidationFailures_ShouldReturnExpectedErrors()
        {
            // arrange
            var reservationId = Guid.NewGuid();

            void AssertContains(ReservationValidationError[] errors, string propertyName, string reason)
            {
                var requiredEntry = errors.Where(e => e.PropertyName == propertyName && e.Reason == reason).ToArray();

                Assert.AreEqual(1, requiredEntry.Length, $"The returned errors contain {requiredEntry.Length} errors for property '{propertyName}' with reason '{reason}' when only one was expected.");
            }

            var fixtures = new ReservationValidationServiceTestFixtures()
                           .WithValidStartDate()
                           .WithReservationId(reservationId)
                           .WithReservationError("startdate", "some date error")
                           .WithReservationError("coursecode", "some course error");

            const int expectedNumberOfErrors = 2;

            // Act + Assert
            await fixtures.CheckReservation(result =>
            {
                Assert.AreEqual(expectedNumberOfErrors, result.ValidationErrors.Length);
                AssertContains(result.ValidationErrors, "startdate", "some date error");
                AssertContains(result.ValidationErrors, "coursecode", "some course error");
            });
        }
예제 #2
0
        public async Task CheckReservation_WithoutReservationId_ShouldNotCallApi()
        {
            var fixtures = new ReservationValidationServiceTestFixtures();

            await fixtures.CheckReservation();

            fixtures.ReservationsApiClientMock
            .Verify(rac => rac.ValidateReservation(
                        It.IsAny <ReservationValidationMessage>(),
                        It.IsAny <CancellationToken>()), Times.Never);
        }
예제 #3
0
        public async Task CheckReservation_WithValidationFailures_ShouldHaveHasErrorsTrue()
        {
            var reservationId = Guid.NewGuid();

            var fixtures = new ReservationValidationServiceTestFixtures()
                           .WithValidStartDate()
                           .WithReservationId(reservationId)
                           .WithReservationError("startdate", "some error")
                           .WithReservationError("coursecode", "some code");

            await fixtures.CheckReservation(result => Assert.IsTrue(result.HasErrors));
        }
예제 #4
0
        public async Task CheckReservation_WithReservationId_ShouldCallApi()
        {
            var reservationId = Guid.NewGuid();

            var fixtures = new ReservationValidationServiceTestFixtures()
                           .WithValidStartDate()
                           .WithReservationId(reservationId);

            await fixtures.CheckReservation();

            fixtures.ReservationsApiClientMock
            .Verify(rac => rac.ValidateReservation(
                        It.Is <ReservationValidationMessage>(msg => msg.ReservationId == reservationId),
                        It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #5
0
        public void Constructor_NullLogger_ShouldThrowNullArgumentException()
        {
            var fixtures = new ReservationValidationServiceTestFixtures();

            Assert.Throws <ArgumentNullException>(() => fixtures.CreateServiceWithNullLogger());
        }
예제 #6
0
        public void Constructor_ValidCall_ShouldNotThrowException()
        {
            var fixtures = new ReservationValidationServiceTestFixtures();

            fixtures.CreateService();
        }