Пример #1
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            V_0 = MixService.GetConnectionString("MixCmsConnection");
            if (!string.IsNullOrEmpty(V_0))
            {
                switch (Enum.Parse <MixEnums.DatabaseProvider>(MixService.GetConfig <string>("DatabaseProvider")))
                {
                case 0:
                {
                    dummyVar0 = SqlServerDbContextOptionsExtensions.UseSqlServer(optionsBuilder, V_0, null);
                    return;
                }

                case 1:
                {
                    dummyVar1 = MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, V_0, null);
                    return;
                }

                case 2:
                {
                    dummyVar2 = NpgsqlDbContextOptionsExtensions.UseNpgsql(optionsBuilder, V_0, null);
                    break;
                }

                default:
                {
                    return;
                }
                }
            }
            return;
        }
        private ICityService getCityService()
        {
            DbContextOptions options     = MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), ConnectionString).Options;
            SakilaDbContext  ctx         = new SakilaDbContext(options);
            ICityService     cityService = new CityService(ctx);

            return(cityService);
        }
Пример #3
0
        public void testFindById()
        {
            DbContextOptions options     = MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), ConnectionString).Options;
            SakilaDbContext  ctx         = new SakilaDbContext(options);
            IFilmService     filmService = new FilmService(ctx);

            Film film = filmService.findById(83);

            Assert.Equal("BLUES INSTINCT", film.Title);
        }
Пример #4
0
        public void testListAll()
        {
            DbContextOptions options     = MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), ConnectionString).Options;
            SakilaDbContext  ctx         = new SakilaDbContext(options);
            IFilmService     filmService = new FilmService(ctx);

            List <Film> filmsList = filmService.listAll();

            Assert.Equal(1000, filmsList.Count);
        }
Пример #5
0
        public void testListAll()
        {
            // restauração do banco
            DbContextOptions options = MySqlDbContextOptionsExtensions
                                       .UseMySql(new DbContextOptionsBuilder(), "server=172.16.99.230;userid=root;pwd=1q2w3e4r;port=3308;database=sakila;sslmode=none;").Options;

            SakilaDbContext ctx = new SakilaDbContext(options);

            filmService = new FilmService(ctx);
            var list = filmService.listAll();

            Assert.Equal(1000, list.Count);
            Assert.NotNull(list[45].Language);
        }
        public void UseMySql_ThrowsIfServiceNameNull()
        {
            var    optionsBuilder = new DbContextOptionsBuilder();
            var    goodBuilder    = new DbContextOptionsBuilder <GoodDbContext>();
            var    config         = new ConfigurationBuilder().Build();
            string serviceName    = null;

            var ex2 = Assert.Throws <ArgumentException>(() => MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, config, serviceName));

            Assert.Contains(nameof(serviceName), ex2.Message);

            var ex4 = Assert.Throws <ArgumentException>(() => MySqlDbContextOptionsExtensions.UseMySql <GoodDbContext>(goodBuilder, config, serviceName));

            Assert.Contains(nameof(serviceName), ex4.Message);
        }
Пример #7
0
        public void testSaveOrUpdate_atualizacao()
        {
            DbContextOptions options     = MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), ConnectionString).Options;
            SakilaDbContext  ctx         = new SakilaDbContext(options);
            IFilmService     filmService = new FilmService(ctx);

            Film film = new Film()
            {
                Id          = 2,
                Title       = "Filme Teste2",
                Description = "Description2",
                ReleaseYear = 2019
            };

            filmService.saveOrUpdate(film);
            Assert.Equal("Filme Teste2", filmService.findById(2).Title);
        }
Пример #8
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (!optionsBuilder.get_IsConfigured())
     {
         V_0 = MixService.GetConnectionString("MixCmsConnection");
         if (!string.IsNullOrEmpty(V_0))
         {
             if (MixService.GetConfig <bool>("IsMysql"))
             {
                 dummyVar0 = MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, V_0, null);
                 return;
             }
             dummyVar1 = SqlServerDbContextOptionsExtensions.UseSqlServer(optionsBuilder, V_0, null);
         }
     }
     return;
 }
Пример #9
0
        public void testSaveOrUpdate_insercao()
        {
            DbContextOptions options     = MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), ConnectionString).Options;
            SakilaDbContext  ctx         = new SakilaDbContext(options);
            IFilmService     filmService = new FilmService(ctx);

            Film film = new Film()
            {
                Title       = "Filme Teste",
                Description = "Description",
                ReleaseYear = 2018
            };

            filmService.saveOrUpdate(film);

            Assert.Equal(film, filmService.findById(1001));
            Assert.Equal(1001, filmService.listAll().Count);
        }
        public void UseMySql_ThrowsIfConfigurationNull()
        {
            var optionsBuilder        = new DbContextOptionsBuilder();
            var goodBuilder           = new DbContextOptionsBuilder <GoodDbContext>();
            IConfigurationRoot config = null;

            var ex = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, config));

            Assert.Contains(nameof(config), ex.Message);

            var ex2 = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, config, "foobar"));

            Assert.Contains(nameof(config), ex2.Message);

            var ex3 = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql <GoodDbContext>(goodBuilder, config));

            Assert.Contains(nameof(config), ex3.Message);

            var ex4 = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql <GoodDbContext>(goodBuilder, config, "foobar"));

            Assert.Contains(nameof(config), ex4.Message);
        }
