This time, it should access a set of documents and retrieve those belonging to an user.
For that, the new classes User, Project and DocumentList are added to Models, along with their interfaces IUser, IProject and IDocumentList respectively.
The Document class will be modified to contain a reference of the Project it belongs to and the User who is its owner.
All those objects will be mocked and the test will access the document list to retrieve those belonging to a user specified.
The test looks like this:
[TestMethod]
public void RetrieveAllDocumentsFromUser()
{
var mUser1 = new Mock<IUser>();
var mUser2 = new Mock<IUser>();
var mDocumentList = new Mock<IDocumentList>();
var mDocument1 = new Mock<IDocument>();
var mDocument2 = new Mock<IDocument>();
var mDocument3 = new Mock<IDocument>();
mUser1.Setup(x => x.ID).Returns(1);
mUser1.Setup(x => x.name).Returns("Test User 01");
mUser1.Setup(x => x.password).Returns("");
mUser1.Setup(x => x.screenName).Returns("User01");
mUser2.Setup(x => x.ID).Returns(2);
mUser2.Setup(x => x.name).Returns("Test User 02");
mUser2.Setup(x => x.password).Returns("");
mUser2.Setup(x => x.screenName).Returns("User02");
mDocument1.Setup(x => x.ID).Returns(1);
mDocument1.Setup(x => x.name).Returns("Test Document 01");
mDocument1.Setup(x => x.owner).Returns(mUser1.Object);
mDocument2.Setup(x => x.ID).Returns(2);
mDocument2.Setup(x => x.name).Returns("Test Document 02");
mDocument2.Setup(x => x.owner).Returns(mUser2.Object);
mDocument3.Setup(x => x.ID).Returns(3);
mDocument3.Setup(x => x.name).Returns("Test Document 03");
mDocument3.Setup(x => x.owner).Returns(mUser1.Object);
mDocumentList.Setup(x => x.documentList).Returns(new List());
mDocumentList.Object.addDocumentToList(mDocument1.Object);
mDocumentList.Object.addDocumentToList(mDocument2.Object);
mDocumentList.Object.addDocumentToList(mDocument3.Object);
Assert.IsNotNull(mDocumentList.Object.documentsOfUser(1));
Assert.AreEqual(2, mDocumentList.Object.documentsOfUser(1).Count);
}
In the last two lines, the mock object for the document list asserts that the list of documents returned exists and that it contains exactly 2 elements.public void RetrieveAllDocumentsFromUser()
{
var mUser1 = new Mock<IUser>();
var mUser2 = new Mock<IUser>();
var mDocumentList = new Mock<IDocumentList>();
var mDocument1 = new Mock<IDocument>();
var mDocument2 = new Mock<IDocument>();
var mDocument3 = new Mock<IDocument>();
mUser1.Setup(x => x.ID).Returns(1);
mUser1.Setup(x => x.name).Returns("Test User 01");
mUser1.Setup(x => x.password).Returns("");
mUser1.Setup(x => x.screenName).Returns("User01");
mUser2.Setup(x => x.ID).Returns(2);
mUser2.Setup(x => x.name).Returns("Test User 02");
mUser2.Setup(x => x.password).Returns("");
mUser2.Setup(x => x.screenName).Returns("User02");
mDocument1.Setup(x => x.ID).Returns(1);
mDocument1.Setup(x => x.name).Returns("Test Document 01");
mDocument1.Setup(x => x.owner).Returns(mUser1.Object);
mDocument2.Setup(x => x.ID).Returns(2);
mDocument2.Setup(x => x.name).Returns("Test Document 02");
mDocument2.Setup(x => x.owner).Returns(mUser2.Object);
mDocument3.Setup(x => x.ID).Returns(3);
mDocument3.Setup(x => x.name).Returns("Test Document 03");
mDocument3.Setup(x => x.owner).Returns(mUser1.Object);
mDocumentList.Setup(x => x.documentList).Returns(new List
mDocumentList.Object.addDocumentToList(mDocument1.Object);
mDocumentList.Object.addDocumentToList(mDocument2.Object);
mDocumentList.Object.addDocumentToList(mDocument3.Object);
Assert.AreEqual(2, mDocumentList.Object.documentsOfUser(1).Count);
At a first run, the test didn't pass.
The method of retrieving the documents in the list was checked and changed, but the test still didn't pass.
Further investigation and debugging revealed an error in the way the items are inserted in the list.
Because of that, a new test case will be created to try the creation of the document list and the insertion of documents in it.