Exemple #1
0
        /// <summary>
        /// This is designed to set up the system for using one DTO and the entity classes in a unit test of 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 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 UnitTestData SetupSingleDtoAndEntities <TDto>(this DbContext context,
                                                                    IGenericServicesConfig publicConfig = null)
        {
            context.RegisterEntityClasses();
            var utData = new UnitTestData(publicConfig);

            utData.AddSingleDto <TDto>();
            return(utData);
        }
Exemple #2
0
        /// <summary>
        /// This is designed to add one DTO to an existing UnitTestData
        /// </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 UnitTestData AddSingleDto <TDto>(this UnitTestData 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);
        }