public void GetVersionFormatted_WithComplexPatternAndAllVarsInformed_ReplaceAllVariables()
        {
            // Arrange
            var pattern = "{MAJOR}[.{MINOR}].{PATCH}[.{BUILD}{REVISION}]";
            var values = new Dictionary<string, string> { { "MAJOR", "1" }, { "MINOR", "2" }, { "PATCH", "4" }, { "BUILD", "B" }, { "REVISION", "9" } };
            var expectedVersion = "1.2.4.B9";

            // Act
            var versionFormatter = new VersionFormatter();
            var result = versionFormatter.GetVersionFormatted(pattern, values);

            // Assert
            Assert.AreEqual(expectedVersion, result);
        }
        public void GetVersionFormatted_WithSimplePatternAndAllVarsInformed_ReplaceAllVariables()
        {
            // Arrange
            var pattern = "{MAJOR}.{MINOR}.{PATCH}";
            var values = new Dictionary<string, string> { { "MAJOR", "1" }, { "MINOR", "2" }, { "PATCH", "4" } };
            var expectedVersion = "1.2.4";

            // Act
            var versionFormatter = new VersionFormatter();
            var result = versionFormatter.GetVersionFormatted(pattern, values);

            // Assert
            Assert.AreEqual(expectedVersion, result);
        }
        public void GetVersionFormatted_WhenCalledWithPatternWithOptionalVarsAndAllValuesThanUsedInMandatoryPart_ReplaceMandatoryAndRemoveOptional()
        {
            // Arrange
            var pattern = "{MAJOR}.{MINOR}.{PATCH}[.{BUILD}{REVISION}]";
            var values = new Dictionary<string, string> { { "MAJOR", "1" }, { "MINOR", "1" }, { "PATCH", "0" } };
            var expectedVersion = "1.1.0";

            // Act
            var versionFormatter = new VersionFormatter();
            var result = versionFormatter.GetVersionFormatted(pattern, values);

            // Assert
            Assert.AreEqual(expectedVersion, result);
        }
        public void GetVersionFormatted_WhenCalledWithPatternAndOtherValuesThanUsedInPattern_ThrowsArgumentException()
        {
            // Arrange
            var pattern = "{MAJOR}.{MINOR}.{PATCH}.{REVISION}";
            var values = new Dictionary<string, string> { { "MAJOR", "1" }, { "MINOR", "1" }, { "REVISION", "0" }, { "BUILD", "0" } };
            var expectedMessage = "The number of values is less than specified in the pattern or not all values has been provided.\nMandatory variables found: MAJOR, MINOR, PATCH, REVISION\nValues provided: MAJOR, MINOR, REVISION, BUILD";

            // Act
            var versionFormatter = new VersionFormatter();
            try
            {
                versionFormatter.GetVersionFormatted(pattern, values);
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                // Assert
                Assert.IsTrue(ex.Message.StartsWith(expectedMessage));
                Assert.AreEqual("values", ex.ParamName);
            }
        }
        public void GetVersionFormatted_WhenCalledWithPatternAndNotAllValuesInOptionalPart_ReplaceAllVariablesAndRemoveOptionalNotProvided()
        {
            // Arrange
            var pattern = "{MAJOR}.{MINOR}.{PATCH}[.{BUILD}{REVISION}]";
            var values = new Dictionary<string, string> { { "MAJOR", "1" }, { "MINOR", "1" }, { "PATCH", "0" }, { "BUILD", "B" } };
            var expectedVersion = "1.1.0.B";

            // Act
            var versionFormatter = new VersionFormatter();
            var result = versionFormatter.GetVersionFormatted(pattern, values);

            // Assert
            Assert.AreEqual(expectedVersion, result);
        }
        public void GetVersionFormatted_WhenCalledWithoutDictionaryValues_ThrowsArgumentNullException()
        {
            // Arrange
            var pattern = "NOTHING.TO.REPLACE";
            var values = new Dictionary<string, string>();

            // Act
            var versionFormatter = new VersionFormatter();
            try
            {
                versionFormatter.GetVersionFormatted(pattern, values);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                // Assert
                Assert.AreEqual("values", ex.ParamName);
            }
        }
        public void GetVersionFormatted_WhenCalledWithInvalidPattern_ThrowsArgumentException()
        {
            // Arrange
            var pattern = "NOTHING.TO.REPLACE";
            var values = new Dictionary<string, string> { { "MAJOR", "1" }, { "MINOR", "1" }, { "REVISION", "0" }, { "BUILD", "0" } };
            var expectedMessage = "The pattern seems not be valid because any variable has been found to replace";

            // Act
            var versionFormatter = new VersionFormatter();
            try
            {
                versionFormatter.GetVersionFormatted(pattern, values);
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                // Assert
                Assert.IsTrue(ex.Message.StartsWith(expectedMessage));
                Assert.AreEqual("pattern", ex.ParamName);
            }
        }