/// <summary> /// This is designed to set up the system for using direct access entity classes in a unit test or a service /// </summary> /// <param name="context">This is the DbContext conatining the entity clas your TDto refers to</param> /// <param name="publicConfig">Optional: you can provide a publicConfig. /// NOTE: All use of this method must use the same config file, because it is read at startup and then cached.</param> public static SpecificUseData SetupEntitiesDirect(this DbContext context, IGenericServicesConfig publicConfig = null) { context.RegisterEntityClasses(); var utData = new SpecificUseData(publicConfig); return(utData); }
/// <summary> /// This is designed to set up the system for using one DTO and the entity classes in a unit test or a service /// </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="context">This is the DbContext containing the entity class your TDto refers to</param> /// <param name="publicConfig">Optional: you can provide a publicConfig. /// NOTE: All use of this method must use the same config file, because it is read at startup and then cached.</param> public static SpecificUseData SetupSingleDtoAndEntities <TDto>(this DbContext context, IGenericServicesConfig publicConfig = null) { context.RegisterEntityClasses(); var utData = new SpecificUseData(publicConfig); utData.AddSingleDto <TDto>(); return(utData); }
/// <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); }