public async void TestDuplicateUID() { // Arrange var gateway = new Gateway { Id = 1, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }; var device = new Device { Id = 1, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", Gateway = gateway }; var device1 = new Device { Id = 2, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", Gateway = gateway }; var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("device_test_uid"); var db = new GatewayDbContext(options.Options); db.Add(device); db.SaveChanges(); var repo = new DeviceRepository(db); // Act var result = await repo.Create(device1); // Assert Assert.False(result.Status); }
public async void TestUpdate() { // Arrange var gateway = new Gateway { Id = 1, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }; var device = new Device { Id = 1, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", Gateway = gateway }; var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("device_test_update"); var db = new GatewayDbContext(options.Options); // db.RemoveRange(db.Gateways); // await db.SaveChangesAsync(); db.Add(device); db.SaveChanges(); var repo = new DeviceRepository(db); // Act device.Vendor = "Vendor 1"; var result = await repo.Update(device); // Assert Assert.True(result.Status); Assert.Equal("Vendor 1", ((Device)result.Entity).Vendor); }
public AuthLogger( GatewayDbContext dbContext, SecurityBot securityBot) { _dbContext = dbContext; _securityBot = securityBot; }
/// <summary> /// Initializes a new instance of the <see cref="DBWriteAuditEventDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database context.</param> public DBWriteAuditEventDelegate( ILogger <DBWriteAuditEventDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
public async void TestFindAll() { // Arrange var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("device_test_findall"); var db = new GatewayDbContext(options.Options); var gateway = new Gateway { Id = 1, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }; var device = new Device { Id = 1, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", GatewayId = 1 }; var data = new List <Device> { device, new Device { Id = 2, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", GatewayId = 1 }, new Device { Id = 3, CreatedDate = new DateTime(), Status = Status.Online, UID = 1, Vendor = "Vendor", GatewayId = 1 } }; db.Add(gateway); db.AddRange(data); db.SaveChanges(); var repo = new DeviceRepository(db); // Act var result = await repo.FindAll(); // Assert Assert.Contains(device, result); }
/// <summary> /// Initializes a new instance of the <see cref="DBDrugLookupDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the databaase.</param> public DBDrugLookupDelegate( ILogger <DBDrugLookupDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
public async void TestGet() { // Arrange var gateway = new Gateway { Id = 1, Name = "BBB", IPv4 = "192.168.4.12", SerialNumber = "sdsd" }; var data = new List <Gateway> { gateway, new Gateway { Id = 2, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }, new Gateway { Id = 3, Name = "asd", IPv4 = "127.0.0.1", SerialNumber = "qdsfs" }, }; var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("gateway_test_get"); var db = new GatewayDbContext(options.Options); db.AddRange(data); db.SaveChanges(); var repo = new GatewayRepository(db); var loggerMock = new Mock <ILogger <GatewayController> >(); var controller = new GatewayController(repo, loggerMock.Object); // Act var result = await controller.Get(); // Assert Assert.Contains(gateway, result); }
/// <summary> /// Initializes a new instance of the <see cref="DBMessagingVerificationDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBMessagingVerificationDelegate( ILogger <DBMessagingVerificationDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
public async void TestFindById() { // Arrange var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("gateway_test_findbyid"); var db = new GatewayDbContext(options.Options); // db.RemoveRange(db.Gateways); // await db.SaveChangesAsync(); var gateway = new Gateway { Id = 1, Name = "BBB", IPv4 = "192.168.4.12", SerialNumber = "sdsd" }; var data = new List <Gateway> { gateway, new Gateway { Id = 2, Name = "ZZZ", IPv4 = "127.0.0.1", SerialNumber = "qwe123" }, new Gateway { Id = 3, Name = "asd", IPv4 = "127.0.0.1", SerialNumber = "qdsfs" }, }.AsQueryable(); db.AddRange(data); await db.SaveChangesAsync(); var repo = new GatewayRepository(db); // Act var result = await repo.FindById(1); // Assert Assert.Equal("BBB", result.Name); }
/// <summary> /// Initializes a new instance of the <see cref="DBEmailDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBEmailDelegate( ILogger <DBEmailDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
public CardPaymentController( GatewayDbContext dbContext, ICardAuthorisation cardAuthoriser) { _dbContext = dbContext; _cardAuthoriser = cardAuthoriser; }
/// <summary> /// Initializes a new instance of the <see cref="DBBetaRequestDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBBetaRequestDelegate( ILogger <DBBetaRequestDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="DBUserDelegateDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBUserDelegateDelegate( ILogger <DBFeedbackDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="DBUserPreferenceDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBUserPreferenceDelegate( ILogger <DBProfileDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="DBApplicationSettingsDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database context.</param> public DBApplicationSettingsDelegate( ILogger <DBApplicationSettingsDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="CloseAccountJob"/> class. /// </summary> /// <param name="configuration">The configuration to use.</param> /// <param name="logger">The logger to use.</param> /// <param name="profileDelegate">The profile delegate.</param> /// <param name="emailService">The email service.</param> /// <param name="authDelegate">The OAuth2 authentication service.</param> /// <param name="userAdminDelegate">The AccessManagement userAdmin delegate.</param> /// <param name="dbContext">The db context to use.</param> public CloseAccountJob( IConfiguration configuration, ILogger <CloseAccountJob> logger, IUserProfileDelegate profileDelegate, IEmailQueueService emailService, IAuthenticationDelegate authDelegate, IUserAdminDelegate userAdminDelegate, GatewayDbContext dbContext) { this.configuration = configuration; this.logger = logger; this.profileDelegate = profileDelegate; this.emailService = emailService; this.authDelegate = authDelegate; this.userAdminDelegate = userAdminDelegate; this.dbContext = dbContext; this.profilesPageSize = this.configuration.GetValue <int>($"{JobKey}:{ProfilesPageSizeKey}"); this.hoursBeforeDeletion = this.configuration.GetValue <int>($"{JobKey}:{HoursDeletionKey}") * -1; this.emailTemplate = this.configuration.GetValue <string>($"{JobKey}:{EmailTemplateKey}"); IConfigurationSection?configSection = configuration?.GetSection(AuthConfigSectionName); this.tokenUri = configSection.GetValue <Uri>(@"AuthTokenUri"); this.tokenRequest = new ClientCredentialsTokenRequest(); configSection.Bind(this.tokenRequest); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { this.logger.LogDebug($"Registering Channel Notification on channel {Channel}"); stoppingToken.Register(() => this.logger.LogInformation($"DBChangeListener exiting...")); try { using var scope = this.services.CreateScope(); GatewayDbContext dbContext = scope.ServiceProvider.GetRequiredService <GatewayDbContext>(); this.CommunicationService = scope.ServiceProvider.GetRequiredService <ICommunicationService>(); NpgsqlConnection con = (NpgsqlConnection)dbContext.Database.GetDbConnection(); con.Open(); con.Notification += this.ReceiveEvent; using NpgsqlCommand cmd = new NpgsqlCommand(); cmd.CommandText = @$ "LISTEN " "{Channel}" ";"; cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.ExecuteNonQuery(); while (!stoppingToken.IsCancellationRequested) { // Wait for the event await con.WaitAsync(stoppingToken).ConfigureAwait(true); } this.logger.LogInformation($"Exiting WaitChannelNotification: {Channel}"); } catch (NpgsqlException e) { this.logger.LogError($"DB Error encountered in WaitChannelNotification: {Channel}\n{e.ToString()}"); } }
/// <summary> /// Initializes a new instance of the <see cref="DBGenericCacheDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBGenericCacheDelegate( ILogger <DBGenericCacheDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="DBLegalAgreementDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBLegalAgreementDelegate( ILogger <DBLegalAgreementDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
/// <summary> /// Initializes a new instance of the <see cref="DBCommunicationDelegate"/> class. /// </summary> /// <param name="logger">Injected Logger Provider.</param> /// <param name="dbContext">The context to be used when accessing the database.</param> public DBCommunicationDelegate( ILogger <DBNoteDelegate> logger, GatewayDbContext dbContext) { this.logger = logger; this.dbContext = dbContext; }
public async void TestNoMoreThan10Devices() { // Arrange var gateway = new Gateway { Id = 1, Name = "wee", IPv4 = "192.168.4.12", SerialNumber = "sdsd", Devices = new List <Device> { new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, new Device { UID = 1 }, } }; var options = new DbContextOptionsBuilder <GatewayDbContext>().UseInMemoryDatabase("gateway_test_devices"); var db = new GatewayDbContext(options.Options); var repo = new GatewayRepository(db); // Act var result = await repo.Create(gateway); // Assert Assert.False(result.Status); }
/// <summary> /// Initializes a new instance of the <see cref="BaseDrugApp{T}"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="parser">The file parser.</param> /// <param name="downloadService">The download utility.</param> /// <param name="configuration">The IConfiguration to use.</param> /// <param name="drugDBContext">The database context to interact with./</param> public BaseDrugApp(ILogger logger, T parser, IFileDownloadService downloadService, IConfiguration configuration, GatewayDbContext drugDBContext) { this.logger = logger; this.parser = parser; this.downloadService = downloadService; this.configuration = configuration; this.drugDbContext = drugDBContext; }
/// <summary> /// Initializes a new instance of the <see cref="DBMigrationsJob"/> class. /// </summary> /// <param name="configuration">The configuration to use.</param> /// <param name="logger">The logger to use.</param> /// <param name="dbContext">The db context to use.</param> public DBMigrationsJob( IConfiguration configuration, ILogger <DBMigrationsJob> logger, GatewayDbContext dbContext) { this.configuration = configuration; this.logger = logger; this.dbContext = dbContext; }
public GrantChecker( GatewayDbContext context, DeveloperApiService developerApiService, ACTokenManager tokenManager) { _dbContext = context; _developerApiService = developerApiService; _tokenManager = tokenManager; }
public Task ClearTimeOutOAuthPack(GatewayDbContext dbContext) { var outDateTime = DateTime.UtcNow - TimeSpan.FromDays(1); var outDateTime2 = DateTime.UtcNow - TimeSpan.FromMinutes(20); dbContext.OAuthPack.Delete(t => t.UseTime < outDateTime); dbContext.OAuthPack.Delete(t => t.CreateTime < outDateTime2); return(dbContext.SaveChangesAsync()); }
public HomeController( IStringLocalizer <HomeController> localizer, GatewayDbContext dbContext, ISessionBasedCaptcha captcha) { _localizer = localizer; _dbContext = dbContext; _captcha = captcha; }
public ApiController( UserManager <GatewayUser> userManager, GatewayDbContext context, ACTokenManager tokenManager) { _userManager = userManager; _dbContext = context; _tokenManager = tokenManager; }
public PasswordController( GatewayDbContext dbContext, ILoggerFactory loggerFactory, UserManager <GatewayUser> userManager, CannonService cannonService) { _dbContext = dbContext; _userManager = userManager; _cannonService = cannonService; _logger = loggerFactory.CreateLogger <ApiController>(); }
public AccountController( ACTokenManager tokenManager, DeveloperApiService apiService, GatewayDbContext dbContext, UserAppAuthManager authManager) { _tokenManager = tokenManager; _apiService = apiService; _dbContext = dbContext; _authManager = authManager; }
public GrantChecker( GatewayDbContext context, DeveloperApiService developerApiService, ACTokenManager tokenManager, AiurCache aiurCache) { _dbContext = context; _developerApiService = developerApiService; _tokenManager = tokenManager; _aiurCache = aiurCache; }