Ejemplo n.º 1
0
        public static async Task storage_can_be_migrated_in_a_batch()
        {
            var v1 = new MemoryStorage<Migration>();
            var v2 = new MemoryStorage<Migration>();
            var v3 = new MemoryStorage<Migration>();
            var migrate = new StorageMigration<Migration>(v2, v1);
            var migrateAndDelete = new StorageMigration<Migration>(v3, v1, null, true);

            var data = Enumerable.Range(0, 100).Select(x => new Migration { Id = x, Time = DateTime.UtcNow });
            await Task.WhenAll(from x in data select v1.Put(x)).ConfigureAwait(false);

            Assert.True(data.Select(x => x.Id).SequenceEqual((await v1.All().ToListAsync().ConfigureAwait(false)).Select(x => x.Id)));

            await migrate.MigrateAsync(123).ConfigureAwait(false);

            Assert.True(data.Select(x => x.Id).SequenceEqual((await v1.All().ToListAsync().ConfigureAwait(false)).Select(x => x.Id)));
            Assert.True(data.Select(x => x.Id).SequenceEqual((await v2.All().ToListAsync().ConfigureAwait(false)).Select(x => x.Id)));

            await migrateAndDelete.MigrateAsync(456).ConfigureAwait(false);
            Assert.Equal(0, (await v1.All().ToListAsync()).Count());
            Assert.True(data.Select(x => x.Id).SequenceEqual((await v3.All().ToListAsync().ConfigureAwait(false)).Select(x => x.Id)));
        }
Ejemplo n.º 2
0
        public static async Task storage_can_be_migrated_by_get_many_request()
        {
            var v1 = new MemoryStorage<Migration>();
            var v2 = new MemoryStorage<Migration>();
            var migrate = new StorageMigration<Migration>(v2, v1, null, true);

            var data = Enumerable.Range(0, 1000).Select(x => new Migration { Id = x, Time = DateTime.UtcNow });
            await Task.WhenAll(from x in data select v1.Put(x)).ConfigureAwait(false);

            var a = await migrate.All().ToListAsync().ConfigureAwait(false);
            var b = await v2.All().ToListAsync().ConfigureAwait(false);

            Assert.True(a.SequenceEqual(b));
            Assert.False((await v1.All().ToListAsync().ConfigureAwait(false)).Any());
        }