Exemplo n.º 1
0
        public void The_same_item_is_not_added_twice()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredStory> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

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

            var datastore = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

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

            //Act
            datastore.AddOrUpdateAsync(items).Wait();
            var countAfterFirstAdd = datastore.GetAllAsync().Result.Count();

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

            //Assert
            Assert.AreEqual(countAfterFirstAdd, countAfterSecondAdd);
        }
Exemplo n.º 2
0
        public void The_same_Id_exists_only_once()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredStory> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

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

            var datastore = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

            var id = 42;

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

            //Act
            datastore.AddOrUpdateAsync(items).Wait();
            var retrieved = datastore.GetAllAsync().Result;

            //Assert
            Assert.AreEqual(1, retrieved.Count(item => item.Id == id));
        }
Exemplo n.º 3
0
        public void Initialize_stores_the_retrieved_items_in_the_DataStore()
        {
            //Arrange
            var story = new FileStoredStory
            {
                Id = 42
            };

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

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

            var folderprovider = new Mock <IStorageFolderProvider>();

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

            var datastore = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

            //Act
            datastore.InitializeAsync().Wait();

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

            Assert.AreEqual(story.Id, result.Single().Id);
        }
Exemplo n.º 4
0
        public void Update_updates_the_existing_item()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredStory> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

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

            var datastore = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

            var id     = 42;
            var story1 = new Story
            {
                Id = id
            };

            var story2 = new Story
            {
                Id = id
            };

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

            //Act
            datastore.UpdateAsync(id, story2).Wait();
            var retrieved = datastore.GetAllAsync().Result;

            //Assert
            Assert.AreEqual(story2, retrieved.Single(item => item.Id == id));
        }
Exemplo n.º 5
0
        public void Added_items_can_be_retrieved()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredStory> >();

            var folderprovider = new Mock <IStorageFolderProvider>();

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

            var datastore = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

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

            //Act
            datastore.AddOrUpdateAsync(items).Wait();
            var retrieved = datastore.GetAllAsync().Result;

            //Assert
            Assert.AreEqual(items.Single(), retrieved.Single());
        }