示例#1
0
        protected TestWithSqlServer()
        {
            var config = new ConfigurationBuilder().AddInMemoryCollection(
                new Dictionary <string, string>
            {
                { "ConnectionStrings:DefaultConnection", TestConnectionString },
            }
                );

            var configuration = config.Build();

            _serviceProvider = new ServiceCollection()
                               .AddSingleton <IConfiguration>(configuration)
                               .AddScoped <IChatService, ChatService>()
                               .AddSingleton <IDbCommands, DbCommands>()
                               .AddDbContext <TestAppDbContext>(options => options.UseSqlServer(TestConnectionString))
                               .BuildServiceProvider();

            lock (_lock)
            {
                if (!_databaseInitialized)
                {
                    _dbContext = _serviceProvider.GetRequiredService <TestAppDbContext>();

                    _dbContext.Database.EnsureDeleted();
                    _dbContext.Database.Migrate();
                    _databaseInitialized = true;
                }
            }
        }
示例#2
0
 public WorkerController(TestAppDbContext context, UserManager <Worker> userManager, SignInManager <Worker> signManager, CacheService cacheService, GenericCacheService <Worker> gservice)
 {
     this.context  = context;
     _signManager  = signManager;
     _userManager  = userManager;
     _cacheService = cacheService;
     _gservice     = gservice;
 }
示例#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, TestAppDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                //drop and re-create the test db
                context.Database.EnsureDeleted();
                context.Database.Migrate();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "PowerDiary TestApp API V1");
                //c.RoutePrefix = string.Empty;
            });

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

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
示例#4
0
 public bool PostAddEmail([FromBody] EmailBinding data)
 {
     try
     {
         using (var context = new TestAppDbContext())
         {
             UserEmail user = new UserEmail();
             user.Email  = data.email;
             user.UserId = data.userId;
             context.UserEmails.Add(user);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#5
0
 public bool PostUser1([FromBody] RegisterBinding data)
 {
     try
     {
         using (var context = new TestAppDbContext())
         {
             User user = new User();
             user.Name        = data.name;
             user.Email       = data.email;
             user.Password    = data.password;
             user.Phone       = data.phone;
             user.DateOfBirth = data.dateOfBirth;
             user.Image       = data.image.FileName;
             context.Users.Add(user);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#6
0
 public dynamic Get()
 {
     try
     {
         using (var context = new TestAppDbContext())
         {
             var users = context.Users.Select(u => new
             {
                 u.Id,
                 u.Email,
                 u.Name,
                 u.Phone,
                 u.DateOfBirth,
                 u.UserEmails
             }).ToList();
             return(users);
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
示例#7
0
        public bool PostUserLogin([FromBody] UserLoginBinding data)
        {
            try
            {
                using (var context = new TestAppDbContext())
                {
                    var user = context.Users.FirstOrDefault(u => u.Email == data.email && u.Password == data.password);

                    if (user != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public ChatEventTypesService(TestAppDbContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#9
0
 public ChatService_Tests()
 {
     _chatService = _serviceProvider.GetRequiredService <IChatService>();
     _dbContext   = _serviceProvider.GetRequiredService <TestAppDbContext>();
 }
示例#10
0
 public ChatService(TestAppDbContext dbContext, IDbCommands dbCommands)
 {
     _dbContext  = dbContext;
     _dbCommands = dbCommands;
 }
示例#11
0
 public WorkerController(TestAppDbContext context, UserManager <Worker> userManager, SignInManager <Worker> signManager)
 {
     this.context = context;
     _signManager = signManager;
     _userManager = userManager;
 }
示例#12
0
 public CompanyController(TestAppDbContext context)
 {
     this.context = context;
 }