public async Task VenueNameSpecifiedWithProviderVenueRef_ReturnsValidationError()
        {
            // Arrange
            var provider = await TestData.CreateProvider();

            var user = await TestData.CreateUser();

            var venue = await TestData.CreateVenue(
                providerId : provider.ProviderId,
                createdBy : user,
                venueName : "My Venue",
                providerVenueRef : "VENUE1");

            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode     = "classroom based",
                ProviderVenueRef = venue.ProviderVenueRef,
                VenueName        = venue.VenueName
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_VENUE_NAME_NOT_ALLOWED_WITH_REF");
        }
        public async Task DurationUnitMissing_ReturnsValidationError()
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DurationUnit = string.Empty,
                Duration     = "10"
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_DURATION_UNIT_REQUIRED");
        }
        public async Task CostEmptyWithEmptyCostDescription_ReturnsSingleCostValidationError()
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                Cost            = string.Empty,
                CostDescription = string.Empty
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_COST_REQUIRED");
        }
        public async Task SubRegionsInvalidWithNonWorkBasedDeliveryMode_DoesNotReturnInvalidValidationError(string deliveryMode)
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode = deliveryMode,
                SubRegions   = "xxx"
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.DoesNotContain(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_SUBREGIONS_INVALID");
        }
        public async Task AttendancePatternNotEmptyWithNonClassroomBasedDeliveryMode_ReturnsValidationError(string deliveryMode)
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                AttendancePattern = "daytime",
                DeliveryMode      = deliveryMode
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_ATTENDANCE_PATTERN_NOT_ALLOWED");
        }
        public async Task StudyModeNotEmptyWithNonClassroomBasedDeliveryMode_ReturnsValidationError(string deliveryMode)
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode = deliveryMode,
                StudyMode    = "full time"
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_STUDY_MODE_NOT_ALLOWED");
        }
        public async Task StartDateNotEmptyWithFlexibleTrue_ReturnsValidationError()
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                StartDate         = "01/04/2021",
                FlexibleStartDate = "yes"
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_START_DATE_NOT_ALLOWED");
        }
        public async Task NationalDeliveryNotEmptyWithNonWorkBasedDeliveryMode_ReturnsValidationError(string nationalDelivery)
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode     = "classroom based",
                NationalDelivery = nationalDelivery
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_NATIONAL_DELIVERY_NOT_ALLOWED");
        }
        public async Task SubRegionsEmptyWithNational_DoesNotReturnValidationError()
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode     = "work based",
                NationalDelivery = "yes",
                SubRegions       = ""
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.DoesNotContain(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_SUBREGIONS_INVALID");
        }
        public async Task ProviderVenueRefEmptyButVenueNameNotEmpty_DoesNotReturnValidationError()
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode     = "classroom based",
                ProviderVenueRef = string.Empty,
                VenueName        = "venue"
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.DoesNotContain(
                validationResult.Errors,
                error => error.PropertyName == nameof(CsvCourseRow.ProviderVenueRef));
        }
        public async Task ProviderVenueRefAndVenueNameEmptyWithClassroomBasedDeliveryMode_ReturnsValidationError()
        {
            // Arrange
            var allRegions = await new RegionCache(SqlQueryDispatcherFactory).GetAllRegions();

            var row = new CsvCourseRow()
            {
                DeliveryMode     = "classroom based",
                ProviderVenueRef = string.Empty,
                VenueName        = string.Empty
            };

            var validator = new CourseUploadRowValidator(Clock, matchedVenueId: null);

            // Act
            var validationResult = validator.Validate(ParsedCsvCourseRow.FromCsvCourseRow(row, allRegions));

            // Assert
            Assert.Contains(
                validationResult.Errors,
                error => error.ErrorCode == "COURSERUN_VENUE_REQUIRED");
        }