Example #1
0
        public void InitializeDb()
        {
            var config = new MapperConfiguration(cfg => { cfg.AddProfile <GarbProfile>(); cfg.CreateMap <IssueDto, IssueDto>(); });

            _mapper  = config.CreateMapper();
            _context = TestInitializer.GetSeededContext(_mapper);
        }
 public ComparisonsController(ILogger <ComparisonsController> logger, GarbContext context)
 {
     _logger            = logger;
     _unitOfWork        = new UnitOfWork(context);
     _buildRepo         = _unitOfWork.BuildRepository;
     _screenInBuildRepo = _unitOfWork.ScreenInBuildRepository;
     _comparisonRepo    = _unitOfWork.ComparisonRepository;
 }
Example #3
0
        public void InitializeDb()
        {
            var config = new MapperConfiguration(cfg => { cfg.AddProfile <GarbProfile>(); });

            _mapper = config.CreateMapper();

            _context = TestInitializer.GetSeededContext(_mapper);

            _unitOfWork = new UnitOfWork(_context);
        }
Example #4
0
 public TokenController(GarbContext context, IConfiguration config, ILogger <TokenController> logger)
 {
     _unitOfWork = new UnitOfWork(context);
     _config     = config;
     _logger     = logger;
 }
Example #5
0
 public LocalesController(GarbContext context)
 {
     _unitOfWork        = new UnitOfWork(context);
     _localeRepo        = _unitOfWork.LocaleRepository;
     _screenInBuildRepo = _unitOfWork.ScreenInBuildRepository;
 }
 public BuildsController(GarbContext context)
 {
     _unitOfWork = new UnitOfWork(context);
     _buildRepo  = _unitOfWork.BuildRepository;
 }
Example #7
0
 public DownloadController(GarbContext context, IOptions <StorageHelper> storageHelper)
 {
     _unitOfWork    = new UnitOfWork(context);
     _storageHelper = storageHelper.Value;
 }
 public ProjectsController(GarbContext context)
 {
     _unitOfWork  = new UnitOfWork(context);
     _projectRepo = _unitOfWork.ProjectRepository;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider, GarbContext context)
        {
            //add CORS
            app.UseCors("CorsPolicy");

            // Add Authentication
            app.UseAuthentication();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            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.Use(async(currentContext, next) =>
            {
                await next();

                // If there's no available file and the request doesn't contain an extension, we're probably trying to access a page.
                // Rewrite request to use app root
                if (currentContext.Response.StatusCode == 404 && !Path.HasExtension(currentContext.Request.Path.Value) && !currentContext.Request.Path.Value.StartsWith("/api") && !currentContext.Request.Path.Value.StartsWith("/api-docs") && !currentContext.Request.Path.Value.StartsWith("/store"))
                {
                    currentContext.Request.Path        = "/index.html";
                    currentContext.Response.StatusCode = 200;                     // Make sure we update the status code, otherwise it returns 404
                    await next();
                }
            });

            app.UseSwagger(options =>
            {
                options.RouteTemplate = "api-docs/{documentName}/swagger.json";
            });

            app.UseSwaggerUI(options =>
            {
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.SwaggerEndpoint(
                        $"/api-docs/{description.GroupName}/swagger.json",
                        description.GroupName.ToUpperInvariant());
                    options.RoutePrefix = "api-docs";
                }
            });

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

            app.UseDefaultFiles();

            //app.UseStaticFiles();


            app.UseSpaStaticFiles();

            app.UseSpaStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(
                    Configuration.GetSection("StorageHelperSettings").GetValue <string>("StorageRootFolder")
                    ),
                RequestPath           = new PathString("/store"),
                ServeUnknownFileTypes = true,
                DefaultContentType    = "application/octet-stream",
                OnPrepareResponse     = con =>
                {
                    con.Context.Response.Headers["Access-Control-Allow-Origin"] = "*";
                }
            });

            app.UseMvc();

            //app.UseMvc(routes =>
            //{
            //	routes.MapRoute(
            //		name: "default",
            //		template: "{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");
                }
            });


            StorageHelper.StorageRootFolder = Configuration.GetSection("StorageHelperSettings").GetValue <string>("StorageRootFolder");

            LdapHelper.LdapServer        = Configuration.GetSection("Authentication").GetValue <string>("LdapServer");
            LdapHelper.LdapDomain        = Configuration.GetSection("Authentication").GetValue <string>("LdapDomain");
            LdapHelper.LocalAdminName    = Configuration.GetSection("Authentication").GetValue <string>("LocalAdminName");
            LdapHelper.LocalAdminPwd     = Configuration.GetSection("Authentication").GetValue <string>("LocalAdminPwd");
            LdapHelper.LocalReadOnlyName = Configuration.GetSection("Authentication").GetValue <string>("LocalReadOnlyName");
            LdapHelper.LocalReadOnlyPwd  = Configuration.GetSection("Authentication").GetValue <string>("LocalReadOnlyPwd");

            DbInitializer.Initialize(context);
        }
