Ejemplo n.º 1
0
        public async Task DeleteItemByRef()
        {
            var repo = new VolatileRepository <Item>(() => null);

            var items = Enumerable.Range(0, 1000).Select(i => new Item {
                Value = Convert.ToString(i, 2)
            }).ToArray();

            await repo.Write(items);

            var to_remove = (await repo.Read(i => i.Value.Contains("101"))).First();

            await repo.Delete(to_remove);

            (await repo.Read(i => i.Value.Contains("101"))).Should().NotContain(i => i.ID == to_remove.ID);
        }
Ejemplo n.º 2
0
        public async Task CreateReadUpdateDelete()
        {
            var repo = new VolatileRepository <Item>(() => null);

            var items = Enumerable.Range(0, 1000).Select(i => new Item {
                Value = Convert.ToString(i, 2)
            }).ToArray();

            await repo.Write(items);

            var results = await repo.Read();

            results.Should().BeEquivalentTo(items);

            await repo.Delete(r => r.Value.Contains("111"));

            results = await repo.Read();

            results.Should().BeEquivalentTo(items.Where(i => !i.Value.Contains("111")).ToArray());

            await repo.Update(
                results
                .Where(i => i.Value.Contains("000"))
                .Select(i => { i.Value = "Hello"; return(i); })
                .ToArray());

            results = await repo.Read();

            var expected =
                items
                .Where(i => !i.Value.Contains("111"))
                .Select(i => { if (i.Value.Contains("000"))
                               {
                                   i.Value = "Hello";
                               }
                               return(i); })
                .ToArray();

            results.Should().BeEquivalentTo(expected);
        }