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.

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.

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? ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.