K
Kenneth Cochran
I'll just start off by saying I'm new to C#, new to unit testing and new to
mock objects.
Ok, I expected the createProcess method in the inherited class to be the one
that gets called by StartDatabaseInstance but that doesn't appear to be the
case. What am I missing?
public bool StartDatabaseInstance(ref string strException)
{
try
{
Process process = createProcess();
ProcessStartInfo pStart = new ProcessStartInfo();
string strFilename = "scm.exe";
string strProgramFiles =
Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles);
string strDefault = Path.Combine(strProgramFiles, "Microsoft SQL
Server\\80\\Tools\\Binn\\scm.exe");
if (File.Exists(strDefault))
{
strFilename = strDefault;
}
pStart.FileName = strFilename;
pStart.Arguments = "*****************************************";
pStart.UseShellExecute = true;
process.StartInfo = pStart;
process.Start();
process.WaitForExit();
return true;
}
catch (Exception ex)
{
strException = ex.Message;
return false;
}
}
public class ChildDatabaseManager
atabaseManager
{
new protected DynamicMock createProcess()
{
DynamicMock mockProcess = new DynamicMock(typeof(Process));
mockProcess.ExpectAndReturn("Start", true);
mockProcess.ExpectAndReturn("WaitForExit", true);
return mockProcess;
}
}
[TestFixture]
public class DatabaseManagerTests
{
[Test]
public void StartDatabaseInstanceTest()
{
string ExceptionMessage = "";
ChildDatabaseManager DatabaseManagerObject = new
ChildDatabaseManager();
DatabaseManagerObject.StartDatabaseInstance(ref ExceptionMessage);
}
}
mock objects.
Ok, I expected the createProcess method in the inherited class to be the one
that gets called by StartDatabaseInstance but that doesn't appear to be the
case. What am I missing?
public bool StartDatabaseInstance(ref string strException)
{
try
{
Process process = createProcess();
ProcessStartInfo pStart = new ProcessStartInfo();
string strFilename = "scm.exe";
string strProgramFiles =
Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles);
string strDefault = Path.Combine(strProgramFiles, "Microsoft SQL
Server\\80\\Tools\\Binn\\scm.exe");
if (File.Exists(strDefault))
{
strFilename = strDefault;
}
pStart.FileName = strFilename;
pStart.Arguments = "*****************************************";
pStart.UseShellExecute = true;
process.StartInfo = pStart;
process.Start();
process.WaitForExit();
return true;
}
catch (Exception ex)
{
strException = ex.Message;
return false;
}
}
public class ChildDatabaseManager

{
new protected DynamicMock createProcess()
{
DynamicMock mockProcess = new DynamicMock(typeof(Process));
mockProcess.ExpectAndReturn("Start", true);
mockProcess.ExpectAndReturn("WaitForExit", true);
return mockProcess;
}
}
[TestFixture]
public class DatabaseManagerTests
{
[Test]
public void StartDatabaseInstanceTest()
{
string ExceptionMessage = "";
ChildDatabaseManager DatabaseManagerObject = new
ChildDatabaseManager();
DatabaseManagerObject.StartDatabaseInstance(ref ExceptionMessage);
}
}