Skip to content

Instantly share code, notes, and snippets.

Created July 28, 2015 18:07
Show Gist options
  • Save anonymous/78948efcc60bdc64df7e to your computer and use it in GitHub Desktop.
Save anonymous/78948efcc60bdc64df7e to your computer and use it in GitHub Desktop.
using Moq;
namespace ConsoleApplication15
{
public class Documents
{
public string Abc { get; set; }
public Documents()
{
}
public Documents(string abc)
{
Abc = abc;
}
}
public interface IDocumentRepository
{
Documents GetDocuments(
int projectPK,
int? folderPK,
bool useFolders,
string search,
int user,
int page,
int pageSize,
string customerConnectionString);
}
public class DocumentsController
{
public IDocumentRepository DocumentRepository { get; private set; }
public DocumentsController(IDocumentRepository documentRepository)
{
DocumentRepository = documentRepository;
}
public Documents GetDocuments(int projectPK, int? folderPK, string search, int page, int pageSize)
{
Documents documents =
DocumentRepository.GetDocuments(
projectPK,
folderPK,
true,
search,
55, //saved in HttpConfiguration
page,
pageSize,
"CustomerConnectionString" //saved in HttpConfiguration
);
return documents;
}
}
class Program
{
static void Main(string[] args)
{
var repositoryMock = new Mock<IDocumentRepository>(MockBehavior.Strict);
repositoryMock
.Setup(
c => c.GetDocuments(
It.IsAny<int>(),
It.IsAny<int?>(),
It.IsAny<bool>(),
It.IsAny<string>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<int>(),
It.IsAny<string>()
)
)
.Returns(new Documents("it works"));
var documentsController = new DocumentsController(repositoryMock.Object);
var response =
documentsController.GetDocuments(
It.IsAny<int>(),
It.IsAny<int?>(),
It.IsAny<string>(),
It.IsAny<int>(),
It.IsAny<int>()
);
//response.Abc == "it works"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment