public async Task <bool> WriteFailsToGetLock()
        {
            MockFileStreamer
            .Setup(x => x.GetLockForFile(It.IsAny <string>()))
            .ReturnsAsync(false);
            var result = await FileDataWorker.Write(ExpectedBasicData.Id, ExpectedBasicData);

            MockFileStreamer.Verify(x => x.GetLockForFile(It.IsAny <string>()), Times.Once);
            return(result);
        }
        public async Task <bool> WriteSuccessfulFirstTime()
        {
            var result = await FileDataWorker.Write(ExpectedBasicData.Id, ExpectedBasicData);

            MockFileStreamer.Verify(x => x.GetLockForFile("Data\\BasicData\\" + ExpectedBasicData.Id + ".data"),
                                    Times.Once);
            MockFileStreamer.Verify(
                x => x.WriteDataToStream("Data\\BasicData\\" + ExpectedBasicData.Id + ".data", ExpectedBasicData),
                Times.Once);
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\BasicData\\" + ExpectedBasicData.Id + ".data"),
                                    Times.Never);
            return(result);
        }
        public async Task <bool> WriteFailsToWriteDataToStreamDueToException()
        {
            MockFileStreamer
            .Setup(x => x.WriteDataToStream(It.IsAny <string>(), It.IsAny <BasicData>()))
            .Throws <Exception>();
            var result = await FileDataWorker.Write(ExpectedBasicData.Id, ExpectedBasicData);

            MockFileStreamer.Verify(x => x.GetLockForFile("Data\\BasicData\\" + ExpectedBasicData.Id + ".data"),
                                    Times.Once);
            MockFileStreamer.Verify(
                x => x.WriteDataToStream("Data\\BasicData\\" + ExpectedBasicData.Id + ".data", ExpectedBasicData),
                Times.Once);
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\BasicData\\" + ExpectedBasicData.Id + ".data"),
                                    Times.Once);
            return(result);
        }
        public async Task <bool> WriteFailsToWriteDataToStreamWithRetry()
        {
            MockFileStreamer
            .Setup(x => x.WriteDataToStream(It.IsAny <string>(), It.IsAny <RetryBasicData>()))
            .ReturnsAsync(false);
            var result = await FileDataWorker.Write(ExpectedRetryBasicData.Id, ExpectedRetryBasicData);

            MockFileStreamer.Verify(
                x => x.GetLockForFile("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"),
                Times.Exactly(3));
            MockFileStreamer.Verify(
                x => x.WriteDataToStream("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data",
                                         ExpectedRetryBasicData), Times.Exactly(3));
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"),
                                    Times.Exactly(3));
            return(result);
        }
        public async Task <bool> WriteSuccessfulAfterRetry()
        {
            MockFileStreamer
            .SetupSequence(x => x.WriteDataToStream("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data",
                                                    ExpectedRetryBasicData))
            .ReturnsAsync(false)
            .ReturnsAsync(true);
            var result = await FileDataWorker.Write(ExpectedRetryBasicData.Id, ExpectedRetryBasicData);

            MockFileStreamer.Verify(
                x => x.GetLockForFile("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"),
                Times.Exactly(2));
            MockFileStreamer.Verify(
                x => x.WriteDataToStream("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data",
                                         ExpectedRetryBasicData), Times.Exactly(2));
            MockFileStreamer.Verify(x => x.UnlockFile("Data\\RetryBasicData\\" + ExpectedRetryBasicData.Id + ".data"),
                                    Times.Exactly(1));
            return(result);
        }