protected virtual void Dispose(bool disposing) { if (disposing) { if (dal != null) { dal.Dispose(); dal = null; } } }
public void MyTestInitialize() { var data = new List <Patient> { new Patient() { id = 1, MRN = "4131", LastName = "Test", FirstName = "James", AddressLine1 = "4 Main Street", Active = true }, new Patient() { id = 2, MRN = "4132", LastName = "Test", FirstName = "James1", AddressLine1 = "5 Main Street", Active = true }, new Patient() { id = 3, MRN = "4133", LastName = "Martin", FirstName = "James1", AddressLine1 = "5 Main Street", Active = true }, new Patient() { id = 4, MRN = "4134", LastName = "Martin", FirstName = "Donna", AddressLine1 = "5 Main Street", Active = false }, new Patient() { id = 5, MRN = "4100", LastName = "Martin", FirstName = "Steve", AddressLine1 = "5 Main Street", Active = false, External_id = "1000023", External_source = "https://fhir.test.com" }, new Patient() { id = 5, MRN = "4101", LastName = "Martin", FirstName = "Steve", AddressLine1 = "5 Main Street", Active = true, External_id = "1000024", External_source = "https://fhir.test.com" } }; var useractions_data = new List <UserAction>(); var dbSetMock = new Mock <IDbSet <Patient> >(); dbSetMock.As <IQueryable <Patient> >().Setup(m => m.Provider).Returns(data.AsQueryable().Provider); dbSetMock.As <IQueryable <Patient> >().Setup(m => m.Expression).Returns(data.AsQueryable().Expression); dbSetMock.As <IQueryable <Patient> >().Setup(m => m.ElementType).Returns(data.AsQueryable().ElementType); dbSetMock.As <IQueryable <Patient> >().Setup(m => m.GetEnumerator()).Returns(data.AsQueryable().GetEnumerator()); dbSetMock.Setup(m => m.Add(It.IsAny <Patient>())).Callback <Patient>(p => data.Add(p)); var dbSetMock_ua = new Mock <IDbSet <UserAction> >(); dbSetMock_ua.As <IQueryable <UserAction> >().Setup(m => m.Provider).Returns(useractions_data.AsQueryable().Provider); dbSetMock_ua.As <IQueryable <UserAction> >().Setup(m => m.Expression).Returns(useractions_data.AsQueryable().Expression); dbSetMock_ua.As <IQueryable <UserAction> >().Setup(m => m.ElementType).Returns(useractions_data.AsQueryable().ElementType); dbSetMock_ua.As <IQueryable <UserAction> >().Setup(m => m.GetEnumerator()).Returns(useractions_data.AsQueryable().GetEnumerator()); dbSetMock_ua.Setup(m => m.Add(It.IsAny <UserAction>())).Callback <UserAction>(u => useractions_data.Add(u)); var customMock = new Mock <ClinicalContext>(); customMock.Setup(p => p.Patients).Returns(dbSetMock.Object); customMock.Setup(u => u.UserActions).Returns(dbSetMock_ua.Object); // this is for the text methods that test the DAL directly. this.dal = new ClinicalDAL(customMock.Object); // make the clincal context global Company.Globals.GlobalVariables.Instance.ClinicalContext = customMock.Object; Company.Globals.GlobalVariables.Instance.ClinicalUser = "******"; }