0

I found a bit of code which im unsure about in this poorly documented project im on. To be honest I havent got a clue what is going here.

public void TestMethod(ISystemScriptingInterface system, ScriptEventArgs eventArgs)


    {
                var databaseScriptingInterface = system.GetInterface("database") as IDatabaseScriptingInterface;

                if (databaseScriptingInterface == null)
                {
                    throw system.GetException(LocalisedSystemText.InternalServerError(), "Database scripting interface was not found", "Test Class", "Running test method", " Scripting.DatabaseInterfaceNotFound");
                }
                if (databaseScriptingInterface != null)
                {


                }
            }

Does any one know what is going on or can give me some good reading material to understand this better
Cheers.

Edited by ogsirus

3
Contributors
2
Replies
19
Views
2 Years
Discussion Span
Last Post by deceptikon
0

It looks like a unit test method that can be called by unit tests. If it cannot find the interface for database scripting, it will throw an exception, otherwise it will do something (not yet defined). In any case, the code is not what I'd call "professional quality" in that instead of an else {} it uses a test for not-null, after it already did a test for null of the interface object - extra unneeded code, and more prone to error.

0

in that instead of an else {} it uses a test for not-null, after it already did a test for null of the interface object

Would you believe that I've seen stuff like this in production code?

YesNo check = CheckThing(thing);

if (check == null)
{
    // Okay, I suppose
}
else if (check.Yes)
{
    // Sure
}
else if (check.No)
{
    // Yup
}
else if (check.Maybe)
{
    // Seriously?
}
else
{
    // WTF!
}

How many conditions can you find for yes or no? ;)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.