public async Task when_getting_element_by_id_in_multiple_threads_then_succeeds()
        {
            int count = 100;
            InMemoryRepository <FooStorageObject> repository = new InMemoryRepository <FooStorageObject>();
            ConcurrentBag <FooStorageObject>      bag        = new ConcurrentBag <FooStorageObject>();
            List <Task> createTasks = new List <Task>();

            for (int i = 1; i < count; i++)
            {
                createTasks.Add(Task.Run(() =>
                {
                    FooStorageObject item = new FooStorageObject {
                        Id = $"Foo{i}", Value = i
                    };

                    repository.Create(item);
                }));
            }

            await Task.WhenAll(createTasks);

            Random random = new Random();

            Parallel.For(fromInclusive: 1, toExclusive: count + 1, body: i =>
            {
                int value = random.Next(minValue: 1, maxValue: count);
                FooStorageObject element = repository.Read($"Foo{value}");

                bag.Add(element);
            });

            count.Should().Be(bag.Count);
        }
        public async Task when_getting_element_by_id_in_multiple_threads_then_succeeds()
        {
            var count       = 100;
            var repository  = new InMemoryRepository <FooStorageObject>();
            var bag         = new ConcurrentBag <FooStorageObject>();
            var createTasks = new List <Task>();

            for (var i = 1; i < count; i++)
            {
                createTasks.Add(Task.Run(() =>
                {
                    var item = new FooStorageObject {
                        Id = $"Foo{i}", Value = i
                    };

                    repository.Create(item);
                }));
            }

            await Task.WhenAll(createTasks);

            var random = new Random();

            Parallel.For(fromInclusive: 1, toExclusive: count + 1, body: i => {
                var value   = random.Next(minValue: 1, maxValue: count);
                var element = repository.Read($"Foo{value}");

                bag.Add(element);
            });

            Assert.Equal(count, bag.Count);
        }
        public void when_deleting_item_with_invalid_id_then_does_not_delete()
        {
            InMemoryRepository <FooStorageObject> repository = new InMemoryRepository <FooStorageObject>();
            FooStorageObject item = new FooStorageObject {
                Id = "Foo1", Value = 1
            };

            repository.Create(item);
            repository.Delete("Foo2");
            repository.ReadAll().Should().NotBeEmpty();
        }
        public void when_deleting_item_then_succeeds()
        {
            InMemoryRepository <FooStorageObject> repository = new InMemoryRepository <FooStorageObject>();
            FooStorageObject item = new FooStorageObject {
                Id = "Foo1", Value = 1
            };

            repository.Create(item);
            repository.Delete("Foo1");
            repository.ReadAll().Should().BeEmpty();
        }
        public void when_deleting_item_with_invalid_id_then_does_not_delete()
        {
            var repository = new InMemoryRepository <FooStorageObject>();
            var item       = new FooStorageObject {
                Id = "Foo1", Value = 1
            };

            repository.Create(item);
            repository.Delete("Foo2");

            Assert.NotEmpty(repository.ReadAll());
        }
        public void when_deleting_item_then_succeeds()
        {
            var repository = new InMemoryRepository <FooStorageObject>();
            var item       = new FooStorageObject {
                Id = "Foo1", Value = 1
            };

            repository.Create(item);
            repository.Delete("Foo1");

            Assert.Empty(repository.ReadAll());
        }
        public void when_updating_item_then_succeeds()
        {
            InMemoryRepository <FooStorageObject> repository = new InMemoryRepository <FooStorageObject>();
            FooStorageObject item = new FooStorageObject {
                Id = "Foo1", Value = 1
            };

            repository.Create(item);

            item.Value = 2;

            repository.Update(item);

            2.Should().Be(repository.ReadAll().First().Value);
        }
        public void when_updating_item_then_succeeds()
        {
            var repository = new InMemoryRepository <FooStorageObject>();
            var item       = new FooStorageObject {
                Id = "Foo1", Value = 1
            };

            repository.Create(item);

            item.Value = 2;

            repository.Update(item);

            Assert.Equal(2, repository.ReadAll().First().Value);
        }