Пример #1
0
        public void WhenBadDateFormatShouldFail()
        {
            var yaml = @"
ignore:
    commits-before: bad format date
";

            using var reader = new StringReader(yaml);
            Should.Throw <YamlException>(() => ConfigSerialiser.Read(reader));
        }
Пример #2
0
        public static string GetEffectiveConfigAsString(string workingDirectory, IFileSystem fileSystem)
        {
            var config        = Provide(workingDirectory, fileSystem);
            var stringBuilder = new StringBuilder();

            using (var stream = new StringWriter(stringBuilder))
            {
                ConfigSerialiser.Write(config, stream);
                stream.Flush();
            }
            return(stringBuilder.ToString());
        }
        private static Config ReadConfig(string workingDirectory, IFileSystem fileSystem)
        {
            var configFilePath = GetConfigFilePath(workingDirectory, fileSystem);

            if (fileSystem.Exists(configFilePath))
            {
                var readAllText = fileSystem.ReadAllText(configFilePath);
                return(ConfigSerialiser.Read(new StringReader(readAllText)));
            }

            return(new Config());
        }
Пример #4
0
        public void WhenNotInConfigShouldHaveDefaults()
        {
            var yaml = @"
next-version: 1.0
";

            using var reader = new StringReader(yaml);
            var config = ConfigSerialiser.Read(reader);

            config.Ignore.ShouldNotBeNull();
            config.Ignore.ShAs.ShouldBeEmpty();
            config.Ignore.Before.ShouldBeNull();
        }
Пример #5
0
        public void WhenNotInConfigShouldHaveDefaults()
        {
            var yaml = @"
            next-version: 1.0
            ";

            using (var reader = new StringReader(yaml))
            {
                var config = ConfigSerialiser.Read(reader);

                Assert.That(config.Ignore, Is.Not.Null);
                Assert.That(config.Ignore.Hashes, Is.Empty);
                Assert.That(config.Ignore.Before, Is.Null);
            }
        }
Пример #6
0
    public void VerifyInit()
    {
        var config  = typeof(Config);
        var aliases = config.GetProperties()
                      .Where(p => p.GetCustomAttribute <ObsoleteAttribute>() == null)
                      .Select(p => ((YamlMemberAttribute)p.GetCustomAttribute(typeof(YamlMemberAttribute))).Alias);
        var writer = new StringWriter();

        ConfigSerialiser.WriteSample(writer);
        var initFile = writer.GetStringBuilder().ToString();

        foreach (var alias in aliases)
        {
            initFile.ShouldContain(alias);
        }
    }
Пример #7
0
        public void ShouldSupportsOtherSequenceFormat()
        {
            var yaml = @"
ignore:
    sha: 
        - b6c0c9fda88830ebcd563e500a5a7da5a1658e98
        - 6c19c7c219ecf8dbc468042baefa73a1b213e8b1
";

            using var reader = new StringReader(yaml);
            var config = ConfigSerialiser.Read(reader);

            config.Ignore.ShouldNotBeNull();
            config.Ignore.ShAs.ShouldNotBeEmpty();
            config.Ignore.ShAs.ShouldBe(new[] { "b6c0c9fda88830ebcd563e500a5a7da5a1658e98", "6c19c7c219ecf8dbc468042baefa73a1b213e8b1" });
        }
Пример #8
0
        public void CanDeserialize()
        {
            var yaml = @"
ignore:
    sha: [b6c0c9fda88830ebcd563e500a5a7da5a1658e98]
    commits-before: 2015-10-23T12:23:15
";

            using var reader = new StringReader(yaml);
            var config = ConfigSerialiser.Read(reader);

            config.Ignore.ShouldNotBeNull();
            config.Ignore.ShAs.ShouldNotBeEmpty();
            config.Ignore.ShAs.ShouldBe(new[] { "b6c0c9fda88830ebcd563e500a5a7da5a1658e98" });
            config.Ignore.Before.ShouldBe(DateTimeOffset.Parse("2015-10-23T12:23:15"));
        }
Пример #9
0
        public void ShouldSupportsOtherSequenceFormat()
        {
            var yaml = @"
            ignore:
                sha: 
                    - b6c0c9fda88830ebcd563e500a5a7da5a1658e98
                    - 6c19c7c219ecf8dbc468042baefa73a1b213e8b1
            ";

            using (var reader = new StringReader(yaml))
            {
                var config = ConfigSerialiser.Read(reader);

                Assert.That(config.Ignore, Is.Not.Null);
                Assert.That(config.Ignore.Hashes, Is.Not.Empty);
                Assert.That(config.Ignore.Hashes, Is.EqualTo(new[] { "b6c0c9fda88830ebcd563e500a5a7da5a1658e98", "6c19c7c219ecf8dbc468042baefa73a1b213e8b1" }));
            }
        }
Пример #10
0
        public void CanDeserialize()
        {
            var yaml = @"
            ignore:
                sha: [b6c0c9fda88830ebcd563e500a5a7da5a1658e98]
                commits-before: 2015-10-23T12:23:15
            ";

            using (var reader = new StringReader(yaml))
            {
                var config = ConfigSerialiser.Read(reader);

                Assert.That(config.Ignore, Is.Not.Null);
                Assert.That(config.Ignore.Hashes, Is.Not.Empty);
                Assert.That(config.Ignore.Hashes, Is.EqualTo(new[] { "b6c0c9fda88830ebcd563e500a5a7da5a1658e98" }));
                Assert.That(config.Ignore.Before, Is.EqualTo(DateTimeOffset.Parse("2015-10-23T12:23:15")));
            }
        }
        private static string GetOverrideConfigHash(Config overrideConfig)
        {
            if (overrideConfig == null)
            {
                return(string.Empty);
            }

            // Doesn't depend on command line representation and
            // includes possible changes in default values of Config per se.
            var stringBuilder = new StringBuilder();

            using (var stream = new StringWriter(stringBuilder))
            {
                ConfigSerialiser.Write(overrideConfig, stream);
                stream.Flush();
            }
            var configContent = stringBuilder.ToString();

            return(GetHash(configContent));
        }