public JsonStoreWithNoFile()
        {
            _fileName = Guid.NewGuid().ToString();
            var options = new JsonStoreOptions
            {
                NamingStrategy = new StaticNamingStrategy(_fileName)
            };

            _store = new JsonStore <Person>(options);
        }
        protected AbstractJsonRepositoryTest()
        {
            _path    = Guid.NewGuid().ToString("N");
            _options = new JsonStoreOptions {
                NamingStrategy = new StaticNamingStrategy(_path)
            };

            // create a file with an item
            JsonFileCreator.CreateSingleItemRepository(_options.GetFileFullPath(_path));
        }
        /// <summary>
        ///     Creates a new instance with the given options and key.
        /// </summary>
        /// <param name="options">The options for this repository.</param>
        /// <param name="keyProperty">A <see cref="Func{TResult}" /> to get the object's key.</param>
        /// <param name="semaphoreFactory">The semaphore factory.</param>
        public ConcurrentJsonRepository(
            JsonStoreOptions options,
            Expression <Func <T, TKey> > keyProperty,
            ISemaphoreFactory semaphoreFactory
            ) : base(options)
        {
            GetKeyValue = keyProperty.Compile();

            _semaphore = semaphoreFactory.GetSemaphore <T>();
        }
Exemplo n.º 4
0
        public async Task ClassName()
        {
            var options = new JsonStoreOptions();

            _path = FilePathEvaluator.GetFilePath(nameof(Person));
            var store = new JsonStore <Person>(options);

            await store.SaveAsync(_person);

            Assert.True(File.Exists(_path));
        }
        public ThrowOnSavingChangedFile()
        {
            _fileName = Guid.NewGuid().ToString();

            // create a item and save it
            _options = new JsonStoreOptions {
                NamingStrategy = new StaticNamingStrategy(_fileName)
            };
            var store = new JsonStore <Person>(_options);

            store.SaveAsync(Constants.GetPerson()).Wait();
        }
Exemplo n.º 6
0
        public async Task ClassName_WithGenerics()
        {
            var options = new JsonStoreOptions();

            _path = FilePathEvaluator.GetFilePath(nameof(Person));
            var store = new JsonRepository <Person, int>(options);

            await store.AddAsync(_person);

            await store.SaveChangesAsync();

            Assert.True(File.Exists(_path));
        }
Exemplo n.º 7
0
        public async Task StaticName()
        {
            var options = new JsonStoreOptions {
                NamingStrategy = new StaticNamingStrategy("static-file-name")
            };

            _path = FilePathEvaluator.GetFilePath("static-file-name");
            var store = new JsonStore <Person>(options);

            await store.SaveAsync(_person);

            Assert.True(File.Exists(_path));
        }
Exemplo n.º 8
0
        public async Task JsonExtension()
        {
            var fileName = Guid.NewGuid().ToString();
            var options  = new JsonStoreOptions {
                NamingStrategy = new StaticNamingStrategy(fileName)
            };

            _path = FilePathEvaluator.GetFilePath(fileName, "json");
            var store = new JsonStore <Person>(options);

            await store.SaveAsync(_person);

            Assert.True(File.Exists(_path));
        }
Exemplo n.º 9
0
        public ConcurrentRepositoryCrudOperations()
        {
            _path    = Guid.NewGuid().ToString("N");
            _options = new JsonStoreOptions {
                NamingStrategy = new StaticNamingStrategy(_path)
            };
            _semaphoreFactory = new LocalSemaphoreFactory();
            _tokenSource      = new CancellationTokenSource();

            // create a file with an item
            var filePath = Path.Combine(_options.Location, $"{_path}.json");

            JsonFileCreator.CreateMultiItemsRepository(filePath);
        }
Exemplo n.º 10
0
        public async Task Generated()
        {
            var extension = Guid.NewGuid().ToString("N");
            var options   = new JsonStoreOptions {
                FileExtension = extension
            };

            _path = FilePathEvaluator.GetFilePath(nameof(Person), extension);
            var store = new JsonStore <Person>(options);

            await store.SaveAsync(_person);

            Assert.True(File.Exists(_path));
        }
Exemplo n.º 11
0
        public ConcurrentJsonStoreExistingFile()
        {
            // creates a file
            _fileName         = Guid.NewGuid().ToString();
            _semaphoreFactory = new LocalSemaphoreFactory();

            // create a file
            _options = new JsonStoreOptions
            {
                NamingStrategy = new StaticNamingStrategy(_fileName)
            };
            var filePath = Path.Combine(_options.Location, $"{_fileName}.json");

            JsonFileCreator.CreateStore(filePath);
        }
        public JsonStoreWithExistingFile()
        {
            _fileName = Guid.NewGuid().ToString();
            _content  = Constants.GetPerson();

            // create a file
            var options = new JsonStoreOptions
            {
                NamingStrategy = new StaticNamingStrategy(_fileName)
            };

            JsonFileCreator.CreateStore(options.GetFileFullPath(_fileName));

            JsonFileCreator.CreateStore(_fileName);
            _store = new JsonStore <Person>(options);
        }
Exemplo n.º 13
0
 public PerFileSemaphore()
 {
     // create a option to simulate a file
     _options = new JsonStoreOptions();
     _factory = new PerFileSemaphoreFactory(_options);
 }
Exemplo n.º 14
0
 protected override JsonRepository <Person, int> GetStore(JsonStoreOptions options)
 {
     return(new(options));
 }
Exemplo n.º 15
0
        public static string GetFilePath(string fileName)
        {
            var options = new JsonStoreOptions();

            return(Path.Combine(options.Location, $"{fileName}.{options.FileExtension}"));
        }
 protected abstract T GetStore(JsonStoreOptions options);
Exemplo n.º 17
0
 protected override ConcurrentJsonRepository <Person, int> GetStore(JsonStoreOptions options)
 {
     return(new(options, new LocalSemaphoreFactory()));
 }
Exemplo n.º 18
0
 /// <summary>
 ///     Creates a new instance of <see cref="ConcurrentJsonStore{T}" /> with the given options.
 /// </summary>
 /// <param name="options">The options for this store.</param>
 /// <param name="semaphoreFactory">The semaphore factory.</param>
 public ConcurrentJsonStore(JsonStoreOptions options, ISemaphoreFactory semaphoreFactory) : base(options)
 {
     _semaphoreFactory = semaphoreFactory;
 }
Exemplo n.º 19
0
        public void CreateRepositoryWithWrongKeyType_Id()
        {
            var options = new JsonStoreOptions();

            Assert.Throws <InvalidJsonRepositoryKeyException>(() => new JsonRepository <Person, string>(options));
        }