Пример #11
0
        public void UseMySql_ThrowsIfDbContextOptionsBuilderNull()
        {
            // Arrange
            DbContextOptionsBuilder optionsBuilder = null;
            DbContextOptionsBuilder <GoodDbContext> goodBuilder = null;
            IConfigurationRoot config = null;

            // Act and Assert
            var ex = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, config));

            Assert.Contains(nameof(optionsBuilder), ex.Message);

            var ex2 = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql(optionsBuilder, config, "foobar"));

            Assert.Contains(nameof(optionsBuilder), ex2.Message);

            var ex3 = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql <GoodDbContext>(goodBuilder, config));

            Assert.Contains(nameof(optionsBuilder), ex3.Message);

            var ex4 = Assert.Throws <ArgumentNullException>(() => MySqlDbContextOptionsExtensions.UseMySql <GoodDbContext>(goodBuilder, config, "foobar"));

            Assert.Contains(nameof(optionsBuilder), ex4.Message);
        }
 private static DbContextOptions GetOptions(string connectionString)
 {
     return(MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), connectionString).Options);
 }
Пример #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var mysql = true;

            if (!mysql)
            {
                string connectionString = "Server=tcp:nerdish.database.windows.net,1433;Initial Catalog=sigma;Persist Security Info=False;User ID=api;Password='******';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
                services.AddDbContext <SigmaContext>(x => x.UseSqlServer(connectionString));
            }
            else
            {
                MySqlConnectionStringBuilder connectionString = new MySqlConnectionStringBuilder()
                {
                    UserID   = "api",
                    Server   = "204.48.19.107",
                    Port     = 3306,
                    Password = "******",
                    Database = "sigma"
                };
                services.AddDbContext <SigmaContext>(x => MySqlDbContextOptionsExtensions.UseMySql(x, connectionString.ToString()));
            }
            services.AddTransient <IRepository <Turno>, RTurno>();
            services.AddTransient <IRepository <Materia>, RMateria>();
            services.AddTransient <IRepository <Orientacion>, ROrientacion>();
            services.AddTransient <IRepository <Grupo>, RGrupo>();
            services.AddTransient <IUserRepository <Docente>, RDocente>();
            services.AddTransient <IRepository <GrupoDocente>, RGrupoDocente>();
            services.AddTransient <IRepository <ParcialGrupo>, RParcialGrupo>();
            services.AddTransient <IRepository <EscritoGrupo>, REscritoGrupo>();
            services.AddTransient <IRepository <TareaGrupo>, RTareaGrupo>();
            services.AddTransient <IRepository <Tarea>, RTarea>();
            services.AddTransient <IUserRepository <Alumno>, RAlumno>();
            services.AddTransient <IRepository <Imagen>, RImagen>();
            services.AddTransient <IRepository <Pregunta>, RPregunta>();
            services.AddTransient <IRepository <PreguntaOpcion>, RPreguntaOpcion>();
            services.AddTransient <IRepository <Alerta>, RAlerta>();
            services.AddTransient <IRepository <Token>, RToken>();
            services.AddTransient <IRepository <Parcial>, RParcial>();
            services.AddTransient <IRepository <EncuestaGlobal>, REncuestaGlobal>();
            services.AddTransient <IRepository <CambioDeSalon>, RCambioDeSalon>();
            services.AddTransient <IRepository <Salon>, RSalon>();
            services.AddTransient <IRepository <HoraMateria>, RHoraMateria>();
            services.AddTransient <IUserRepository <Adscripto>, RAdscripto>();
            services.AddTransient <IRepository <Escrito>, REscrito>();
            services.AddIdentity <AppUser, IdentityRole>(options =>
            {
                options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                options.User.RequireUniqueEmail        = false;
            }).AddEntityFrameworkStores <SigmaContext>().AddDefaultTokenProviders();
            services.AddMvc();

            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 1;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
            });

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); // => remove default claims
            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = Configuration["JwtIssuer"],
                    ValidAudience    = Configuration["JwtIssuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtKey"])),
                    ClockSkew        = TimeSpan.Zero // remove delay of token when expire
                };
            });
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });
        }
Пример #14
0
 private static DbContextOptions <DBEntities> GetOptions()
 {
     return(MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder <DBEntities>(), Startup.ConnectionString).Options);
 }
Пример #15
0
 private static DbContextOptions GetOptions()
 {
     return(MySqlDbContextOptionsExtensions.UseMySql(new DbContextOptionsBuilder(), "Server=78.102.218.164;Port=7688;Database=chatter;User=conApp;Password=igR7DqL3HcvnHJ2q;CharSet=utf8;").Options);
 }