public void GetDocumentsByDeliverableId_ShouldReturnTestFileName1() { //Arrange int testDeliverableId = 1; MRMUser testMRMUser = new MRMUser() { Id = 1, FirstName = "TestFirst", LastName = "TestLast", DepartmentId = 84//MRM Team }; Document testDocument1 = new Document() { Id = 1, Name = "TestDocumentName1", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.Department }, DepartmentId = 84,//MRM Team DeliverableId = 1, FileName = "TestFileName1", Description = "TestDescription", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2 }; //Build Document list List <Document> testDocumentList = new List <Document> { testDocument1 }; IQueryable <Document> testDocumentQueryable = testDocumentList.AsQueryable(); mockUserRepository.Setup(user => user.GetById(It.IsAny <long>())).Returns(testMRMUser); mockDocumentRepository.Setup(doc => doc.GetAll()).Returns(testDocumentQueryable); //Act var docService = new DocumentsService(mockUnitOfWork.Object, null, mockDocumentRepository.Object, mockUserRepository.Object, mockDocumentAccessTypeRepository.Object, mockMRMUserRepository.Object, mockDeliverableDocumentRepository.Object, mockContractRequestMasterVendorDocumentRepository.Object); docService.UserId = testDocument1.OwnerMRMUserId; var result = docService.GetDocumentsByDeliverableId(testDeliverableId).ToList(); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 1); }
public void GetDocumentsByDeliverableId_ShouldReturnThreeDocuments() { //Arrange #region Data Setup int testDeliverableId = 1; string testDocDescription = "WillReturn"; MRMUser testMRMUser = new MRMUser() { Id = 1, FirstName = "TestFirst", LastName = "TestLast", DepartmentId = 84//MRM Team }; Document testDocument1 = new Document() { Id = 1, Name = "TestDocumentName1", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.Department }, DepartmentId = 84,//MRM Team DeliverableId = 1, FileName = "TestFileName1", Description = "WillReturn", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2 }; Document testDocument2 = new Document() { Id = 2, Name = "TestDocumentName2", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.GeneralAccess }, DepartmentId = 19,//Finance DeliverableId = 1, FileName = "TestFileName2", Description = "WillReturn", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2 }; Document testDocument3 = new Document() { Id = 2, Name = "TestDocumentName3", OthersCanDeleteFlag = true, DocumentAccessType = null, DepartmentId = 19,//Finance DeliverableId = 1, FileName = "TestFileName3", Description = "WillReturn", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2 }; List <Document_MRMUser> testDocMRMUsers = new List <Document_MRMUser>(); Document testDocument4 = new Document() { Id = 2, Name = "TestDocumentName4", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.SpecificPeople }, DepartmentId = 19,//Finance DeliverableId = 1, FileName = "TestFileName4", Description = "WillNotReturn", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 3, Document_MRMUser = testDocMRMUsers,//Will not return, no users }; Document testDocument5 = new Document() { Id = 2, Name = "TestDocumentName5", OthersCanDeleteFlag = true, DocumentAccessType = null, DepartmentId = 19,//Finance DeliverableId = 1, FileName = "TestFileName5", Description = "WillNotReturn", IsActiveFlag = false, //Will not return. Only Active docs FileId = null, OwnerMRMUserId = 2 }; Document testDocument6 = new Document() { Id = 2, Name = "TestDocumentName5", OthersCanDeleteFlag = true, DocumentAccessType = null, DepartmentId = 19, //Finance DeliverableId = 2, //Will not return, not matching deliverableId being passed in FileName = "TestFileName5", Description = "WillNotReturn", IsActiveFlag = false, FileId = null, OwnerMRMUserId = 2 }; #endregion //Build Document list List <Document> testDocumentList = new List <Document> { testDocument1, testDocument2, testDocument3, testDocument4, testDocument5, testDocument6 }; IQueryable <Document> testDocumentQueryable = testDocumentList.AsQueryable(); mockUserRepository.Setup(user => user.GetById(It.IsAny <long>())).Returns(testMRMUser); mockDocumentRepository.Setup(doc => doc.GetAll()).Returns(testDocumentQueryable); //Act var docService = new DocumentsService(mockUnitOfWork.Object, null, mockDocumentRepository.Object, mockUserRepository.Object, mockDocumentAccessTypeRepository.Object, mockMRMUserRepository.Object, mockDeliverableDocumentRepository.Object, mockContractRequestMasterVendorDocumentRepository.Object); docService.UserId = 2; var result = docService.GetDocumentsByDeliverableId(testDeliverableId).ToList(); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 3); Assert.IsTrue(result.TrueForAll(doc => doc.Description.Equals(testDocDescription))); }
public void GetDocumentsByDeliverableId_ShouldReturnSpecificUserDocument() { //Arrange int testDeliverableId = 1; MRMUser testMRMUser = new MRMUser() { Id = 1, FirstName = "TestFirst", LastName = "TestLast", DepartmentId = 19//Finance }; Document testDocument1 = new Document() { Id = 1, Name = "TestDocumentName1", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.Department }, DepartmentId = 84,//MRM Team DeliverableId = 1, FileName = "TestFileName2", Description = "TestDescription", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2 }; Document testDocument2 = new Document() { Id = 2, Name = "TestDocumentName2", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.GeneralAccess }, DepartmentId = 84,//MRM Team DeliverableId = 1, FileName = "TestFileName2", Description = "TestDescription", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2 }; Document_MRMUser testSPDocUser = new Document_MRMUser() { MRMUserId = 10 }; List <Document_MRMUser> testSPDocUserList = new List <Document_MRMUser> { testSPDocUser }; Document testSpecificPeople = new Document() { Id = 3, Name = "TestSP", OthersCanDeleteFlag = true, DocumentAccessType = new DocumentAccessType() { Code = Constants.DocumentAccessType.SpecificPeople }, DepartmentId = 84,//MRM Team DeliverableId = 1, FileName = "TestSP", Description = "TestSPDescription", IsActiveFlag = true, FileId = null, OwnerMRMUserId = 2, Document_MRMUser = testSPDocUserList }; //Build Document list List <Document> testDocumentList = new List <Document> { testDocument1, testDocument2, testSpecificPeople }; IQueryable <Document> testDocumentQueryable = testDocumentList.AsQueryable(); mockUserRepository.Setup(user => user.GetById(It.IsAny <long>())).Returns(testMRMUser); mockDocumentRepository.Setup(doc => doc.GetAll()).Returns(testDocumentQueryable); //Act var docService = new DocumentsService(mockUnitOfWork.Object, null, mockDocumentRepository.Object, mockUserRepository.Object, mockDocumentAccessTypeRepository.Object, mockMRMUserRepository.Object, mockDeliverableDocumentRepository.Object, mockContractRequestMasterVendorDocumentRepository.Object); docService.UserId = 10; var result = docService.GetDocumentsByDeliverableId(testDeliverableId).ToList(); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); var specificPeopleDoc = result.Where(x => x.Id == 3).ToList(); Assert.IsTrue(specificPeopleDoc.Count() > 0); }