public void TestSetupSingleDtoAndEntitiesTestAssemblyEfCoreContextAndTestDbContextOk() { //SETUP var options1 = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options1)) { context.RegisterEntityClasses(); } var options2 = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options2)) { context.RegisterEntityClasses(); } //ATTEMPT var setupDtos = new SetupDtosAndMappings(new GenericServicesConfig()); setupDtos.ScanAllAssemblies(new[] { GetType().Assembly }, true); //VERIFY setupDtos.IsValid.ShouldBeFalse(); setupDtos.Errors.Count.ShouldEqual(3); }
/// <summary> /// If you use ConfigureGenericServicesEntities, then you should follow it with this method to find/set up the DTOs /// </summary> /// <param name="setupPart1"></param> /// <param name="assembliesToScan"></param> /// <returns></returns> public static IGenericServicesSetupPart2 ScanAssemblesForDtos(this IGenericServicesSetupPart1 setupPart1, params Assembly[] assembliesToScan) { var dtosRegister = new SetupDtosAndMappings(setupPart1.PublicConfig); var wrappedMapping = dtosRegister.ScanAllAssemblies(assembliesToScan, setupPart1.PublicConfig); if (!dtosRegister.IsValid) { throw new InvalidOperationException($"SETUP FAILED with {dtosRegister.Errors.Count} errors. Errors are:\n" + dtosRegister.GetAllErrors()); } return(new GenericServicesSetupPart2(setupPart1.Services, setupPart1.PublicConfig, wrappedMapping)); }
/// <summary> /// This is designed to add one DTO to an existing SpecificUseData /// </summary> /// <typeparam name="TDto">This should be the type of a class that has the <see cref="ILinkToEntity{TEntity}"/> applied to it</typeparam> /// <param name="utData"></param> /// <returns></returns> public static SpecificUseData AddSingleDto <TDto>(this SpecificUseData utData) { var status = new StatusGenericHandler(); var typesInAssembly = typeof(TDto).Assembly.GetTypes(); var dtoRegister = new RegisterOneDtoType(typeof(TDto), typesInAssembly, utData.PublicConfig); status.CombineStatuses(dtoRegister); if (!status.IsValid) { throw new InvalidOperationException($"SETUP FAILED with {status.Errors.Count} errors. Errors are:\n" + status.GetAllErrors()); } SetupDtosAndMappings.SetupMappingForDto(dtoRegister, utData.ReadProfile, utData.SaveProfile); return(utData); }
public void TestSetupSingleDtoAndEntitiesInitializeOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.RegisterEntityClasses(); //ATTEMPT var setupDtos = new SetupDtosAndMappings(new GenericServicesConfig()); var wrappedMappings = setupDtos.ScanAllAssemblies(new[] { typeof(BookListDto).Assembly }, true); //VERIFY setupDtos.IsValid.ShouldBeTrue(setupDtos.GetAllErrors()); wrappedMappings.ShouldNotBeNull(); } }