Exemple #1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) {
                var context = serviceScope.ServiceProvider.GetRequiredService <BloggingDbContext>();
                // context.Database.Migrate();
                var dbCreatedCurrently = context.Database.EnsureCreated();
                if (env.IsDevelopment() && dbCreatedCurrently)
                {
                    var seed = new TestDataSeeder(Configuration);
                    seed.SeedData();
                }
            }

            app.UseRouting();

            app.UseCors("default");
            app.UseMultiTenant();

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

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers()
                .RequireAuthorization("ApiScope");
            });
        }
        protected override void Seed(WFPICTContext context)
        {
            // Look for any students.
            if (context.Users.Any())
            {
                return; // DB has been seeded
            }

            string companyName   = "Encore Piano Moving";
            var    alreayCompany =
                context.Companys.FirstOrDefault(
                    x => x.Name.Equals(companyName, StringComparison.InvariantCultureIgnoreCase));

            if (alreayCompany == null)
            {
                // Company Settings
                var companyID = Guid.NewGuid();
                var company   = new Company()
                {
                    Id        = companyID,
                    CreatedAt = DateTime.Now,
                    Name      = companyName,
                    Details   = "Encore Piano Moving",
                    Logo      = "logo.jpg",
                    WebSite   = "www.movemypiano.com",
                    //Theme = (int) ThemesEnum.Default
                };
                context.Companys.Add(company);
                context.SaveChanges();

                SecurityDataSeeder.Seed(context);

                TestDataSeeder.Seed(context);
            }
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            var startupLogger = loggerFactory.CreateLogger <Startup>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // // Create DB on startup
            // using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
            // {
            //     serviceScope.ServiceProvider.GetService<SkillustratorContext>().Database.Migrate();
            // }
            CircuitBreaker.Do(() => TestDataSeeder.InitializeDeficiencyDatabaseAsync(app.ApplicationServices, true).Wait(), TimeSpan.FromSeconds(3));

            // Not currently seeding anything, fix
            var applicantSeeder = new TestDataSeeder();

            applicantSeeder.SeedAsync(app.ApplicationServices).Wait();
            startupLogger.LogInformation("Data seed completed.");
        }
Exemple #4
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) {
                var context = serviceScope.ServiceProvider.GetRequiredService <BloggingDbContext>();
                // context.Database.Migrate();
                var dbCreatedCurrently = context.Database.EnsureCreated();
                if (env.IsDevelopment() && dbCreatedCurrently)
                {
                    var seed = new TestDataSeeder(Configuration);
                    seed.SeedData();
                }
            }

            app.UseRouting();

            app.UseCors("default");
            app.UseMultiTenant();

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

            app.UseSwagger();
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "The API V1");
                c.OAuthClientId("the_api_swagger");
                c.OAuthAppName("The API - Swagger");
                // c.OAuthUsePkce();
            });

            app.UseEndpoints(endpoints =>
            {
                // endpoints.MapControllers().RequireAuthorization("ApiScope");
                endpoints.MapControllers();
            });
        }
Exemple #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            string dbName = "TestDb";

            services.AddDbContext <AppDbContext>(options => options.UseInMemoryDatabase(databaseName: dbName));

            //var context = services.GetRequiredService<AppDbContext>();

            var builder = new DbContextOptionsBuilder <AppDbContext>();

            builder.UseInMemoryDatabase <AppDbContext>(dbName);

            var context = new AppDbContext(builder.Options);

            if (!context.Movies.Any())
            {
                var tds = new TestDataSeeder(context);
                tds.SeedData();
            }

            var config = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile(new AutoMapperProfileConfiguration()));
            var mapper = config.CreateMapper();

            services.AddSingleton(mapper);
            services.AddTransient <IMovieService, MovieService>();
            services.AddTransient <IMovieRepository, MovieRepository>();
            services.AddTransient <IUnitOfWork, UnitOfWork>();
            services.AddTransient <IMemoryCache, MemoryCache>();
        }
