public static IServiceProvider CreateProvider(Action <IServiceCollection> overrides = null) { IConfigurationRoot configuration = new ConfigurationBuilder().Build(); var eventApiHttpSettings = new RepositorySettings { ConnectionString = new ConnectionString { PostgresUser = RandomBuilder.NextString(), PostgresPassword = RandomBuilder.NextString(), PostgresServer = RandomBuilder.NextString() } }; var priceLadderSettings = new PublicHolidaySettings { ApiUrl = RandomBuilder.NextString(), ResourceId = RandomBuilder.NextString(), State = RandomBuilder.NextString() }; IServiceCollection services = new ServiceCollection() .AddServiceOptions(configuration) .AddTimeLoggerService() .AddRepository((_, builder) => builder.UseInMemoryDatabase(Guid.NewGuid().ToString())) .AddPublicHolidayClient() .Replace(ServiceDescriptor.Singleton <IOptions <RepositorySettings> >(new OptionsWrapper <RepositorySettings>(eventApiHttpSettings))) .Replace(ServiceDescriptor.Singleton <IOptions <PublicHolidaySettings> >(new OptionsWrapper <PublicHolidaySettings>(priceLadderSettings))) .AddTransient <TimesheetController>(); overrides?.Invoke(services); return(services.BuildServiceProvider(true)); }
public void And_Name_Overflows_Max_Length() { // Arrange string invalidName = RandomBuilder.NextString(ValidationLimits.NameMaxLength + 1); var productOption = new ProductOptionDto { Description = "description", Name = invalidName, ProductId = RandomBuilder.NextGuid() }; // Act var result = _validator.TestValidate(productOption); // Assert result.ShouldHaveValidationErrorFor(x => x.Name); Assert.True(!result.IsValid); Assert.True(result.Errors.Count == 1); Assert.Contains(result.Errors, x => x.PropertyName == "Name" && x.ErrorMessage == ValidationErrors.NameMaxLengthError); }
public void And_Description_Overflows_Max_Length() { // Arrange string invalidDescription = RandomBuilder.NextString(ValidationLimits.DescriptionMaxLength + 1); var product = new ProductDto { Price = 10, Code = "code", Description = invalidDescription, Name = "name" }; // Act var result = _validator.TestValidate(product); // Assert result.ShouldHaveValidationErrorFor(x => x.Description); Assert.True(!result.IsValid); Assert.True(result.Errors.Count == 1); Assert.Contains(result.Errors, x => x.PropertyName == "Description" && x.ErrorMessage == ValidationErrors.DescriptionMaxLengthError); }