コード例 #1
0
        public void LockingTest()
        {
            Task.Factory.StartNew(() =>
            {
                using (var repo = new FileSystemRepository <TestClass, String, String>("Test", x => Tuple.Create(x.ID, x.StringValue)))
                {
                    var obj = new TestClass("key", "value");
                    repo.Insert(obj);
                    repo.SaveChanges();

                    repo.Remove(obj);
                    repo.SaveChanges();
                }
            });

            Task.Factory.StartNew(() =>
            {
                using (var repo = new FileSystemRepository <TestClass, String, String>("Test", x => Tuple.Create(x.ID, x.StringValue)))
                {
                    var obj = new TestClass("key", "value");
                    repo.Insert(obj);
                    repo.SaveChanges();

                    repo.Remove(obj);
                    repo.SaveChanges();
                }
            });
        }
コード例 #2
0
        public Repository <T> GetRepository <T>()
            where T : class
        {
            //FileStream
            string         fileName   = typeof(T).Name + suffix;
            Repository <T> repository = new FileSystemRepository <T>(fileName, new Func <T, object>(FileKeySelector <T>));

            return(repository);
        }
コード例 #3
0
        public void Backup()
        {
            var implicitKeyRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = "BackupTests/SingleFile"
            });
            var multipleFileRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = "BackupTests/FilePerObject", FileStorageType = FileStorageType.FilePerObject
            });

            var expectedSingleFilePath    = "BackupTests/SingleFile/backup/" + DateTime.Today.ToString("yyyyMMdd");
            var expectedFilePerObjectPath = "BackupTests/FilePerObject/Test/backup/" + DateTime.Today.ToString("yyyyMMdd");

            try
            {
                var obj = new TestClass("key", "value");
                implicitKeyRepo.Insert(obj);
                multipleFileRepo.Insert(obj);

                implicitKeyRepo.SaveChanges();
                multipleFileRepo.SaveChanges();

                implicitKeyRepo.CreateBackup();
                multipleFileRepo.CreateBackup();

                Assert.IsTrue(Directory.Exists(expectedSingleFilePath) && Directory.EnumerateFiles(expectedSingleFilePath).Any());
                Assert.IsTrue(Directory.Exists(expectedFilePerObjectPath) && Directory.EnumerateFiles(expectedFilePerObjectPath).Any());

                // Try again to make sure we don't have any issues with overwriting existing files
                implicitKeyRepo.CreateBackup();
                multipleFileRepo.CreateBackup();

                Assert.IsTrue(Directory.Exists(expectedSingleFilePath) && Directory.EnumerateFiles(expectedSingleFilePath).Any());
                Assert.IsTrue(Directory.Exists(expectedFilePerObjectPath) && Directory.EnumerateFiles(expectedFilePerObjectPath).Any());
            }

            catch (Exception)
            {
                throw;
            }

            finally
            {
                Directory.Delete(expectedSingleFilePath, true);
                Directory.Delete(expectedFilePerObjectPath, true);

                implicitKeyRepo.RemoveAll();
                multipleFileRepo.RemoveAll();

                implicitKeyRepo.SaveChanges();
                multipleFileRepo.SaveChanges();
            }
        }
コード例 #4
0
ファイル: Tests.cs プロジェクト: aomidi/Repository
        public void Standard()
        {
            var implicitKeyRepo = new FileSystemRepository <TestClass>(x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = "Tests/ImplicitKeyRepositories"
            });
            var typedRepo = new FileSystemRepository <TestClass, String>(x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = "Tests/TypedKeyRepositories"
            });
            var explicitKeyRepo = new ExplicitKeyFileSystemRepository <TestClass>(new FileSystemOptions <TestClass> {
                FolderPath = "Tests/ExplicitKeyRepositories"
            });

            StandardTests.All(implicitKeyRepo);
        }
コード例 #5
0
        public void MultipleKeys()
        {
            using (var repo = new FileSystemRepository <TestClass, String, String>("Test", x => Tuple.Create(x.ID, x.StringValue)))
            {
                var obj = new TestClass("key", "value");
                repo.Insert(obj);
                repo.SaveChanges();

                Assert.AreEqual(1, repo.Items.Count());

                repo.Remove(obj);
                repo.SaveChanges();
                Assert.AreEqual(0, repo.Items.Count());
            }
        }
コード例 #6
0
        public void Standard()
        {
            var implicitKeyRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = "Tests/ImplicitKeyRepositories"
            });
            var gzipRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = "Tests/ImplicitKeyRepositories", StreamGenerator = new GZipStreamGenerator(), FileExtension = ".txt.gz"
            });
            var explicitKeyRepo = new ExplicitKeyFileSystemRepository <TestClass>("Test", new FileSystemOptions <TestClass> {
                FolderPath = "Tests/ExplicitKeyRepositories"
            });

            StandardTests.All(implicitKeyRepo, null, explicitKeyRepo);
            StandardTests.All(gzipRepo);
        }
コード例 #7
0
        public void MultipleKeys()
        {
            using (var repo = new FileSystemRepository <TestClass, String, String>("Test", x => Tuple.Create(x.ID, x.StringValue), new FileSystemOptions <TestClass> {
                FolderPath = Path.Combine(basePath, "MultipleKeysTests")
            }))
            {
                var obj = new TestClass("key", "value");
                repo.Insert(obj);
                repo.SaveChanges();

                Assert.AreEqual(1, repo.Items.Count());

                repo.Remove(obj);
                repo.SaveChanges();
                Assert.AreEqual(0, repo.Items.Count());
            }
        }
コード例 #8
0
        public void Standard()
        {
            var implicitKeyRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = Path.Combine(basePath, "Tests/ImplicitKeyRepositories")
            });
            var gzipRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = Path.Combine(basePath, "Tests/ImplicitKeyRepositories"), StreamGenerator = new GZipStreamGenerator(), FileExtension = ".txt.gz"
            });
            var explicitKeyRepo = new ExplicitKeyFileSystemRepository <TestClass>("Test", new FileSystemOptions <TestClass> {
                FolderPath = Path.Combine(basePath, "Tests/ExplicitKeyRepositories")
            });
            var multipleFileRepo = new FileSystemRepository <TestClass>("Test", x => x.ID, new FileSystemOptions <TestClass> {
                FolderPath = Path.Combine(basePath, "Tests/ImplicitKeyRepositories"), FileStorageType = FileStorageType.FilePerObject
            });

            StandardTests.All(implicitKeyRepo, null, explicitKeyRepo);
            StandardTests.All(gzipRepo);
            StandardTests.All(multipleFileRepo);
        }