public void Convert_正常系_UnitTestResultとTestDefinitionが複数件存在する場合()
        {
            // Arrange
            var target = new TestRun
            {
                Results         = GetUnitTestResultTestData().Take(3).ToArray(),
                TestDefinitions = GetTestDefinitionTestData().Take(3).ToArray()
            };

            // Act
            var result = ConvertLogic.Convert(target);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Count);

            var i = 0;

            foreach (var resultLine in result)
            {
                var expectedResult = target.Results.Skip(i).First();
                AssertUnitTestResult(expectedResult, resultLine);

                var expectedDefinition = target.TestDefinitions.Skip(i).First();
                AssertTestDefinition(expectedDefinition, resultLine);
                i++;
            }
        }
        public void Convert_正常系_UnitTestResultとTestDefinitionが1件存在する場合()
        {
            // Arrange
            var target = new TestRun
            {
                Results         = GetUnitTestResultTestData().Take(1).ToArray(),
                TestDefinitions = GetTestDefinitionTestData().Take(1).ToArray()
            };

            // Act
            var result = ConvertLogic.Convert(target);

            // Assert
            Assert.NotNull(result);
            Assert.Single(result);

            var resultLine     = result.First();
            var expectedResult = target.Results.First();

            AssertUnitTestResult(expectedResult, resultLine);

            var expectedDefinition = target.TestDefinitions.First();

            AssertTestDefinition(expectedDefinition, resultLine);
        }
        public void Convert_正常系_対象が全て空の場合()
        {
            // Arrange
            var target = new TestRun();

            // Act
            var result = ConvertLogic.Convert(target);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.Count == 0);
        }
        public void Convert_正常系_UnitTestResultのみ存在する場合()
        {
            // Arrange
            var target = new TestRun
            {
                Results = GetUnitTestResultTestData().Take(1).ToArray()
            };

            // Act
            var result = ConvertLogic.Convert(target);

            // Assert
            Assert.NotNull(result);
            Assert.Single(result);

            var resultLine = result.First();
            var expected   = target.Results.First();

            AssertUnitTestResult(expected, resultLine);
        }
        private void btnGo_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder    = null;
            string        messageText      = "";
            Exception     exceptionDetails = null;
            string        path             = tbPath.Text;
            string        fileName         = tbFileName.Text;
            ReadFileLogic readFileLogic    = null;

            try
            {
                logicBase = new LogicBase();
                ResetListBox();
                if ((string.IsNullOrEmpty(path) == false) && (string.IsNullOrEmpty(fileName) == false))
                {
                    readFileLogic = new ReadFileLogic();
                    if (readFileLogic != null)
                    {
                        readFileLogic.PathName = path;
                        readFileLogic.FileName = fileName;
                        readFileLogic.ReadFile();
                        messageText = ConvertLogic.ConvertPersonallyIdentifiableInformationToString(readFileLogic.personallyIdentifiableInformation);
                        listBox1.Items.Add(messageText);

                        logicBase.personallyIdentifiableInformation = new PersonallyIdentifiableInformation(readFileLogic.personallyIdentifiableInformation);

                        foreach (BloodGlucose bloodGlucose in readFileLogic.listBloodGlucose)
                        {
                            messageText = ConvertLogic.ConvertBloodGlucoseToString(bloodGlucose);
                            listBox1.Items.Add(messageText);
                            logicBase.listBloodGlucose.Add(new BloodGlucose(bloodGlucose));
                        }

                        foreach (PulseAndOxygen pulseAndOxygen in readFileLogic.listPulseAndOxygen)
                        {
                            messageText = ConvertLogic.ConvertPulseAndOxygenToString(pulseAndOxygen);
                            listBox1.Items.Add(messageText);
                            logicBase.listPulseAndOxygen.Add(new PulseAndOxygen(pulseAndOxygen));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                stringBuilder    = new StringBuilder();
                exceptionDetails = exception;

                while (exceptionDetails != null)
                {
                    messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n";

                    stringBuilder.Append(messageText);

                    exceptionDetails = exceptionDetails.InnerException;
                }

                messageText = stringBuilder.ToString();

                listBox1.Items.Add(messageText);
            }
        }
Esempio n. 6
0
        public static bool Main(string[] args)
        {
            var result = true;

            if (args == null || args.Length == 0)
            {
                Console.WriteLine();
                Console.WriteLine("TrxConverter");
                Console.WriteLine();
                Console.WriteLine("Description:");
                Console.WriteLine("    Visual Studio テスト結果ファイル (.trx) を CSVファイルに変換するツール");
                Console.WriteLine();
                Console.WriteLine("Usage:");
                Console.WriteLine("    TrxConverter.ConsoleApp.exe <変換対象.trxファイルパス>");
                Console.WriteLine();
                return(true);
            }

            try
            {
                Console.WriteLine(".trxファイルの変換処理を開始します。");

                var input = args.First();
                Console.WriteLine($"対象ファイルパス: [{input}]");

                var fileName = Path.GetFileName(input);
                if (fileName == null)
                {
                    throw new ArgumentException("変換対象となる.trxファイルパスを指定して下さい");
                }

                var dirName = Path.GetDirectoryName(input);
                if (string.IsNullOrEmpty(dirName))
                {
                    dirName = Directory.GetCurrentDirectory();
                }

                foreach (var file in Directory.EnumerateFiles(dirName, fileName, SearchOption.TopDirectoryOnly))
                {
                    using (var fs = new FileStream(file, FileMode.Open))
                        using (var xml = XmlReader.Create(fs))
                        {
                            var serializer = new XmlSerializer(typeof(TestRun));
                            var model      = (TestRun)serializer.Deserialize(xml);

                            var report = ConvertLogic.Convert(model);

                            using (var writer = new StreamWriter($"{Path.GetFileNameWithoutExtension(file)}.csv", false, new UTF8Encoding(true)))
                                using (var csv = new CsvWriter(writer, CultureInfo.CurrentCulture))
                                {
                                    csv.Context.RegisterClassMap <TestReportLineMap>();
                                    csv.WriteRecords(report);
                                }
                        }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("変換処理に失敗しました。");
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                result = false;
            }

            Console.WriteLine("変換処理が完了しました。");
            return(result);
        }