How to modularly verify that a log has been called with the correct localized, formatted string?

In the application I'm testing, I want to make sure that a log is called for certain inputs. Some of the methods have different possible log messages (for example, "incorrect", "value out of range"). Thus, I want to make sure that the registrar is being called with the correct message.

Themselved logger lines are in RESX and may be localized in the future. In addition, the wording may change. Therefore, simply comparing it with a hard-coded string can lead to a breakdown of the associated tests with each text change. Since they are localizable, would that mean I would have to force unit-test to run under a specific culture, or is there a better way?

Complicating this, RESX strings are actually not as simple as above, but the forms are "Line {0}: Value '{1}' at column {2} is malformed."then used as input to string.Format () to create "Line 12: Value '12a.45' at column 45 is malformed.", for example. This is the string that the registrar actually receives. Should I hard code this line in a unit test?

Edit:

I will try to explain in more detail using a very simplified method to show what I mean:

public void ConvertSomething(object value)
{
    if (/* Check if valid value */)
    {
        var convertedValue = /* Some conversion */ ;
        if (/* Check is in range */)
        {
            // Do something
        }
        else
        {
            Logger.Log(string.Format(Resources.OutOfRange, LineNumber, convertedValue));
        }
    }
    else
    {
        Logger.Log(string.Format(Resources.InvalidValue, LineNumber, value, ColumnNumber));
    }
}

How to check if the login with the correct message is called? I can’t just check if any call to the registrar has been called. If I give him a valid, but out of range value, but the validation has an error, it will call the registrar, but with the message “invalid value”, when it should be “out of range”.

, , . ?

+3
2

, . , / .

, ( ), .

, , , , . , , .

NUnit :

http://www.nunit.org/index.php?p=culture&r=2.4.8

: , , ? , , , , , , . , .NET .

, , , , , .

2: , , . , params object[] args, ?

? , , . , , , , .

3: , . resx, , . , .

resx , , , , , , .

+3

, .

0

All Articles