public void InsertThenUpdate_ShouldReflectChanges() { // Arrange var dummyId = 7; var dbModel = new ReportLinesModel() { ReportId = dummyId, OssIndexId = _OssIndexId, }; // Act var newId = new ReportLinesRepository(AppState.ConnectionString) .Insert(dbModel); dummyId = 8; var dbModel2 = new ReportLinesRepository(AppState.ConnectionString) .Select(newId); dbModel2.ReportId = dummyId; new ReportLinesRepository(AppState.ConnectionString) .Update(dbModel2); var actualValue = new ReportLinesRepository(AppState.ConnectionString) .Select(newId) .ReportId; // Assert Assert.AreEqual(dummyId, actualValue); }
public void InsertBulkThenSelectList_ShouldEqualTwo() { // Arrange var dummyId = 7; var listPoco = new List <ReportLinesModel>() { new ReportLinesModel() { ReportId = dummyId, OssIndexId = _OssIndexId, }, new ReportLinesModel() { ReportId = dummyId, OssIndexId = _OssIndexId, } }; // Act new ReportLinesRepository(AppState.ConnectionString).InsertBulk(listPoco); var actualValue = new ReportLinesRepository(AppState.ConnectionString) .SelectList() .Where(x => x.ReportId.Equals(dummyId)) .ToList() .Count; // Assert Assert.IsTrue(actualValue >= 2); }
public void InsertAndSelect_ShouldEqualInserted() { // Arrange var dbModel = new ReportLinesModel() { ReportId = 7, OssIndexId = _OssIndexId, }; var expectedValue = new ReportLinesRepository(AppState.ConnectionString) .Insert(dbModel); // Act var actualValue = new ReportLinesRepository(AppState.ConnectionString) .Select(expectedValue) .Id; // Assert Assert.AreEqual(expectedValue, actualValue); }
public void InsertAndDelete_ShouldNoLongerExistAfterDelete() { // Arrange var expectedValue = 0; var dbModel = new ReportLinesModel() { ReportId = 7, OssIndexId = _OssIndexId, }; // Act var newId = new ReportLinesRepository(AppState.ConnectionString).Insert(dbModel); new ReportLinesRepository(AppState.ConnectionString).Delete(newId); var actualValue = new ReportLinesRepository(AppState.ConnectionString) .Select(newId) .Id; // Assert Assert.AreEqual(expectedValue, 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); }