public ServicesServiceTests()
        {
            //create InMemory DbContext
            var builder = new DbContextOptionsBuilder <AlgDbContext>();

            builder.UseInMemoryDatabase("ServicesServiceTests")
            .EnableSensitiveDataLogging();
            var options = builder.Options;
            var context = new AlgDbContext(options);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            _usersRepository = new UsersRepository(context);

            //create UsersService
            _servicesRepository = new ServicesRepository(context);
            var config = new MapperConfiguration(c =>
            {
                c.AddProfile <ServicesMapProfile>();
            });

            _mapper = config.CreateMapper();

            _settings = new PagingSettings
            {
                PageSize = 4
            };
            _servicesService = new ServicesService(_servicesRepository, _mapper,
                                                   Microsoft.Extensions.Options.Options.Create(_settings));

            //seed with initial data
            new UsersSeeds(context).Seed();
            new ServicesSeeds(context).Seed();
        }
        public UsersServiceTests()
        {
            //create InMemory DbContext
            var builder = new DbContextOptionsBuilder <AlgDbContext>();

            builder.UseInMemoryDatabase("UsersServiceTests")
            .EnableSensitiveDataLogging();
            var options = builder.Options;
            var context = new AlgDbContext(options);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            //init UsersService
            _usersRepository = new UsersRepository(context);
            var config = new MapperConfiguration(c =>
            {
                c.AddProfile <UsersMapProfile>();
            });
            var mapper = config.CreateMapper();

            var settings = new JWTSettings
            {
                Secret        = "REPLACE THIT WITH YOUR OWN SECRET STRING",
                TokenValidHrs = 10
            };

            _usersService = new UsersService(_usersRepository, mapper,
                                             Microsoft.Extensions.Options.Options.Create(settings));

            //seed with initial data
            new UsersSeeds(context).Seed();
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IApiVersionDescriptionProvider provider, AlgDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMiddleware <ExceptionsHandlingMiddleware>();

            app.UseCors("Default");

            app.UseHttpsRedirection();
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseSwaggerDocumentation(env, provider, "ALG API documentation");

            //migrate and seed database
            new DbInitializer(context).InitDatabase();
        }
 public ServicesRepository(AlgDbContext context)
 {
     _context = context;
 }
Exemple #5
0
 public ServicesSeeds(AlgDbContext context)
 {
     _context = context;
 }
 public UsersRepository(AlgDbContext context)
 {
     _context = context;
 }
Exemple #7
0
 public UsersSeeds(AlgDbContext context)
 {
     _context = context;
 }