public async Task Delete_RootObject_from_database_by_URL() { var options = new DbContextOptionsBuilder <GeolocationDbContext>() .UseInMemoryDatabase(databaseName: "Delete_RootObject_from_database_by_IP") .Options; var urlAddress = "www.onet.pl"; var mockLogger = Mock.Of <ILogger <RootObjectRepository> >(); using (var context = new GeolocationDbContext(options)) { var repository = new RootObjectRepository(mockLogger, context); await repository.Add(new RootObject { URLValue = urlAddress }); } using (var context = new GeolocationDbContext(options)) { Assert.AreEqual(1, context.Geolocations.Count()); Assert.AreEqual(urlAddress, context.Geolocations.Single().URLValue); } using (var context = new GeolocationDbContext(options)) { var repository = new RootObjectRepository(mockLogger, context); await repository.RemoveByURL(urlAddress); Assert.AreEqual(0, context.Geolocations.Count()); } }
public async Task Delete_RootObject_from_database_by_IP() { var options = new DbContextOptionsBuilder <GeolocationDbContext>() .UseInMemoryDatabase(databaseName: "Delete_RootObject_from_database_by_IP") .Options; var ipAddress = "89.64.27.223"; var mockLogger = Mock.Of <ILogger <RootObjectRepository> >(); using (var context = new GeolocationDbContext(options)) { var repository = new RootObjectRepository(mockLogger, context); await repository.Add(new RootObject { ip = ipAddress }); } using (var context = new GeolocationDbContext(options)) { Assert.AreEqual(1, context.Geolocations.Count()); Assert.AreEqual(ipAddress, context.Geolocations.Single().ip); } using (var context = new GeolocationDbContext(options)) { var repository = new RootObjectRepository(mockLogger, context); await repository.RemoveByIP(ipAddress); Assert.AreEqual(0, context.Geolocations.Count()); } }
public BitcoinUnitOfWork(string connectionString) { _context = new BitcoinContext(connectionString); BpiRepository = new BpiRepository(_context); EURRepository = new EURRepository(_context); GBPRepository = new GBPRepository(_context); RootObjectRepository = new RootObjectRepository(_context); TimeRepository = new TimeRepository(_context); USDRepository = new USDRepository(_context); }
public void GetTransactionsSinceLastInterval_should_return_transactions() { try { const int RESULTLIMIT = 1000; IApiEndPointRepository apiConfigurator = new ApiEndPointRepository(); IHashingAlgorithm hashingAlgorithm = new Murmur3(); var newRelicService = new NewRelicService(apiConfigurator); var rootObject = newRelicService.GetTransactionsSinceLastInterval( new TimeSpan(1, 0, 0, 0), RESULTLIMIT); Assert.IsNotNull(rootObject); Assert.IsTrue(rootObject?.results?.Any()); if (rootObject?.results != null) { foreach (var result in rootObject?.results) { if (result?.events != null) { foreach (var eventObj in result?.events) { eventObj.HashedByteValue = eventObj.GenerateHashedByteValue(hashingAlgorithm); } } } } RootObjectRepository rootObjectRepository = new RootObjectRepository(); rootObjectRepository.SaveRootObject(rootObject); Assert.IsNotNull(rootObject); } catch (Exception ex) { Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); } }
public async Task Add_RootObject_to_database() { var options = new DbContextOptionsBuilder <GeolocationDbContext>() .UseInMemoryDatabase(databaseName: "Add_RootObject_to_database") .Options; var mockLogger = Mock.Of <ILogger <RootObjectRepository> >(); var id = Guid.NewGuid(); using (var context = new GeolocationDbContext(options)) { var repository = new RootObjectRepository(mockLogger, context); await repository.Add(new RootObject { Id = id }); } using (var context = new GeolocationDbContext(options)) { Assert.AreEqual(1, context.Geolocations.Count()); Assert.AreEqual(id, context.Geolocations.Single().Id); } }