public void CanSaveToRepo() { DataPoint point = new DataPoint(); point.Description = "Description_".RandomLetters(5); DaoRepository repo = new DaoRepository(); repo.Database = new SQLiteDatabase(".\\", nameof(CanSaveToRepo)); repo.AddType <DataPoint>(); repo.AddType <DataRelationship>(); string prop1 = "Hello_".RandomLetters(8); string prop2 = "banana".RandomLetters(4); bool gender = false; point.Property("Name", prop1); point.Property("LastName", prop2); point.Property("Gender", gender); point = repo.Save(point); Expect.IsTrue(point.Cuid.Length > 0); OutLine(point.Cuid); DataPoint retrieved = repo.Query <DataPoint>(dp => dp.Cuid == point.Cuid).FirstOrDefault(); Expect.AreEqual(point.Description, retrieved.Description); Expect.AreEqual(prop1, retrieved.Property("Name").Value); Expect.AreEqual(prop2, retrieved.Property("LastName").Value); Expect.AreEqual(false, retrieved.Property("Gender").Value); Expect.AreEqual(prop1, retrieved.Property <string>("Name")); Expect.AreEqual(prop2, retrieved.Property <string>("LastName")); Expect.AreEqual(gender, retrieved.Property <bool>("Gender")); }
private void GetTestRepoAndResponder(string methodName, out DaoRepository repo, out TestRestResponder responder, out Database database) { string testDirPath = Path.Combine(RuntimeSettings.AppDataFolder, methodName); ILogger logger = GetLogger(); database = new SQLiteDatabase(".", methodName); repo = new DaoRepository(database, logger); repo.WarningsAsErrors = false; repo.AddType <TestStudent>(); repo.AddType <TestClass>(); responder = new TestRestResponder(BamConf.Load(testDirPath), repo, logger); }
public EventSourceService(DaoRepository daoRepository, AppConf appConf, ILogger logger) : base(daoRepository, appConf) { SupportedEvents = new HashSet <string>(); Logger = logger ?? appConf?.Logger ?? Log.Default; DaoRepository?.AddType <EventMessage>(); _listeners = new Dictionary <string, HashSet <EventSubscription> >(); }
public void TestDaoRepoHbGen() { Database db = DataProvider.Current.GetAppDatabaseFor(ProcessApplicationNameProvider.Current, this); DaoRepository repo = new DaoRepository(db) { BaseNamespace = typeof(ShellDescriptor).Namespace, RequireCuid = true }; repo.AddType <ShellDescriptor>(); ShellDescriptor d = new ShellDescriptor() { AssemblyName = "Ass", NameSpace = "Ns" }; d = repo.Save(d); ShellDescriptor queried = repo.Query <ShellDescriptor>(c => c.Id == d.Id).FirstOrDefault(); Expect.IsNotNull(queried); Expect.AreEqual(d, queried); ShellDescriptor retrieved = repo.Retrieve <ShellDescriptor>(d.Id); Expect.IsNotNull(retrieved); Expect.AreEqual(d, retrieved); Pass("yay"); }
protected static DaoRepository GetTestDaoRepository() { DaoRepository daoRepo = new DaoRepository(); daoRepo.WarningsAsErrors = false; daoRepo.Database = new SQLiteDatabase(".\\", "UNITTESTS"); daoRepo.AddType(typeof(TestContainer)); return(daoRepo); }
public ShellGenProvider() { ShellGenerationDatabase = DataProvider.Current.GetAppDatabaseFor(ProcessApplicationNameProvider.Current, this); ShellGenerationRepository = new DaoRepository(ShellGenerationDatabase) { BaseNamespace = typeof(ShellDescriptor).Namespace, RequireCuid = true }; ShellGenerationRepository.AddType <ShellDescriptor>(); }
private void GetRepos(string dbName, out DaoRepository daoRepo, out CachingRepository cachingRepo) { SQLiteDatabase db = new SQLiteDatabase(dbName); daoRepo = new DaoRepository(db); daoRepo.DaoNamespace = $"{typeof(TestMonkey).Namespace}.Dao"; daoRepo.WarningsAsErrors = false; daoRepo.AddType <TestMonkey>(); cachingRepo = new CachingRepository(daoRepo); }
public WriteEventService( IRepository genericRepo, DaoRepository daoRepo, AppConf appConf, MetricsService metricsEvents, SystemEventService notificationEvents) : base(genericRepo, daoRepo, appConf) { _metricsEvents = metricsEvents; _notificationEvents = notificationEvents; daoRepo.AddType <ExternalEventSubscriptionDescriptor>(); }
public void SchemaNameShouldBeUsed() { string schemaName = "TheSchemaName_".RandomLetters(5); DaoRepository repo = new DaoRepository(new SQLiteDatabase(".", MethodBase.GetCurrentMethod().Name), Log.Default, schemaName); repo.WarningsAsErrors = false; repo.AddType <Parent>(); Assembly daoAssembly = repo.GenerateDaoAssembly(); Type type = daoAssembly.GetTypes().FirstOrDefault(t => t.HasCustomAttributeOfType <TableAttribute>()); Expect.IsNotNull(type); Expect.AreEqual(schemaName, Dao.ConnectionName(type)); }
public void SetsModified() { string schemaName = "TheSchemaName_".RandomLetters(5); DaoRepository repo = new DaoRepository(new SQLiteDatabase(".", MethodBase.GetCurrentMethod().Name), Log.Default, schemaName); repo.WarningsAsErrors = false; repo.AddType <TestRepoData>(); TestRepoData data = new TestRepoData(); Expect.IsNull(data.Modified); data = repo.Save(data); Expect.IsNotNull(data.Modified); Expect.IsFalse(data.Modified == default(DateTime)); }
public void CanSaveCatalog() { DaoRepository repo = new DaoRepository(); repo.AddType <CatalogDefinition>(); Organization org = Organization.Public; string catalogName = "MyTestCatalog"; CatalogDefinition catalogDefinition = new CatalogDefinition() { OrganizationKey = org.Key, Name = catalogName }; CatalogDefinition saved = catalogDefinition.SaveByKey <CatalogDefinition>(repo); Expect.AreEqual(saved.Key, catalogDefinition.Key); Expect.AreEqual(saved, catalogDefinition); }
private IEnumerable <Repository> GetTestRepositories() { ConsoleLogger logger = new ConsoleLogger { AddDetails = false, UseColors = true }; logger.StartLoggingThread(); string schemaName = "TheSchemaName_".RandomLetters(5); DaoRepository daoRepo = new DaoRepository(new SQLiteDatabase(".", nameof(RepoQueryTest)), logger, schemaName); daoRepo.WarningsAsErrors = false; daoRepo.AddType(typeof(KeyHashRepoTestData)); yield return(daoRepo); CachingRepository cachingRepo = new CachingRepository(daoRepo, logger); yield return(cachingRepo); }
public void ShouldQueryCacheTest() { ConsoleLogger logger = new ConsoleLogger { AddDetails = false, UseColors = true }; logger.StartLoggingThread(); string schemaName = "TheSchemaName_".RandomLetters(5); DaoRepository repo = new DaoRepository(new SQLiteDatabase(".", nameof(ShouldQueryCacheTest)), logger, schemaName); repo.AddType(typeof(TestData)); CachingRepository cachingRepo = new CachingRepository(repo, logger); TestData data = new TestData { Name = "Bryan", SerialNumber = "12345A", OtherInformation = "is having an existential crisis" }; data.Save <TestData>(cachingRepo); bool?queriedSource = false; bool?queriedCache = false; cachingRepo.SubscribeOnce(nameof(CachingRepository.QueriedSource), (o, a) => { OutLineFormat("Queried source: {0}", ConsoleColor.Yellow, a.PropertiesToLine()); queriedSource = true; }); cachingRepo.SubscribeOnce(nameof(CachingRepository.QueriedCache), (o, a) => { OutLineFormat("Queried cache: {0}", ConsoleColor.Green, a.PropertiesToLine()); queriedCache = true; }); IEnumerable <TestData> result = cachingRepo.Query <TestData>(td => td.SerialNumber.Equals(data.SerialNumber)); Expect.AreEqual(1, result.Count()); result = cachingRepo.Query <TestData>(td => td.SerialNumber.Equals(data.SerialNumber)); Expect.AreEqual(1, result.Count()); Expect.IsTrue(queriedSource.Value, "didn't query source"); Expect.IsTrue(queriedCache.Value, "didn't query cache"); }
public void SavingKeyHashRepoDataShouldntDuplicate() { ConsoleLogger logger = new ConsoleLogger { AddDetails = false, UseColors = true }; logger.StartLoggingThread(); string schemaName = "TheSchemaName_".RandomLetters(5); DaoRepository repo = new DaoRepository(new SQLiteDatabase(".", nameof(SavingKeyHashRepoDataShouldntDuplicate)), logger, schemaName); repo.WarningsAsErrors = false; repo.AddType(typeof(KeyHashRepoTestData)); CachingRepository cachingRepo = new CachingRepository(repo, logger); string nameOne = 32.RandomLetters(); string valueOne = 16.RandomLetters(); KeyHashRepoTestData one = new KeyHashRepoTestData { Name = nameOne, SomeOtherUniqueProperty = valueOne }; KeyHashRepoTestData two = new KeyHashRepoTestData { Name = nameOne, SomeOtherUniqueProperty = valueOne }; Expect.AreEqual(one, two); one.Save <KeyHashRepoTestData>(cachingRepo); var queryParams = new { Name = nameOne }; cachingRepo.Cache <KeyHashRepoTestData>(queryParams); List <KeyHashRepoTestData> retrieved = cachingRepo.Query <KeyHashRepoTestData>(queryParams).ToList(); Expect.AreEqual(1, retrieved.Count); two.Save <KeyHashRepoTestData>(cachingRepo); retrieved = cachingRepo.Query <KeyHashRepoTestData>(queryParams).ToList(); Expect.AreEqual(1, retrieved.Count); }
public override void AddType(Type type) { DaoRepository.AddType(type); base.AddType(type); }
public UnitTestRunListener(string resultDirectory, string resultFileName) { DaoRepository = new DaoRepository(new SQLiteDatabase(resultDirectory, resultFileName)); DaoRepository.AddType(typeof(TestResult)); DaoRepository.EnsureDaoAssemblyAndSchema(); }
public RepositoryChunkStorage(DataSettings dataSettings, ILogger logger = null) { DataSettings = dataSettings; Repository = new DaoRepository(); Repository.AddType <ChunkData>(); }