Example #1
0
        public void UnPopulatedConfigIsNotValid()
        {
            var raw      = new RawConfiguration();
            var settings = SettingsParser.ParseToSettings(raw);

            Assert.That(settings, Is.Null);
        }
        public void Parse(RawConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException();
            }

            var element = JsonDocument.Parse(configuration.RawValue).RootElement;

            if (!element.TryGetProperty(nameof(EnabledModules), out var enabledModulesElement))
            {
                throw new InvalidConfigurationException("Failed to parse enabled modules list.");
            }

            var enabledModules = new List <Type>();

            foreach (var value in enabledModulesElement.EnumerateArray().Select(x => x.ToString()))
            {
                var type = Utility.GetTypeFromAnyAssembly(value);

                if (type == null)
                {
                    throw new InvalidConfigurationException($"Failed to find module {value}.");
                }

                enabledModules.Add(type);
            }

            EnabledModules = enabledModules;
        }
 /// <summary>
 /// Read osu! profile configuration
 /// </summary>
 /// <param name="path">the configuration file path</param>
 /// <param name="readPassword">should reader read the password information</param>
 /// <exception cref="FileNotFoundException"></exception>
 public OsuProfileConfiguration(string path, bool readPassword = false)
 {
     if (!File.Exists(path))
     {
         throw new FileNotFoundException(path);
     }
     raw = new RawConfiguration(path, readPassword);
 }
Example #4
0
        public void TestConfiguration_InvalidConfiguration()
        {
            /* PRECONDITION */
            Debug.Assert(Config != null);

            /* GIVEN */
            var rawConfig = new RawConfiguration("{ }");

            /* WHEN */
            Assert.ThrowsException <InvalidConfigurationException>(() => Config.Parse(rawConfig));
        }
Example #5
0
        public void TestRawConfiguration_CorrectParamPropagation()
        {
            /* GIVEN */
            const string testString = "TestString";

            /* WHEN */
            var rawConfiguration = new RawConfiguration(testString);

            /* THEN */
            Assert.IsNotNull(rawConfiguration.RawValue);
            Assert.AreEqual(testString, rawConfiguration.RawValue);
        }
Example #6
0
        public void Parse(RawConfiguration configuration)
        {
            var element = JsonDocument.Parse(configuration.RawValue).RootElement;

            try
            {
                UrlSuffix = element.GetProperty(configUrlSuffixField).GetString();
            }
            catch (KeyNotFoundException)
            {
                throw new InvalidConfigurationException("Failed to parse UrlSuffix.");
            }
        }
Example #7
0
        /// <summary>
        ///     Parses the configuration from the provided value
        /// </summary>
        /// <param name="configuration">The configuration <see cref="JsonElement" /> to parse from</param>
        public void Parse(RawConfiguration configuration)
        {
            Debug.Assert(expectedConfiguration != null);
            Debug.Assert(TestResult != null);

            if (configuration != null && expectedConfiguration.RawValue.Equals(configuration.RawValue))
            {
                TestResult.Complete();
            }
            else
            {
                TestResult.Fail(new ArgumentException());
            }
        }
        public void TestDesktopCaptureConfiguration_ParseFailsInvalidMonitorIndex()
        {
            /* PRECONDITION */
            Debug.Assert(Config != null);

            /* GIVEN */
            const string config = @"{
                ""PromptUserForMonitorSelection"": true
            }";

            var rawConfig = new RawConfiguration(config);

            /* WHEN */
            Assert.ThrowsException<InvalidConfigurationException>(() => Config.Parse(rawConfig));
        }
        public void Parse(RawConfiguration configuration)
        {
            var element = JsonDocument.Parse(configuration.RawValue).RootElement;

            try
            {
                SamplingRateInHz = element.GetProperty(nameof(SamplingRateInHz)).GetUInt32();
                Threshold        = element.GetProperty(nameof(Threshold)).GetInt32();
            }
            catch (KeyNotFoundException)
            {
                throw new InvalidConfigurationException(
                          "Failed to parse the sampling rate and the threshold for mouse module.");
            }
        }
