/// <summary>
        /// Initializes a new instance of the <see cref="DataTablePlusTests"/> class.
        /// </summary>
        public DataTablePlusTests()
        {
            // Sets the culture to invariant in order to avoid some exception details in another language
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var configurationBuilder = new ConfigurationBuilder();

            // Gets the connection string from the configuration file
            var configuration    = configurationBuilder.AddJsonFile("appsettings.json").Build();
            var connectionString = configuration.GetConnectionString("Context");

            var dbContextOptionsBuilder = new DbContextOptionsBuilder <Context>();

            dbContextOptionsBuilder.UseSqlServer(connectionString);
            dbContextOptionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);

            // Creates the DbContext
            var context = new Context(dbContextOptionsBuilder.Options);

            // Adds the DbProvider to DataTablePlus configurations
            Startup.AddDbProvider(DbProvider.SQLServer);

            // Adds the DbContext to DataTablePlus configurations
            Startup.AddDbContext(context);

            // Also, a connection string can be added to these configurations
            // You should specify at least one of them (DbContext and/or a ConnectionString) and just a reminder: if a DbContext was not provided, the EF extensions will not be available

            // Adds the connection string to DataTablePlus configurations
            Startup.AddConnectionString(connectionString);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the data table plus.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="dbProvider">The database provider.</param>
        /// <param name="dbContext">The database context.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <returns>IServiceCollection.</returns>
        /// <exception cref="ArgumentNullException">
        /// services
        /// or
        /// dbContext
        /// </exception>
        /// <exception cref="ArgumentException">
        /// dbProvider
        /// or
        /// connectionString
        /// </exception>
        public static IServiceCollection AddDataTablePlus(this IServiceCollection services, DbProvider dbProvider, DbContext dbContext, string connectionString)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (dbProvider == DbProvider.None)
            {
                throw new ArgumentException(nameof(dbProvider));
            }

            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException(nameof(connectionString));
            }

            Startup.AddDbProvider(dbProvider);
            Startup.AddDbContext(dbContext);
            Startup.AddConnectionString(connectionString);

            return(services);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the data table plus.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="dbProvider">The database provider.</param>
        /// <returns>IServiceCollection.</returns>
        /// <exception cref="ArgumentNullException">services</exception>
        /// <exception cref="ArgumentException">dbProvider</exception>
        public static IServiceCollection AddDataTablePlus(this IServiceCollection services, DbProvider dbProvider)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (dbProvider == DbProvider.None)
            {
                throw new ArgumentException(nameof(dbProvider));
            }

            Startup.AddDbProvider(dbProvider);

            return(services);
        }
        public static void Initialize(TestContext testContext)
        {
            // Sets the culture to invariant in order to avoid some exception details in another language
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // Creates the DbContext
            var context = new Context();

            // Adds the DbProvider to DataTablePlus configurations
            Startup.AddDbProvider(DbProvider.SQLServer);

            // Adds the DbContext to DataTablePlus configurations
            Startup.AddDbContext(context);

            // Also, a connection string can be added to these configurations
            // You should specify at least one of them (DbContext and/or a ConnectionString) and just a reminder: if a DbContext was not provided, the EF extensions will not be available

            // Gets the connection string from the configuration file
            var connectionString = ConfigurationManager.ConnectionStrings["Context"].ConnectionString;

            // Adds the connection string to DataTablePlus configurations
            Startup.AddConnectionString(connectionString);
        }