I'm writing an extension for string.Format (which I've done before with no problems.)
My extension:
public static string FormatWith(this string source, params object[] args) {
source.ThrowIfNull("source");
return string.Format(source, args);
}
My test:
[TestMethod]
public void FormatWith_ShouldReturnCorrectResult_FromValidArgs() {
var expected = "testing 123";
var actual = "test".FormatWith("ing", " ", 123);
Assert.AreEqual(expected, actual);
}
In my test, after the call to FormatWith, actual should be "testing 123" but it is just "test".
My test's message:
Assert.AreEqual failed. Expected:<testing123>. Actual:<test>.
I've tried passing types other than string into the extension but the result is unchanged. And I'm sure source.ThrowIfNull is not throwing an exception.
So what gives? Am I overlooking something? A nice answer would show me a working implementation of FormatWith along with an explanation of why my implementation is not working.
Edit: I'm an idiot and completely forgot about {0}, {1}... I use this on a daily basis too. Will accept first answer when timer is up. Thanks guys.