Example #10
0
        public static GarbContext GetSeededContext(IMapper mapper)
        {
            string project1Name     = "Velocity";
            string project2Name     = "Test2";
            string project1Version0 = "0.1";
            string project1Version1 = "1.0";
            string project2Version1 = "2.2";
            string project2Version2 = "2.3";
            string userName         = TestInitializer.UserName;


            var options = new DbContextOptionsBuilder <GarbContext>()
                          .UseInMemoryDatabase(databaseName: $"GarbTestDb-{Guid.NewGuid()}")
                          .Options;

            var context = new GarbContext(options, mapper);

            var users = new User [] {
                new User {
                    UserName = userName
                }
            };

            foreach (User u in users)
            {
                context.Users.Add(u);
            }
            context.SaveChanges();


            var projects = new Project[] {
                new Project {
                    ProjectName = project1Name
                },
                new Project {
                    ProjectName = project2Name
                }
            };

            foreach (Project p in projects)
            {
                context.Projects.Add(p);
            }
            context.SaveChanges();


            var oldBuilds = new Build[] {
                new Build {
                    ProjectName = project1Name, BuildName = project1Version0
                },
                new Build {
                    ProjectName = project2Name, BuildName = project2Version1
                },
            };

            foreach (Build b in oldBuilds)
            {
                context.Builds.Add(b);
            }
            context.SaveChanges(userName);

            Thread.Sleep(10); // slight delay, so the new builds have new timestamps

            var newBuilds = new Build[] {
                new Build {
                    ProjectName = project1Name, BuildName = project1Version1
                },
                new Build {
                    ProjectName = project2Name, BuildName = project2Version2
                }
            };

            foreach (Build b in newBuilds)
            {
                context.Builds.Add(b);
            }
            context.SaveChanges(userName);

            var locales = new Locale[] {
                new Locale {
                    LocaleCode = "en-US", LocaleName = "English (United States)"
                },
                new Locale {
                    LocaleCode = "pl-PL", LocaleName = "Polish"
                }
            };

            foreach (Locale l in locales)
            {
                context.Locales.Add(l);
            }
            context.SaveChanges();

            string screen1Name = "Install";
            string screen2Name = "Uninstall";

            var screens = new Screen[] {
                new Screen {
                    ProjectName = project1Name, ScreenName = screen1Name
                },
                new Screen {
                    ProjectName = project1Name, ScreenName = screen2Name
                },
            };

            foreach (Screen s in screens)
            {
                context.Screens.Add(s);
            }
            context.SaveChanges();

            var previousBuildId = context.Builds.FirstOrDefault(b => b.BuildName == project1Version0).Id;

            var currentBuildId = context.Builds.FirstOrDefault(b => b.BuildName == project1Version1).Id;

            var screensInBuild = new ScreenInBuild[]
            {
                new ScreenInBuild {
                    ProjectName = project1Name, ScreenName = screen1Name, BuildId = previousBuildId, LocaleCode = "pl-PL"
                },
                new ScreenInBuild {
                    ProjectName = project1Name, ScreenName = screen1Name, BuildId = previousBuildId, LocaleCode = "en-US"
                },
                new ScreenInBuild {
                    ProjectName = project1Name, ScreenName = screen1Name, BuildId = currentBuildId, LocaleCode = "pl-PL"
                },
                new ScreenInBuild {
                    ProjectName = project1Name, ScreenName = screen1Name, BuildId = currentBuildId, LocaleCode = "en-US"
                },
            };

            foreach (ScreenInBuild sb in screensInBuild)
            {
                context.ScreensInBuilds.Add(sb);
            }
            context.SaveChanges(userName);

            var issues = new Issue[] {
                new Issue {
                    ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "en-US", IssueType = IssueType.Hardcode, Identifier = "1", Value = "Hardcode", ModifiedInBuildId = currentBuildId, IssueStatus = IssueStatus.Active
                },
                new Issue {
                    ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.Hardcode, Identifier = "1", Value = "Hardcode", ModifiedInBuildId = currentBuildId, IssueStatus = IssueStatus.Active
                },
                new Issue {
                    ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.Linguistic, Identifier = "2", Value = "Test1", ModifiedInBuildId = currentBuildId, IssueStatus = IssueStatus.FalsePositive
                },
                new Issue {
                    ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.Overlapping, Identifier = "3", Value = "", ModifiedInBuildId = currentBuildId, IssueStatus = IssueStatus.Active, X = 0, Y = 0, Width = 10, Height = 10
                },
                new Issue {
                    ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.CharacterCorruption, Identifier = "7", Value = "C0rrpu4Ed!", ModifiedInBuildId = previousBuildId, IssueStatus = IssueStatus.Active
                },
            };

            foreach (Issue i in issues)
            {
                context.Issues.Add(i);
            }
            context.SaveChanges(userName);



            return(context);
        }
 /// <summary>
 /// Constructor for issues controller
 /// </summary>
 /// <param name="context"></param>
 /// <param name="mapper"></param>
 public IssuesController(GarbContext context, IMapper mapper)
 {
     _unitOfWork = new UnitOfWork(context);
     _mapper     = mapper;
 }
Example #12
0
 public ScreensController(GarbContext context, IOptions <StorageHelper> storageHelper, ILogger <ScreensController> logger)
 {
     _unitOfWork    = new UnitOfWork(context);
     _storageHelper = storageHelper.Value;
     _logger        = logger;
 }