Esempio n. 1
0
        public async Task Should_not_try_to_write_files_if_another_instance_is_reading()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredStory> >();
            var testHelper    = new AsyncReadTester();

            storagefolder
            .Setup(mock => mock.GetStoredItemsAsync())
            .Returns(testHelper.ReadAsync());
            storagefolder
            .Setup(mock => mock.CreateFileForItemAsync(It.IsAny <FileStoredStory>(), It.IsAny <string>()))
            .Callback(() => testHelper.SetOtherFunctionCalled());

            var folderprovider = new Mock <IStorageFolderProvider>();

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


            var datastore1 = new InMemoryFileBackedStoryDataStore(folderprovider.Object);
            var datastore2 = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

            var reading = datastore1.InitializeAsync();

            //Act
            var writing = datastore2.AddOrUpdateAsync(new[] { new Story() });

            testHelper.StopFakeReading();

            await Task.WhenAll(reading, writing);

            //Assert
            Assert.IsFalse(testHelper.CalledWhileInProgress);
        }
Esempio n. 2
0
        public async Task Should_not_load_items_if_another_initialization_is_in_progressAsync()
        {
            //Arrange
            var storagefolder = new Mock <IStorageFolder <FileStoredStory> >();
            var testHelper    = new AsyncReadTester();

            storagefolder
            .Setup(fake => fake.GetStoredItemsAsync())
            .Returns(testHelper.ReadAsync());

            var folderprovider = new Mock <IStorageFolderProvider>();

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


            var datastore = new InMemoryFileBackedStoryDataStore(folderprovider.Object);

            var firstInit = datastore.InitializeAsync();

            //Act
            var secondInit = datastore.InitializeAsync();

            testHelper.StopFakeReading();

            await Task.WhenAll(firstInit, secondInit);

            //Assert
            Assert.IsFalse(testHelper.CalledWhileInProgress);
        }