public async Task OptionIsDisabled()
        {
            // load the file
            var store  = new JsonStore <Person>(_options);
            var person = await store.ReadAsync();

            // change it using another instance
            var options2 = new JsonStoreOptions(_options)
            {
                ThrowOnSavingChangedFile = false
            };
            var store2 = new JsonStore <Person>(options2);

            person.FullName = Guid.NewGuid().ToString("N");
            await store2.SaveAsync(person);

            // change it again and try to save
            var newPerson = Constants.GetPerson();

            newPerson.FullName = Guid.NewGuid().ToString("N");
            await store2.SaveAsync(newPerson);

            // ensure the file was saved
            var readContent = await store2.ReadAsync();

            Assert.Equal(newPerson, readContent);
        }
Beispiel #2
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();
        }
        public async Task SaveAndRead()
        {
            var person = new Person
            {
                FullName  = Guid.NewGuid().ToString(),
                BirthDate = DateTime.UnixEpoch
            };
            await _store.SaveAsync(person);

            var readPerson = await _store.ReadAsync();

            Assert.Equal(person, readPerson);
        }
Beispiel #5
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));
        }
Beispiel #6
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));
        }
Beispiel #7
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));
        }
        public async Task FileNotLoaded()
        {
            // change the content without load the file must be ignored
            var store  = new JsonStore <Person>(_options);
            var person = Constants.GetPerson();

            person.FullName = Guid.NewGuid().ToString("N");

            await store.SaveAsync(person);

            // ensure the file was saved
            var readContent = await store.ReadAsync();

            Assert.Equal(person, readContent);
        }
        public async Task FileWasLoaded()
        {
            // load the file
            var store  = new JsonStore <Person>(_options);
            var person = await store.ReadAsync();

            // change it using another instance
            await Task.Run(async() =>
            {
                var store2      = new JsonStore <Person>(_options);
                person.FullName = Guid.NewGuid().ToString("N");
                await store2.SaveAsync(person);
            });

            // change it again and try to save
            var newPerson = Constants.GetPerson();

            newPerson.FullName = Guid.NewGuid().ToString("N");

            await Assert.ThrowsAsync <FileChangedException>(() => store.SaveAsync(newPerson));
        }