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>(); }
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(); }
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)); }
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)); }
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)); }
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); }
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)); }
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); }
public PerFileSemaphore() { // create a option to simulate a file _options = new JsonStoreOptions(); _factory = new PerFileSemaphoreFactory(_options); }
protected override JsonRepository <Person, int> GetStore(JsonStoreOptions options) { return(new(options)); }
public static string GetFilePath(string fileName) { var options = new JsonStoreOptions(); return(Path.Combine(options.Location, $"{fileName}.{options.FileExtension}")); }
protected abstract T GetStore(JsonStoreOptions options);
protected override ConcurrentJsonRepository <Person, int> GetStore(JsonStoreOptions options) { return(new(options, new LocalSemaphoreFactory())); }
/// <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; }
public void CreateRepositoryWithWrongKeyType_Id() { var options = new JsonStoreOptions(); Assert.Throws <InvalidJsonRepositoryKeyException>(() => new JsonRepository <Person, string>(options)); }