-
-
Save anonymous/78948efcc60bdc64df7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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