public void BuildFileMergeInfoTest(string testCase, string[] arguments, FileMergeInfo expectedResult, Exception expectedException)
        {
            try
            {
                var argumentParser = new ArgumentParser
                {
                    Arguments = arguments
                };
                var actual = argumentParser.BuildFileMergeInfo();

                Assert.NotNull(testCase);

                Assert.Equal(expectedResult.DestinationFile, actual.DestinationFile);

                if (expectedResult.FileParts?.Any() ?? false)
                {
                    for (int i = 0; i < expectedResult.FileParts.Count(); i++)
                    {
                        Assert.Equal(expectedResult.FileParts.ElementAt(i), actual.FileParts.ElementAt(i));
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Equal(expectedException.GetType().FullName, ex.GetType().FullName);
                Assert.Equal(expectedException.Message, ex.Message);
            }
        }
Exemplo n.º 2
0
        public async Task MergerTest(string testCase, FileMergeInfo fileMergingInfo, Exception expectedException)
        {
            try
            {
                var merger = new Merger(Configuration)
                {
                    FileMergingInfo = fileMergingInfo
                };

                await merger.MergeFiles();

                Assert.NotNull(testCase);
                Assert.True(File.Exists(fileMergingInfo.DestinationFile));

                FileInfo destinationFile = new FileInfo(fileMergingInfo.DestinationFile);
                var      filePartsSize   = fileMergingInfo.FileParts.Sum(x => new FileInfo(x).Length);
                Assert.Equal(filePartsSize, destinationFile.Length);
            }
            catch (Exception ex)
            {
                if (expectedException == null)
                {
                    throw;
                }

                Assert.Equal(expectedException.GetType().FullName, ex.GetType().FullName);
                Assert.Equal(expectedException.Message, ex.Message);
            }
            finally
            {
                if (File.Exists(fileMergingInfo.DestinationFile))
                {
                    File.Delete(fileMergingInfo.DestinationFile);
                }
            }
        }