public void InsertAndDelete_ShouldNoLongerExistAfterDelete() { // Arrange var expectedValue = 0; var dbModel = new OssIndexVulnerabilitiesModel() { OssIndexId = _OssIndexId, InsertDate = DateTime.Now, OssId = "earum", Title = "et", Description = "voluptatem", CvssScore = 3983, CvssVector = "quasi", Cve = "deserunt", Reference = "fugit", }; // Act var newId = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString).Insert(dbModel); new OssIndexVulnerabilitiesRepository(AppState.ConnectionString).Delete(newId); var actualValue = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Select(newId) .Id; // Assert Assert.AreEqual(expectedValue, actualValue); }
public void InsertAndSelect_ShouldEqualInserted() { // Arrange var dbModel = new OssIndexVulnerabilitiesModel() { OssIndexId = _OssIndexId, InsertDate = DateTime.Now, OssId = "expedita", Title = "dolor", Description = "cumque", CvssScore = 89, CvssVector = "maxime", Cve = "ut", Reference = "temporibus", }; var expectedValue = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Insert(dbModel); // Act var actualValue = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Select(expectedValue) .Id; // Assert Assert.AreEqual(expectedValue, actualValue); }
public void InsertBulkThenSelectList_ShouldEqualTwo() { // Arrange var expectedValue = 2; var dummyString = Guid.NewGuid().ToString().Replace("-", ""); var listPoco = new List <OssIndexVulnerabilitiesModel>() { new OssIndexVulnerabilitiesModel() { OssIndexId = _OssIndexId, InsertDate = DateTime.Now, OssId = dummyString, Title = "dolor", Description = "doloribus", CvssScore = 7036, CvssVector = "aperiam", Cve = "iste", Reference = "beatae", }, new OssIndexVulnerabilitiesModel() { OssIndexId = _OssIndexId, InsertDate = DateTime.Now, OssId = dummyString, Title = "totam", Description = "doloribus", CvssScore = 7036, CvssVector = "aperiam", Cve = "iste", Reference = "beatae", } }; // Act new OssIndexVulnerabilitiesRepository(AppState.ConnectionString).InsertBulk(listPoco); var actualValue = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .SelectList() .Where(x => x.OssId.Equals(dummyString)) .ToList() .Count; // Assert Assert.AreEqual(expectedValue, actualValue); }
public void InsertThenUpdate_ShouldReflectChanges() { // Arrange var dummyString = Guid.NewGuid().ToString().Replace("-", ""); var dbModel = new OssIndexVulnerabilitiesModel() { OssIndexId = _OssIndexId, InsertDate = DateTime.Now, OssId = dummyString, Title = "et", Description = "voluptatem", CvssScore = 3983, CvssVector = "quasi", Cve = "deserunt", Reference = "fugit", }; // Act var newId = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Insert(dbModel); dummyString = Guid.NewGuid().ToString().Replace("-", ""); var dbModel2 = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Select(newId); dbModel2.OssId = dummyString; new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Update(dbModel2); var actualValue = new OssIndexVulnerabilitiesRepository(AppState.ConnectionString) .Select(newId) .OssId; // Assert Assert.AreEqual(dummyString, actualValue); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(15); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext <EntityFrameWorkMagicContext>(options => options.UseSqlServer(Configuration.GetConnectionString("EntityFrameWorkMagicContext"))); // DI var connectionString = Environment.GetEnvironmentVariable("SQL_CONNECTION") ?? Configuration.GetConnectionString("ConnMsSQL"); var projectRepository = new ProjectRepository(connectionString); var componentRepository = new ComponentRepository(connectionString); var ossIndexRepository = new OssIndexRepository(connectionString); var ossIndexVulnerabilitiesRepository = new OssIndexVulnerabilitiesRepository(connectionString); var reportRepository = new ReportRepository(connectionString); var reportLinesRepository = new ReportLinesRepository(connectionString); var packageTypeRepository = new PackageTypeRepository(); var httpWebRequestFactory = new HttpWebRequestFactory(); var coordinatesService = new CoordinatesService(); var jsonConvertService = new JsonConvertService(); var ossReportService = new OssReportService( reportRepository, componentRepository, ossIndexRepository, reportLinesRepository, coordinatesService, httpWebRequestFactory, jsonConvertService, ossIndexVulnerabilitiesRepository); services.AddTransient <IProjectRepository>(s => projectRepository); services.AddTransient <IComponentRepository>(s => componentRepository); services.AddTransient <IOssIndexRepository>(s => ossIndexRepository); services.AddTransient <IOssIndexVulnerabilitiesRepository>(s => ossIndexVulnerabilitiesRepository); services.AddTransient <IReportRepository>(s => reportRepository); services.AddTransient <IReportLinesRepository>(s => reportLinesRepository); services.AddTransient <IPackageTypeRepository>(s => packageTypeRepository); services.AddSingleton <IJsonConvertService>(jsonConvertService); services.AddSingleton <ICoordinatesService>(coordinatesService); services.AddSingleton <ISelectListItemService>(new SelectListItemService(projectRepository, packageTypeRepository)); services.AddSingleton <IScoreService>(new ScoreService(reportRepository, reportLinesRepository, ossIndexRepository, ossIndexVulnerabilitiesRepository)); services.AddSingleton <IScoreClassService>(new ScoreClassService()); services.AddSingleton <IBreadcrumbReportService>(new BreadcrumbReportService()); services.AddSingleton <IOssReportService>(ossReportService); services.AddSingleton <IOssIndexStatusService>(new OssIndexStatusService( reportRepository, reportLinesRepository, ossIndexRepository)); services.AddSingleton <IApiCallerService>(new ApiCallerService( ossIndexRepository, ossReportService)); services.AddSingleton <ICoordinatePartsFactory>(new CoordinatePartsFactory()); services.AddSingleton <IHttpWebRequestFactory>(httpWebRequestFactory); }