Ejemplo n.º 1
0
        public async Task ShouldReturnWhatHasBeenSavedAsync()
        {
            var transactionProvider = TransactionProvider.OfType <int>();
            var backend             = DiffstoreDBMS.Embedded(db, transactionProvider, policy);
            var data = CreateSampleData();
            var keys = data.Select(e => e.Key);

            Assert.Empty(await backend.Keys());
            await SaveDataAsync(data, backend);

            Assert.Equal(keys, await backend.Keys());
            var savedData = await backend.GetAll();

            Assert.Equal(data, savedData);
        }
Ejemplo n.º 2
0
        public async Task ShouldAllowSingleWriteAndThrowOnAnyAccessAttemptAsync()
        {
            var transactionProvider = SimulatedWriteLock <int>();
            var backend             = DiffstoreDBMS.Embedded(db, transactionProvider, policy);
            var data = CreateSampleData();

            await SaveDataAsync(data, backend);

            await Assert.ThrowsAsync <ResourceIsBusyException>(
                () => backend.Get(data.First().Key)
                );

            await Assert.ThrowsAsync <ResourceIsBusyException>(
                () => backend.Save(data.First())
                );
        }
Ejemplo n.º 3
0
        public async Task ShouldAllowMultipleReadsAndThrowOnWriteAttemptAsync()
        {
            var transactionProvider = SimulatedReadLock <int>();
            var backend             = DiffstoreDBMS.Embedded(db, transactionProvider, policy);
            var data           = CreateSampleData();
            var firstKey       = data.First().Key;
            var lastKey        = data.Last().Key;
            var readLockedKeys = new[] { firstKey, lastKey };

            await SaveDataAsync(data, backend);

            var firstEntity = await backend.Get(firstKey);

            var firstEntityToo = await backend.Get(firstKey);

            var lastEntity = await backend.Get(lastKey);

            Assert.Equal(readLockedKeys, transactionProvider.InRead);
            Assert.Empty(transactionProvider.InWrite);
            Assert.Equal(firstEntity, firstEntityToo);
            await Assert.ThrowsAsync <ResourceIsBusyException>(() => backend.Save(firstEntity));
        }