Пример #1
0
        public async Task The_same_item_is_not_added_twiceAsync()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            var items = new[]
            {
                new Bucket()
            };

            //Act
            await datastore.AddOrUpdateAsync(items);

            var countAfterFirstAdd = (await datastore.GetAllAsync()).Count();

            datastore.AddOrUpdateAsync(items).Wait();
            var countAfterSecondAdd = (await datastore.GetAllAsync()).Count();

            //Assert
            Assert.AreEqual(countAfterFirstAdd, countAfterSecondAdd);
        }
Пример #2
0
        public async Task Added_items_can_be_retrievedAsync()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            var items = new[]
            {
                new Bucket()
            };

            //Act
            await datastore.AddOrUpdateAsync(items);

            var retrieved = await datastore.GetAllAsync();

            //Assert
            Assert.AreEqual(items.Single(), retrieved.Single());
        }
Пример #3
0
        public async Task Stories_are_fetched_from_StoryStoreAsync()
        {
            //Arrange
            var containedStoryIds = new[] { 31415, 2718 };
            var bucket            = new FileStoredBucket
            {
                Id       = 42,
                StoryIds = containedStoryIds.AsEnumerable()
            };

            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            storagefolder
            .Setup(fake => fake.GetStoredItemsAsync())
            .Returns(MakeAsync(new[] { bucket }));

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);


            //Act
            await datastore.InitializeAsync();

            _ = await datastore.GetAllAsync();

            //Assert
            storyStore.Verify(mock => mock.GetAsync(containedStoryIds), Times.Once);
        }
Пример #4
0
        public async Task Initialize_stores_the_retrieved_items_in_the_DataStoreAsync()
        {
            //Arrange
            var bucket = new FileStoredBucket
            {
                Id = 42
            };

            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            storagefolder
            .Setup(fake => fake.GetStoredItemsAsync())
            .Returns(MakeAsync(new[] { bucket }));

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            //Act
            await datastore.InitializeAsync();

            //Assert
            var result = datastore.GetAllAsync().Result;

            Assert.AreEqual(bucket.Id, result.Single().Id);
        }
Пример #5
0
        public async Task Contained_stories_from_StoryStore_are_added_to_BucketAsync()
        {
            //Arrange
            var id     = 42;
            var bucket = new FileStoredBucket
            {
                Id = id
            };

            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            storagefolder
            .Setup(fake => fake.GetStoredItemsAsync())
            .Returns(MakeAsync(new[] { bucket }));

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var stories = new[]
            {
                new Story {
                    Id = 4
                },
                new Story
                {
                    Id = 2
                }
            };
            var storyStore = new Mock <IDataStore <Story> >();

            storyStore
            .Setup(fake => fake.GetAsync(It.IsAny <IEnumerable <int> >()))
            .ReturnsAsync(stories);

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            //Act
            await datastore.InitializeAsync();

            var buckets = await datastore.GetAllAsync();

            //Assert
            var storiesOfBucket = buckets.Single().Stories;

            Assert.AreEqual(stories.Length, storiesOfBucket.Count);
            foreach (var fakeStory in stories)
            {
                var bucketContainsStory = storiesOfBucket.Any(returnedStory => returnedStory.Id == fakeStory.Id);
                Assert.IsTrue(bucketContainsStory, $"Story with id {fakeStory.Id} not found in bucket!");
            }
        }
Пример #6
0
        public async Task The_same_Id_exists_only_onceAsync()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            var id = 42;

            var items = new[]
            {
                new Bucket
                {
                    Id = id
                },
                new Bucket
                {
                    Id = id
                }
            };

            //Act
            await datastore.AddOrUpdateAsync(items);

            var retrieved = await datastore.GetAllAsync();

            //Assert
            Assert.AreEqual(1, retrieved.Count(item => item.Id == id));
        }
Пример #7
0
        public async Task Update_updates_the_existing_itemAsync()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            var id      = 42;
            var bucket1 = new Bucket
            {
                Id = id
            };

            var bucket2 = new Bucket
            {
                Id = id
            };

            datastore.AddOrUpdateAsync(new[] { bucket1 }).Wait();

            //Act
            await datastore.UpdateAsync(id, bucket2);

            var retrieved = await datastore.GetAllAsync();

            //Assert
            Assert.AreEqual(bucket2, retrieved.Single(item => item.Id == id));
        }
Пример #8
0
        public async Task Adding_the_same_Id_again_updates_exising_item_to_the_newAsync()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredBucket> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

            folderprovider
            .Setup(fake => fake.GetStorageFolder <FileStoredBucket>(It.IsAny <string>()))
            .Returns(storagefolder.Object);

            var storyStore = new Mock <IDataStore <Story> >();

            var datastore = new InMemoryFileBackedBucketDataStore(folderprovider.Object, storyStore.Object);

            var id    = 42;
            var item1 = new Bucket
            {
                Id = id
            };

            var item2 = new Bucket
            {
                Id = id
            };

            //Act
            await datastore.AddOrUpdateAsync(new[] { item1 });

            await datastore.AddOrUpdateAsync(new[] { item2 });

            var retrieved = await datastore.GetAllAsync();

            //Assert
            Assert.AreEqual(item2, retrieved.Single(item => item.Id == id));
        }