Ejemplo n.º 1
0
        public void Updating_item_updates_corresponding_file()
        {
            //Arrange
            var id     = 42;
            var story1 = new Story
            {
                Id = id
            };

            var story2 = new Story
            {
                Id = id
            };

            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);

            datastore.AddOrUpdateAsync(new[] { story1 }).Wait();
            //Act
            datastore.UpdateAsync(id, story2).Wait();

            //Assert
            storagefolder.Verify(mock => mock.ReplaceFileWithItemAsync(id.ToString(), It.IsAny <FileStoredStory>()));
        }
Ejemplo n.º 2
0
        public void Trying_to_set_an_item_with_id_that_differs_from_supplied_id_throws_InvalidOperationException()
        {
            //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
            };

            datastore.AddOrUpdateAsync(new[] { story1 }).Wait(); //first, the id must exist

            var story2 = new Story
            {
                Id = 314
            };

            //Act &&
            //Assert
            Assert.ThrowsExceptionAsync <InvalidOperationException>(() => datastore.UpdateAsync(id, story2)).Wait();
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public void Trying_to_update_non_existing_item_throws_InvalidOperationException()
        {
            //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
            };


            //Act &&
            //Assert
            Assert.ThrowsExceptionAsync <InvalidOperationException>(() => datastore.UpdateAsync(id, story1)).Wait();
        }