public async Task TransferFromJsonToJson_AllDataTransferred()
        {
            var transfer = new DataTransferAction();

            var sourceConfiguration =
                Mocks
                    .Of<IJsonFileSourceAdapterConfiguration>(c =>
                        c.Files == new[] { @"InputData\Test.json" })
                    .First();

            var sinkConfiguration =
                Mocks
                    .Of<IJsonFileSinkAdapterConfiguration>(c => 
                        c.File == @"OutputData\Test.json" &&
                        c.Prettify == true)
                    .First();

            using (var source = await new JsonFileSourceAdapterFactory()
                .CreateAsync(sourceConfiguration, DataTransferContextMock.Instance, CancellationToken.None))
            using (var sink = await new JsonFileSinkAdapterFactory()
                .CreateAsync(sinkConfiguration, DataTransferContextMock.Instance, CancellationToken.None))
            {
                await transfer.ExecuteAsync(source, sink, new DummyTransferStatisticsMock(), CancellationToken.None);
            }

            var resultFile = new FileInfo(@"OutputData\Test.json");
            Assert.IsTrue(resultFile.Exists, TestResources.OutputFileMissing);
            Assert.IsTrue(resultFile.Length > 0, TestResources.OutputFileEmpty);
        }
        public async Task ExecuteAsync_SampleData_Transferred()
        {
            const int NumberOfItems = 10;

            var action = new DataTransferAction();

            var sourceData = SampleData.GetSimpleDataItems(NumberOfItems);
            var sinkMock = new DataSinkAdapterMock();

            using (var source = new DataSourceAdapterMock(sourceData))
            using (var sink = sinkMock)
                await action.ExecuteAsync(source, sink, new DummyTransferStatisticsMock(), CancellationToken.None);

            var receivedData = sinkMock.ReceivedData;

            Assert.IsNotNull(receivedData, TestResources.NullDataInSink);

            CollectionAssert.AreEquivalent(
                sourceData,
                receivedData.ToArray(),
                TestResources.ReceivedDataDoesNotMatch);
        }
        public async Task ExecuteAsync_SampleData_StatisticsPopulated()
        {
            const int NumberOfItems = 10;
            const int ThrowAfter = 5;

            var action = new DataTransferAction();

            var sourceData = SampleData.GetSimpleDataItems(NumberOfItems);

            var transferredCount = 0;
            var sinkMock = new DataSinkAdapterMock(i =>
                {
                    if (++transferredCount > ThrowAfter)
                        throw new Exception();
                });

            var statistics = new InMemoryTransferStatistics(ErrorDetailsProviderMock.Instance);
            statistics.Start();
            using (var source = new DataSourceAdapterMock(sourceData))
            using (var sink = sinkMock)
                await action.ExecuteAsync(source, sink, statistics, CancellationToken.None);
            statistics.Stop();

            var receivedData = sinkMock.ReceivedData;

            Assert.IsNotNull(receivedData, TestResources.NullDataInSink);
            Assert.AreEqual(ThrowAfter, receivedData.Count(), TestResources.InvalidNumberOfDataItems);

            var resultStatistics = statistics.GetSnapshot();
            Assert.AreEqual(ThrowAfter, resultStatistics.Transferred, TestResources.StatisticsInvalidTransferredCount);
            Assert.AreEqual(NumberOfItems - ThrowAfter, resultStatistics.Failed, TestResources.StatisticsInvalidFailedCount);
            Assert.AreNotEqual(TimeSpan.Zero, resultStatistics.ElapsedTime, TestResources.StatisticsElapsedTimeIsEmpty);

            var resultExceptions = resultStatistics.GetErrors();
            Assert.IsNotNull(resultExceptions, TestResources.NullTransferExceptions);
            Assert.AreEqual(NumberOfItems - ThrowAfter, resultExceptions.Count, TestResources.InvalidNumberOfTransferExceptions);
        }