Hi, I am newbiew. And i encoutered the same problem when I use the sample code to compile.
Because I cannot succeed to compile it. However, these code is from the TypeMock document. It should be excuted successfully.
The error message is that "Error 1, Expected class, delegate, enum, interface, or struct". It showed that " public
bool is worng, could help for this? Thanks.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using TypeMock;
public bool IsAuthenticated(string name,string password)
{
Logger.Log(Logger.NORMAL,"Entering Authentication");
try
{
// do something
int Results = DoSelect(statement);
bool isOk = Results==1;
if (isOk)
{
Logger.Log(Logger.NORMAL,"User Authenticated "+name);
}
else
{
Logger.Log(Logger.SECURITY,"User login failed "+name);
}
return isOk;
}
catch (Exception ex)
{
Logger.Log(Logger.FAILED,"Login system failure",ex);
// handle exception
}
}
[TestFixture]
public class AccountTest
{
[Test]
public void Authenticated()
{
Authentication authenticator = new Authentication();
// Initialize Type Mocks (This can be done in the [Setup])
MockManager.Init();
// the Logger class is now being mocked
Mock logMock = MockManager.Mock(typeof(Logger));
// set up our expectations for 2 Log calls in IsAuthenticated
// 1) "Entering Authentication" Log at first line
// 2) "User login failed user" Log
logMock.ExpectCall("Log");
logMock.ExpectCall("Log");
// authentication should fail
Assert.IsFalse(authenticator.IsAuthenticated("user", "password"));
// Verify that all calls were made (This can be done in the [Teardown])
MockManager.Verify();
}
}