public void UpdateDocumentGroup() { DocumentGroup existingDocumentGroup; using (var uow = new XbtContext()) { var repo = new GenericRepository <DocumentGroup>(uow); //[retrieve any existing document group] existingDocumentGroup = repo.Get().FirstOrDefault(); //Check if there was any document group retreived Assert.IsNotNull(existingDocumentGroup); //edit an existing class existingDocumentGroup.Name = "Corporate Documents"; existingDocumentGroup.Description = "Documents used by the corporate department"; repo.Update(existingDocumentGroup); try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); //If we have reached here the test has failed Assert.Fail("Test failed"); } }; //Retreive the modified document group using a new unit of work and repository //to ensure values are retreived from database instead of in memory graph var uow1 = new XbtContext(); var repo1 = new GenericRepository <DocumentGroup>(uow1); var modifiedDocumentGroup = repo1.GetById(existingDocumentGroup.Id); //Establish if the changes to the document group were pushed to the database Assert.AreEqual(modifiedDocumentGroup.Name, "Corporate Documents"); Assert.AreEqual(modifiedDocumentGroup.Description, "Documents used by the corporate department"); }
public void RetrieveCustomer() { using (var uow = new XbtContext()) { var retrievedCustomer = from rc in uow.DocumentOwners.OfType <Customer>() select rc; var result = retrievedCustomer.ToList(); Assert.IsNotNull(result); } }
public void CreateDocumentGroup() { using (var uow = new XbtContext()) { var repo = new GenericRepository <DocumentGroup>(uow); //Create new document group var newDocumentGroup = new DocumentGroup() { Name = "Credit Documents", Description = "Documents used in the credit department" }; repo.Insert(newDocumentGroup); try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); //If we have reached here the test has failed Assert.Fail("Test failed"); } //Retrieve saved document using a new unit of work and repository //to ensure values are retreived from database instead of in memory graph var uow1 = new XbtContext(); var repo1 = new GenericRepository <DocumentGroup>(uow1); var savedDocumentGroup = repo1.GetById(newDocumentGroup.Id); //Establish if the saved document group has the same name as the saved one Assert.AreEqual(savedDocumentGroup.Name, newDocumentGroup.Name); }; }
public void Should_Retrieve_DocTags_By_DocTypeId() { int docTypeId = 1; using (var uow = new XbtContext()) { //Retreive document type by id var docType = uow.DocumentTypes.Include("DocumentTags").SingleOrDefault(d => d.Id == docTypeId); //retrieve doc tags related to document type retrieved var docTags = docType.DocumentTags.ToList(); //Assert Assert.IsTrue(docTags.Count() > 2); } }
public void OneDocumentTagWithManyDocumentTypes() { DocumentType existingdocumentType; DocumentTag existingdocumentTag; using (var uow = new XbtContext()) { //var repoDocType = new GenericRepository<DocumentType>(uow); //[retrieve any existing document type] existingdocumentType = uow.DocumentTypes.Include("DocumentTags").FirstOrDefault(); Assert.IsTrue(existingdocumentType.DocumentTags.Count() > 1, "Document Type should atleast have more than one tag"); existingdocumentTag = uow.DocumentTags.Include("DocumentTypes").FirstOrDefault(); Assert.IsTrue(existingdocumentTag.DocumentTypes.Count() > 1, "Document Tag should atleast have more than one type"); } }
public void should_retrieve_documentOwner_of_type_customer() { using (var uow = new XbtContext()) { var repo = new GenericRepository <DocumentOwner>(uow); var docOwner = repo.Get(includeProperties: "Documents").FirstOrDefault(d => d.Id == 1); try { if (docOwner != null) { Assert.IsTrue(docOwner is Customer); } } catch (Exception) { Assert.Fail("Document Owner is not of type Customer"); } } }
public void AddNewCustomer() { var customer = new Customer() { CustomerNo = 235, FirstName = "Timo", LastName = "Lukyamuzi", DateOfBirth = DateTime.Now.ToLocalTime(), Email = "*****@*****.**", Address = "Ebbs" }; using (var uow = new XbtContext()) { uow.DocumentOwners.Add(customer); try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); //If we have reached here the test has failed Assert.Fail("Test failed"); } } }
public void Should_Retreive_Documents_By_Customer() { using (var uow = new XbtContext()) { var repo = new GenericRepository <DocumentOwner>(uow); var customer = repo.Get(includeProperties: "Documents").FirstOrDefault(d => d.Id == 1); try { if (customer != null) { var documents = customer.Documents.ToList(); Assert.IsTrue(documents.Count() > 1); } } catch (Exception ex) { Assert.Fail("Customer has zero documents"); } } }
public void CreateDocumentTag() { DocumentTag newDocTag = new DocumentTag(); using (var uow = new XbtContext()) { var repoDocGroup = new GenericRepository <DocumentGroup>(uow); var newDocumentGroup = new DocumentGroup() { Name = "Credit Documents", Description = "Documents used in the credit department" }; repoDocGroup.Insert(newDocumentGroup); //Retrieve Inserted document var insertedDocumentGroup = repoDocGroup.GetById(newDocumentGroup.Id); var repoDocType = new GenericRepository <DocumentType>(uow); var newDocumentType = new DocumentType() { Name = "Document Type 3", Description = "Document type description 3", DocumentGroup = insertedDocumentGroup, DocumentDirectory = @"\TestDocuments", }; repoDocType.Insert(newDocumentType); var repoDocTag = new GenericRepository <DocumentTag>(uow); var insertedDocumentType = repoDocType.GetById(newDocumentType.Id); newDocTag.Name = "New Doc Tag"; newDocTag.Description = "New Doc Tag Description"; newDocTag.DocumentTypes = new List <DocumentType>() { insertedDocumentType }; repoDocTag.Insert(newDocTag); try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); //If we have reached here the test has failed Assert.Fail("Test failed"); } } //Retreive the modified document tag using a new unit of work and repository //to ensure values are retreived from database instead of in memory graph var uowDoctag = new XbtContext(); var repoExistingDocTag = new GenericRepository <DocumentTag>(uowDoctag); var retrievedDocumentTag = repoExistingDocTag.Get().FirstOrDefault(); Assert.AreEqual(retrievedDocumentTag.Name, newDocTag.Name); }
public void Should_Create_Document() { using (var uow = new XbtContext()) { //retrieve document owner var docOwner = from rc in uow.DocumentOwners.OfType <Customer>() select rc; var result = docOwner.FirstOrDefault(); //retrieve document type int doctypeId = 1; var repoDocType = new GenericRepository <DocumentType>(uow); var docType = repoDocType.GetById(doctypeId); var newDocument = new Document() { Description = "New Doc Description", SerialNo = "35-899-hello-world", FileName = "New Document-hello-world", DocumentType = docType, DocumentOwner = result }; uow.Documents.Add(newDocument); try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); //If we have reached here the test has failed Assert.Fail("Test failed"); } //Assert.IsNotNull(newDocument); //Retreive the inserted document using a new unit of work and repository //to ensure values are retreived from database instead of in memory graph var uow1 = new XbtContext(); var repo1 = new GenericRepository <Document>(uow1); var insertedDocument = repo1.GetById(newDocument.Id); Assert.NotNull(insertedDocument); } }
/// <summary> /// Constructor /// </summary> public DocumentArchivingProcess() { uow = new XbtContext(); }
/// <summary> /// Constructor /// </summary> public CustomerBL() { uow = new XbtContext(); }
public void UpdateDocumentType() { DocumentType existingdocumentType; using (var uow = new XbtContext()) { var repo = new GenericRepository <DocumentType>(uow); //[retrieve any existing document type] existingdocumentType = repo.Get().FirstOrDefault(); //Check if there was any document type retreived Assert.IsNotNull(existingdocumentType); //Create new document group var repoDoc = new GenericRepository <DocumentGroup>(uow); var newDocumentGroup = new DocumentGroup() { Name = "updates Credit Documents", Description = "updated Documents used in the credit department" }; repoDoc.Insert(newDocumentGroup); uow.SaveChanges(); Assert.IsNotNull(newDocumentGroup); //edit an existing document type properties existingdocumentType.Name = "New document type name"; existingdocumentType.Description = "New document type description"; existingdocumentType.DocumentGroup = newDocumentGroup; repo.Update(existingdocumentType); try { uow.SaveChanges(); } catch (DbEntityValidationException ex) { //Retrieve validation errors ex.EntityValidationErrors.ToList().ForEach ( v => { v.ValidationErrors.ToList().ForEach ( e => { System.Diagnostics.Debug.WriteLine(e.ErrorMessage); } ); } ); //If we have reached here the test has failed Assert.Fail("Test failed"); } } //Retreive the modified document type using a new unit of work and repository //to ensure values are retreived from database instead of in memory graph var uow1 = new XbtContext(); var repo1 = new GenericRepository <DocumentType>(uow1); var modifiedDocumentType = repo1.Get(d => d.Id == existingdocumentType.Id, includeProperties: "DocumentGroup").FirstOrDefault(); Assert.NotNull(modifiedDocumentType); Assert.AreEqual(modifiedDocumentType.Name, existingdocumentType.Name); Assert.AreEqual(modifiedDocumentType.Description, existingdocumentType.Description); Assert.AreEqual(modifiedDocumentType.DocumentGroup.Id, existingdocumentType.DocumentGroup.Id); }
/// <summary> /// Constructor /// </summary> public DocumentTypeBL() { uow = new XbtContext(); }