예제 #1
0
        public void WhenFileDoesNotExistItsContentsIsNull(string applicationArgumentsPropertyName, string errorReportPropertyName)
        {
            StorageManager.InTemporaryDirectory(directory =>
            {
                using (var tempFileManager = new TempFileManager(directory))
                {
                    //Given
                    const string reportName       = "JEU76-12-95FE";
                    var errorReportCreator        = GetErrorReportCreator();
                    const string exceptionMessage = reportName + " exception message";
                    var exception            = new Exception(exceptionMessage);
                    var version              = new Version(1, 2, 3, 4);
                    var applicationArguments = new ApplicationArguments();

                    const string ldrContents  = "Ldr file contents";
                    const string highContents = "High file contents";
                    const string lowContents  = "Low file contents";
                    applicationArguments.DesiredResistance = 8820;
                    applicationArguments.FileType          = "bmp";
                    applicationArguments.High                    = 20;
                    applicationArguments.Low                     = 128;
                    applicationArguments.LcdHeight               = 1440;
                    applicationArguments.LcdWidth                = 2560;
                    applicationArguments.MaskFilePath            = @"c:\user\my\dir\mask.bmp";
                    applicationArguments.OriginalExposureTime    = 1540;
                    applicationArguments.MeasurementsNrOfColumns = 7;
                    applicationArguments.MeasurementsNrOfRows    = 9;
                    if (applicationArgumentsPropertyName != nameof(ApplicationArguments.LdrCalibrationFilePath))
                    {
                        applicationArguments.LdrCalibrationFilePath = tempFileManager.GetTempFile(ldrContents);
                    }
                    if (applicationArgumentsPropertyName != nameof(ApplicationArguments.LcdMeasurementsFilePathHigh))
                    {
                        applicationArguments.LcdMeasurementsFilePathHigh = tempFileManager.GetTempFile(highContents);
                    }
                    if (applicationArgumentsPropertyName != nameof(ApplicationArguments.LcdMeasurementsFilePathLow))
                    {
                        applicationArguments.LcdMeasurementsFilePathLow = tempFileManager.GetTempFile(lowContents);
                    }

                    //When
                    errorReportCreator.CreateReport(version, exception, applicationArguments, directory, reportName);

                    //Then
                    var filesInDirectory = Directory.GetFiles(directory, reportName + "*").ToList();
                    filesInDirectory.Count.Should().Be(1);
                    var report = filesInDirectory.Single();

                    var actualFileContents = File.ReadAllText(report);
                    var actualErrorReport  = JsonConvert.DeserializeObject <ErrorReport>(actualFileContents);

                    var propertyInfo  = typeof(ErrorReport).GetProperty(errorReportPropertyName);
                    var propertyValue = propertyInfo.GetValue(actualErrorReport);
                    propertyValue.Should().BeNull();
                }
            });
        }
예제 #2
0
        private void OpenAsSqlFile()
        {
            var tempFileManager = new TempFileManager();
            var tmpSqlFile      = tempFileManager.GetTempFile(SqlText, "sql");

            Process.Start(tmpSqlFile);
        }
예제 #3
0
        public void SerializedErrorReportContainsCorrectData()
        {
            StorageManager.InTemporaryDirectory(directory =>
            {
                using (var tempFileManager = new TempFileManager(directory))
                {
                    //Given
                    const string reportName       = "JEU76-12-95FE";
                    const string expectedFileName = "JEU76-12-95FE_expected.json";
                    var errorReportCreator        = GetErrorReportCreator();
                    const string exceptionMessage = reportName + " exception message";
                    var exception            = new Exception(exceptionMessage);
                    var version              = new Version(1, 2, 3, 4);
                    var applicationArguments = new ApplicationArguments();

                    const string ldrContents  = "Ldr file contents";
                    const string highContents = "High file contents";
                    const string lowContents  = "Low file contents";
                    applicationArguments.DesiredResistance = 8820;
                    applicationArguments.FileType          = "bmp";
                    applicationArguments.High                        = 20;
                    applicationArguments.Low                         = 128;
                    applicationArguments.LcdHeight                   = 1440;
                    applicationArguments.LcdWidth                    = 2560;
                    applicationArguments.MaskFilePath                = @"c:\user\my\dir\mask.bmp";
                    applicationArguments.OriginalExposureTime        = 1540;
                    applicationArguments.MeasurementsNrOfColumns     = 7;
                    applicationArguments.MeasurementsNrOfRows        = 9;
                    applicationArguments.LdrCalibrationFilePath      = tempFileManager.GetTempFile(ldrContents);
                    applicationArguments.LcdMeasurementsFilePathHigh = tempFileManager.GetTempFile(highContents);
                    applicationArguments.LcdMeasurementsFilePathLow  = tempFileManager.GetTempFile(lowContents);

                    //When
                    errorReportCreator.CreateReport(version, exception, applicationArguments, directory, reportName);

                    //Then
                    var filesInDirectory = Directory.GetFiles(directory, reportName + "*").ToList();
                    filesInDirectory.Count.Should().Be(1);
                    var report = filesInDirectory.Single();

                    var actualFileContents   = File.ReadAllText(report);
                    var expectedFilePath     = StorageManager.GetFullFilePath(expectedFileName);
                    var expectedFileContents = File.ReadAllText(expectedFilePath);
                    actualFileContents.Should().Be(expectedFileContents);
                }
            });
        }