public async Task ReadAllSuccessful()
        {
            var dataSet = FileDataWorker.ReadAll <BasicData>();
            var results = new List <BasicData>();

            await foreach (var data in dataSet)
            {
                results.Add(data);
            }
            Assert.AreSame(ExpectedBasicData, results.ElementAt(0));
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\BasicData\\" + ExpectedBasicData.Id + ".data"),
                                    Times.Once);
        }
        public async Task ReadAllFailsToGetLockWithRetry()
        {
            MockFileStreamer
            .Setup(x => x.GetLockForFile(It.IsAny <string>()))
            .ReturnsAsync(false);
            var dataSet = FileDataWorker.ReadAll <BasicData>();
            var results = new List <BasicData>();

            await foreach (var data in dataSet)
            {
                results.Add(data);
            }
            MockFileStreamer.Verify(x => x.ReadDataFromStream <RetryBasicData>(It.IsAny <string>()), Times.Never);
        }
        public async Task ReadAllFailsDueToReadThrowingAnExceptionWithRetry()
        {
            MockFileStreamer
            .Setup(x => x.ReadDataFromStream <RetryBasicData>(It.IsAny <string>()))
            .Throws <Exception>();
            var dataSet = FileDataWorker.ReadAll <RetryBasicData>();
            var results = new List <RetryBasicData>();

            await foreach (var data in dataSet)
            {
                results.Add(data);
            }
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"),
                                    Times.Exactly(3));
        }
        public async Task ReadAllWhenThereAreNoFiles()
        {
            MockFileStreamer
            .Setup(x => x.GetAllFileNames("Data\\BasicData", "data"))
            .Returns(new List <string>().ToArray());
            var dataSet = FileDataWorker.ReadAll <BasicData>();
            var results = new List <BasicData>();

            await foreach (var data in dataSet)
            {
                results.Add(data);
            }
            Assert.IsEmpty(results);
            MockFileStreamer.Verify(x => x.ReadDataFromStream <BasicData>(It.IsAny <string>()), Times.Never);
        }
        public async Task ReadAllSuccessfulWithRetry()
        {
            MockFileStreamer
            .SetupSequence(x =>
                           x.ReadDataFromStream <RetryBasicData>("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"))
            .Throws <Exception>()
            .ReturnsAsync(ExpectedRetryBasicData);
            var dataSet = FileDataWorker.ReadAll <RetryBasicData>();
            var results = new List <RetryBasicData>();

            await foreach (var data in dataSet)
            {
                results.Add(data);
            }
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"),
                                    Times.Exactly(2));
        }