public void Calling_ParseWithArgumentsString_With_Empty_ArgumentsString_Returns_Error() { // Arrange var input = ""; // Act var actual = StringFormatParser.ParseWithArgumentsString("something", input); // Assert actual.IsSuccessful.Should().BeFalse(); actual.ErrorMessages.Should().HaveCount(1); actual.ErrorMessages.First().Should().Be("Arguments string is empty"); }
public void CanUseParsedArgumentsStringForStringFormat() { // Arrange const string FormatString = "Hello, {0}{1}"; const string ArgumentsString = "John Doe, !"; var parsedArguments = StringFormatParser.ParseWithArgumentsString(FormatString, ArgumentsString).Values.Select(kvp => kvp.Value.ToString()).ToArray(); //note that we have to replace the double quotes... // Act var actual = string.Format(FormatString, parsedArguments); // Assert actual.Should().Be("Hello, John Doe!"); }
public void CanParseFormatStringWithArgumentsString() { // Arrange const string FormatString = "Hello {0}{1}"; const string Args = "\"world\", \"!\""; // Act var actual = StringFormatParser.ParseWithArgumentsString(FormatString, Args); // Assert actual.IsSuccessful.Should().BeTrue(); actual.ErrorMessages.Should().BeEmpty(); var contents = string.Join("|", actual.Values.Select(kvp => string.Format("{0};{1}", kvp.Key, kvp.Value))); contents.Should().Be("0;\"world\"|1;\"!\""); }