Exemple #6
0
        public async Task AddCircleTopicReply_AddNotificationToCommentOwner()
        {
            var repliedUserName   = "******";
            int repliedUserNameId = TestDataSeeder.GetAppUserIdByName(repliedUserName);
            var commentOwnerName  = "TestMember1";
            int commentOwnerId    = TestDataSeeder.GetAppUserIdByName(commentOwnerName);

            await LoginByUser(repliedUserName);

            var contents = BuildStringContent(new CircleTopicCommentReply()
            {
                AppUserId = repliedUserNameId, CommentId = 1, Reply = "Reply Test"
            });
            var response = await _client.PostAsync("/api/circletopiccommentreply", contents);

            response.EnsureSuccessStatusCode();

            //Check if notification was created
            await LoginByUser(commentOwnerName);

            var notifications = await _client.GetAsync("/api/notification/" + commentOwnerId);

            string result = await notifications.Content.ReadAsStringAsync();

            Assert.Contains("notificationType\":" + (int)NotificationEnum.NewCircleCommentReplyByMember, result);
        }
Exemple #7
0
        protected override void Seed(ToolTracker.ToolTrackerDbContext context)
        {
            var seeder = new TestDataSeeder();

            seeder.WipeOutData();
            seeder.SeedShops();
            seeder.SeedInmates();
            //seeder.SeedTools();
        }
Exemple #8
0
        private static void Main(/*string[] args*/)
        {
            var seeder = new TestDataSeeder();

            seeder.ClearTables();
            seeder.SeedTables();

            var tutorController = new TutorController();

            tutorController.ListAll();
        }
        private async Task <HttpResponseMessage> participateEvent(string userName, int circleEventId)
        {
            int userId = TestDataSeeder.GetAppUserIdByName(userName);

            await LoginByUser(userName);

            var contents = BuildStringContent(new CircleEventParticipation()
            {
                AppUserId     = userId,
                CircleEventId = circleEventId
            });

            return(await _client.PostAsync("/api/circleeventparticipation", contents));
        }
        public async Task Setup()
        {
            var dbopts = new DbContextOptionsBuilder <DataContext>()
                         .UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=AspNetCoreCQRS;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")
                         .Options;

            Context = new DataContext(dbopts);
            Context.Database.Migrate();
            UnitOfWork = new UnitOfWork(Context);

            Seeder = new TestDataSeeder(Context);
            await Seeder.ClearSeedData();

            await Seeder.Seed();
        }
Exemple #11
0
        private static void SeedDatabase(IWebHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <NorthwindDbContext>();

                    TestDataSeeder.Initialize(context, services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError("An error occurred while seeding the database");
                }
            }
        }
        public async Task AcceptRequest_AddMemberAndNotification()
        {
            //Arrange
            string circleOwnerName = "TestMember1";
            // int ownerUserId = TestData.GetAppUserIdByName(circleOwnerName);
            // int ownerUserId = 11;
            string requestUserName = "******";
            // int requestUserId = 13;
            int requestUserId = TestDataSeeder.GetAppUserIdByName(requestUserName);

            //Act
            var approvingRequest = new CircleRequest {
                AppUserId = requestUserId, CircleId = 1
            };

            //Accept circle request by owner
            await LoginByUser(circleOwnerName);

            var contents = new StringContent(JsonConvert.SerializeObject(approvingRequest), Encoding.UTF8, "application/json");
            var response = await _client.PostAsync("/api/circlemember/approve", contents);

            response.EnsureSuccessStatusCode();
            //Check if a new member was added
            response = await _client.GetAsync("/api/circlemember/" + approvingRequest.CircleId + "/latest");

            response.EnsureSuccessStatusCode();
            var jsonResult = JsonConvert.DeserializeObject <JArray>(await response.Content.ReadAsStringAsync());
            var memberList = jsonResult.ToObject <List <CircleMember> >();

            Assert.True(memberList.Any(ml => ml.AppUserId == requestUserId && ml.CircleId == 1));

            //Check if notification was created
            await LoginByUser(requestUserName);

            var notifications = await _client.GetAsync("/api/notification/" + requestUserId);

            string result = await notifications.Content.ReadAsStringAsync();

            Assert.Contains("notificationType\":" + (int)NotificationEnum.CircleRequestAccepted, result);
        }
Exemple #13
0
 public CIController()
 {
     _testDataSeeder = new TestDataSeeder();
 }
 private void AddTestCode(string expectedCode)
 {
     using var ctx = GetContext();
     TestDataSeeder.AddCode(ctx.DB, expectedCode);
 }