Example #10
0
        public void Parse(RawConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException();
            }

            var element = JsonDocument.Parse(configuration.RawValue).RootElement;

            if (!element.TryGetProperty(nameof(RelativeFilePath), out var relativeFilePathElement))
            {
                throw new InvalidConfigurationException("Failed to parse relative file path.");
            }

            RelativeFilePath = new FilePath(relativeFilePathElement.GetString(), true);
        }
        public void Parse(RawConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException();
            }

            var element = JsonDocument.Parse(configuration.RawValue).RootElement;

            Width             = GetUintFromProperty(element, nameof(Width));
            Height            = GetUintFromProperty(element, nameof(Height));
            KiloBitsPerSecond = GetUintFromProperty(element, nameof(KiloBitsPerSecond));
            FramesPerSecond   = GetUintFromProperty(element, nameof(FramesPerSecond));

            if (!element.TryGetProperty(nameof(RelativeFilePath), out var recordingElement))
            {
                throw new InvalidConfigurationException("Failed to parse relative file path.");
            }

            RelativeFilePath = new FilePath(recordingElement.GetString(), true);
        }
        public void TestDesktopCaptureConfiguration_ParseFailsInvalidFPS()
        {
            /* PRECONDITION */
            var expectedConfig = GenerateDefaultExpectedParsedConfig();

            Debug.Assert(expectedConfig != null);
            Debug.Assert(Config != null);

            /* GIVEN */
            var config = @"{
                ""Width"": " + expectedConfig.Width + @",
                ""Height"": " + expectedConfig.Height + @",
                ""KiloBitsPerSecond"": " + expectedConfig.KiloBitsPerSecond + @",
                ""RelativeFilePath"": """ + expectedConfig.RelativeFilePath + @"""
            }";

            var rawConfig = new RawConfiguration(config);

            /* WHEN */
            Assert.ThrowsException <InvalidConfigurationException>(() => Config.Parse(rawConfig));
        }
Example #13
0
        public void TestSessionConfiguration_ParseFailsInvalidDecoder()
        {
            /* PRECONDITION */
            Debug.Assert(Config != null);

            /* GIVEN */
            const string config = @"{
                ""Encoders"": [
                    ""MORRTest.TestHelper.Encoder.TestEncoder""
                ],
                ""Decoders"": [
                    ""MORRTest.TestHelper.Decoder.""
                ],
                ""RecordingDirectory"": ""C:\\""
            }";

            var rawConfig = new RawConfiguration(config);

            /* WHEN */
            Assert.ThrowsException <InvalidConfigurationException>(() => Config.Parse(rawConfig));
        }
Example #14
0
        public void Parse(RawConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException();
            }

            var element = JsonDocument.Parse(configuration.RawValue).RootElement;

            if (!element.TryGetProperty(nameof(MonitorIndex), out var indexElement) ||
                !indexElement.TryGetInt32(out var monitorIndex))
            {
                throw new InvalidConfigurationException("Failed to parse monitor index.");
            }

            MonitorIndex = Index.FromStart(monitorIndex);

            if (!element.TryGetProperty(nameof(PromptUserForMonitorSelection), out var promptElement))
            {
                throw new InvalidConfigurationException("Failed to parse prompt behaviour.");
            }

            PromptUserForMonitorSelection = promptElement.GetBoolean();
        }
Example #15
0
 /// <summary>
 /// Creates a new TestConfiguration which validates the configuration meets the expectedConfiguration.
 /// </summary>
 /// <param name="expectedConfiguration">The expected configuration used for validating the Parse method.</param>
 public TestConfiguration(RawConfiguration expectedConfiguration)
 {
     this.expectedConfiguration = expectedConfiguration;
 }
Example #16
0
        public void Parse(RawConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException();
            }

            var element  = JsonDocument.Parse(configuration.RawValue).RootElement;
            var encoders = new List <Type>();

            if (!element.TryGetProperty(nameof(Encoders), out var encodersElement))
            {
                throw new InvalidConfigurationException("Failed to parse encoders property.");
            }

            foreach (var encoderElement in encodersElement.EnumerateArray())
            {
                if (!TryGetType(encoderElement, out var encoder))
                {
                    throw new InvalidConfigurationException("Failed to parse encoder type.");
                }

                encoders.Add(encoder);
            }

            Encoders = encoders;

            // Specifying a decoder is optional; do not throw an error if the property does not exist
            if (element.TryGetProperty(nameof(Decoders), out var decodersElement))
            {
                var decoders = new List <Type>();

                foreach (var decoderElement in decodersElement.EnumerateArray())
                {
                    if (!TryGetType(decoderElement, out var decoder))
                    {
                        throw new InvalidConfigurationException("Failed to parse decoder type.");
                    }

                    decoders.Add(decoder);
                }

                Decoders = decoders;
            }

            if (!element.TryGetProperty(nameof(RecordingDirectory), out var directoryElement))
            {
                throw new InvalidConfigurationException("Failed to parse directory path.");
            }

            try
            {
                var directoryPath = directoryElement.GetString();
                directoryPath      = Environment.ExpandEnvironmentVariables(directoryPath);
                RecordingDirectory = new DirectoryPath(directoryPath);
            }
            catch (ArgumentException innerException)
            {
                throw new InvalidConfigurationException("Failed to evaluate directory path.", innerException);
            }
        }