public void GivenANewServiceOffering_WhenSaveChanges_ThenDatabaseContainsServiceOfferings()
        {
            Target.ServiceOfferings.Add(new ServiceOffering
            {
                Provider = new Provider
                {
                    Name = "999999"
                },
                ServiceType = new ServiceType
                {
                    Name = "999999"
                },
                Program = new Program
                {
                    Name = "99999"
                }
            });

            Target.SaveChanges();

            using (EducationDataContext verifyContext = new EducationDataContext())
            {
                Assert.IsNotNull(verifyContext.ServiceOfferings.SingleOrDefault(s => s.Provider.Name.Equals("999999") && s.ServiceType.Name.Equals("999999")));
            }
        }
 public void WhenCreate_ThenGetInstance()
 {
     using (EducationDataContext actual = EducationDataContextFactory.Create(MockKernel))
     {
         Assert.IsNotNull(actual);
     }
 }
        public void WhenInitialize_ThenExpectedPropertiesAreProtected()
        {
            var expected = new List <Property>
            {
                new Property {
                    EntityName = "SSD.Domain.Student", Name = "StudentKey"
                },
                new Property {
                    EntityName = "SSD.Domain.Student", Name = "ServiceRequests"
                },
                new Property {
                    EntityName = "SSD.Domain.Student", Name = "StudentAssignedOfferings"
                },
                new Property {
                    EntityName = "SSD.Domain.ServiceOffering", Name = "StudentAssignedOfferings"
                }
            };

            ResetDatabase();
            Target.Dispose();
            Target = new EducationDataContext();

            var actual = Target.Properties.Where(p => p.IsProtected).ToList();

            Assert.IsTrue(expected.All(p => actual.Exists(a => a.Name == p.Name && a.EntityName == p.EntityName)));
            Assert.IsFalse(actual.Any(a => !expected.Exists(p => p.Name == a.Name && p.EntityName == a.EntityName)));
        }
 public void GivenInjectedCache_WhenCreate_ThenContextCacheIsSet()
 {
     using (EducationDataContext actual = EducationDataContextFactory.Create(MockKernel))
     {
         MockConfigurator.AssertWasCalled(m => m.Configure(MockKernel, actual));
     }
 }
 public void InitializeTest()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     Target = new AgreementManager(repositoryContainer);
 }
 public static void CleanupAssembly()
 {
     using (EducationDataContext context = new EducationDataContext())
     {
         context.Database.Delete();
     }
 }
 public void InitializeTest()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     Target = new PrivateHealthFieldManager(repositoryContainer, MockRepository.GenerateMock<IBlobClient>(), new DataTableBinder(), new UserAuditor());
 }
        public void GivenANewServiceOffering_WhenSaveChanges_ThenDatabaseContainsServiceOfferings()
        {
            Target.ServiceOfferings.Add(new ServiceOffering
            {
                Provider = new Provider
                {
                    Name = "999999"
                },
                ServiceType = new ServiceType
                {
                    Name = "999999"
                },
                Program = new Program
                {
                    Name = "99999"
                }
            });

            Target.SaveChanges();

            using (EducationDataContext verifyContext = new EducationDataContext())
            {
                Assert.IsNotNull(verifyContext.ServiceOfferings.SingleOrDefault(s => s.Provider.Name.Equals("999999") && s.ServiceType.Name.Equals("999999")));
            }
        }
 public static void InitializeAssembly(TestContext testContext)
 {
     using (EducationDataContext context = new EducationDataContext())
     {
         context.Database.Delete();
         context.Database.Initialize(true);
     }
 }
 public void TestInitialize()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     Target = new ServiceOfferingManager(repositoryContainer, new DataTableBinder());
     User = new EducationSecurityPrincipal(new UserRepository(EducationContext).Items.Where(s => s.UserKey == "Bob").Include("UserRoles.Role").Single());
 }
 public void InitializeTest()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     ProviderManager manager = new ProviderManager(repositoryContainer, new DataTableBinder());
     Target = new ProviderController(manager);
 }
        public void WhenCreate_ThenContextConnectionStringComesFromConfiguration()
        {
            string expected = ConfigurationManager.AppSettings["DatabaseConnectionString"];

            using (EducationDataContext actual = EducationDataContextFactory.Create(MockKernel))
            {
                Assert.IsTrue(actual.Database.Connection.ConnectionString.Contains(expected)); // NOTE: Won't be equal because the connection is wrapped for caching/tracing
            }
        }
        public void WhenConfigure_ThenDatabaseInitialized()
        {
            using (EducationDataContext actual = new EducationDataContext())
            {
                Target.Configure(MockKernel, actual);

                Assert.IsTrue(actual.Database.Exists());
            }
        }
Example #14
0
 public static EducationDataContext Create(IKernel kernel)
 {
     lock (LockObject)
     {
         EducationDataContext     instance     = new EducationDataContext();
         IDataContextConfigurator configurator = kernel.Resolve <IDataContextConfigurator>();
         configurator.Configure(kernel, instance);
         return(instance);
     }
 }
 public void InitializeTest()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     ProviderManager providerManager = new ProviderManager(repositoryContainer, new DataTableBinder());
     ProgramManager programManager = new ProgramManager(repositoryContainer, new DataTableBinder());
     ServiceTypeManager serviceTypeManager = new ServiceTypeManager(repositoryContainer, new DataTableBinder());
     Target = new PartnersController(providerManager, programManager, serviceTypeManager);
 }
 public static EducationDataContext Create(IKernel kernel)
 {
     lock (LockObject)
     {
         EducationDataContext instance = new EducationDataContext();
         IDataContextConfigurator configurator = kernel.Resolve<IDataContextConfigurator>();
         configurator.Configure(kernel, instance);
         return instance;
     }
 }
        public void GivenSingleSchoolId_WhenResetApprovals_ThenNewContextCanFindNoStudentsWithApprovedProviders()
        {
            Target.ResetApprovals(new[] { 1 });

            Context.SaveChanges();
            using (EducationDataContext assertContext = new EducationDataContext())
            {
                Assert.IsFalse(assertContext.Students.Where(s => s.SchoolId == 1 && s.ApprovedProviders.Count() > 0).Any());
            }
        }
        public void GivenEnableTracingFalse_WhenConfigure_ThenContextTracingNotConfigured()
        {
            Target.EnableTracing = false;

            using (EducationDataContext actual = new EducationDataContext())
            {
                Target.Configure(MockKernel, actual);

                Assert.IsNull(actual.Log);
            }
        }
        public void GivenAStudentQueryable_WhenIncludeClassesAndTeachers_ThenGetStudentsWithClassesWithATeacher()
        {
            List<Student> items = Target.Items.ToList();
            Context = new EducationDataContext();
            Target = new StudentRepository(Context);

            List<Student> expanded = Target.Items.Include("Classes.Teacher").ToList();

            Assert.IsTrue(items.Any(s => s.Classes.Count == 0));
            Assert.IsTrue(expanded.Any(s => s.Classes.Count > 0));
            Assert.IsTrue(expanded.Any(s => s.Classes.All(c => c.Teacher != null)));
        }
 public static void ForceDeleteEducationDatabase(string databaseName)
 {
     using (EducationDataContext context = new EducationDataContext())
     {
         if (context.Database.Exists())
         {
             string dropUsersCommand = string.Format("USE [master]; ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE", databaseName);
             context.Database.ExecuteSqlCommand(dropUsersCommand);
             context.Database.Delete();
         }
     }
 }
        public void WhenInitializeDatabase_ThenFulfillmentStatusesPopulated()
        {
            List <string> expected = new List <string> {
                Statuses.Open, Statuses.Fulfilled, Statuses.Rejected
            };

            ResetDatabase();
            Target.Dispose();
            Target = new EducationDataContext();

            var actual = Target.FulfillmentStatuses.Select(f => f.Name).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
        public void GivenANewServiceType_WhenSaveChanges_ThenDatabaseContainsServiceType()
        {
            Target.ServiceTypes.Add(new ServiceType
            {
                Name        = "Tester Service",
                Description = "Tester Service Description"
            });

            Target.SaveChanges();

            using (EducationDataContext verifyContext = new EducationDataContext())
            {
                Assert.IsNotNull(verifyContext.ServiceTypes.SingleOrDefault(s => s.Name.Equals("Tester Service")));
            }
        }
        public void GivenANewUserIsAdded_WhenSaveChanges_ThenDatabaseContainsUser()
        {
            string userKey = Guid.NewGuid().ToString();

            Target.Users.Add(new User {
                UserKey = userKey, FirstName = "Mr.", LastName = "Blah", DisplayName = "blah", EmailAddress = "*****@*****.**"
            });

            Target.SaveChanges();

            using (EducationDataContext verifyContext = new EducationDataContext())
            {
                Assert.IsNotNull(verifyContext.Users.SingleOrDefault(u => u.UserKey == userKey));
            }
        }
        public void GivenEnableCachingFalse_WhenConfigure_ThenContextCachingNotConfigured()
        {
            ICache expected = MockRepository.GenerateMock <ICache>();

            MockKernel.Expect(m => m.Resolve <ICache>()).Return(expected);
            Target.EnableCaching = false;

            using (EducationDataContext actual = new EducationDataContext())
            {
                Target.Configure(MockKernel, actual);

                Assert.IsNull(actual.Cache);
                Assert.AreEqual(CachingPolicy.NoCaching, actual.CachingPolicy);
            }
        }
        public void GivenANewServiceType_WhenSaveChanges_ThenDatabaseContainsServiceType()
        {
            Target.ServiceTypes.Add(new ServiceType
            {
                Name = "Tester Service",
                Description = "Tester Service Description"
            });

            Target.SaveChanges();

            using (EducationDataContext verifyContext = new EducationDataContext())
            {
                Assert.IsNotNull(verifyContext.ServiceTypes.SingleOrDefault(s => s.Name.Equals("Tester Service")));
            }
        }
        public void GivenANewServiceType_WhenSaveChanges_ThenNewServiceTypeIsSaved()
        {
            ServiceType serviceType = new ServiceType
            {
                Name        = "Bob",
                Description = "Bob's Description",
            };

            Target.ServiceTypes.Add(serviceType);

            Target.SaveChanges();

            var secondaryClient = new EducationDataContext();
            var actual          = secondaryClient.ServiceTypes.Where(s => s.Name == "Bob").SingleOrDefault();

            Assert.IsNotNull(actual);
        }
        public void GivenStudentAssignedOfferingIsActive_WhenGenerateEditViewModel_ThenAuditDataPopulated()
        {
            int entityId;
            using (EducationDataContext setupContext = new EducationDataContext())
            {
                StudentAssignedOffering entity = setupContext.StudentAssignedOfferings.Single(a => a.LastModifyingUser != null);
                entity.IsActive = true;
                setupContext.SaveChanges();
                entityId = entity.Id;
            }

            StudentServiceOfferingScheduleModel actual = Target.GenerateEditViewModel(User, entityId);

            Assert.IsNotNull(actual.Audit.CreatedBy);
            Assert.AreNotEqual(DateTime.MinValue, actual.Audit.CreateTime);
            Assert.IsNotNull(actual.Audit.LastModifiedBy);
            Assert.IsTrue(actual.Audit.LastModifyTime.HasValue);
        }
        public void GivenProviderProgramAssociationsWereMade_WhenEdit_ThenProviderHasSelectedPrograms()
        {
            try
            {
                EducationSecurityPrincipal user = new EducationSecurityPrincipal(new UserRepository(EducationContext).Items.Where(s => s.UserKey == "Bob").Include("UserRoles.Role").Single());
                var expected = new int[] { 1, 2 };
                var provider = EducationContext.Providers.First();
                var viewModel = new ProviderModel { Id = provider.Id, Name = provider.Name, SelectedPrograms = expected, Address = provider.Address, Contact = provider.Contact, Website = provider.Website };

                Target.Edit(user, viewModel);

                using (EducationDataContext verificationContext = new EducationDataContext())
                {
                    var actual = verificationContext.Providers.Include(p => p.ServiceOfferings).Single(p => p.Id == viewModel.Id).ServiceOfferings.Where(s => s.IsActive).Select(s => s.ProgramId).Distinct();
                    CollectionAssert.AreEquivalent(expected, actual.ToList());
                }
            }
            finally
            {
                AssemblySetup.ForceDeleteEducationDatabase("SSD");
            }
        }
        public void GivenProviderWithApprovingStudents_WhenDelete_ThenNoApprovedProviderMappingsToDeletedProvider()
        {
            int toDeleteId;
            using (EducationDataContext setupContext = new EducationDataContext())
            {
                Provider temp = new Provider
                {
                    Name = "blah blah blah",
                    IsActive = true,
                    ApprovingStudents = setupContext.Students.ToList()
                };
                foreach (Student student in temp.ApprovingStudents)
                {
                    student.ApprovedProviders.Add(temp);
                }
                setupContext.Providers.Add(temp);
                setupContext.SaveChanges();
                toDeleteId = temp.Id;
            }

            Target.Delete(toDeleteId);

            Assert.IsFalse(EducationContext.Students.Any(s => s.ApprovedProviders.Select(p => p.Id).Contains(toDeleteId)));
        }
        public void GivenANewServiceType_WhenSaveChanges_ThenNewServiceTypeIsSaved()
        {
            ServiceType serviceType = new ServiceType
            {
                Name = "Bob",
                Description = "Bob's Description",
            };
            Target.ServiceTypes.Add(serviceType);

            Target.SaveChanges();

            var secondaryClient = new EducationDataContext();
            var actual = secondaryClient.ServiceTypes.Where(s => s.Name == "Bob").SingleOrDefault();
            Assert.IsNotNull(actual);
        }
        public void GivenValidViewModelHasSelectedProviders_WhenEdit_ThenProviderAssociationsChange()
        {
            try
            {
                EducationContext.Database.ExecuteSqlCommand("Update SSD.StudentAssignedOffering Set IsActive = 0");
                var expected = new int[] { 1, 2 };
                ProgramModel viewModel = new ProgramModel { Id = 2, Name = "something valid", SelectedProviders = expected, SelectedServiceTypes = new List<int> { 2 } };

                Target.Edit(viewModel);

                using (EducationDataContext assertContext = new EducationDataContext())
                {
                    var actual = assertContext.Programs.Include("ServiceOfferings.Provider").Single(p => p.Id == viewModel.Id).ServiceOfferings.Where(s => s.IsActive).Select(s => s.Provider).Distinct();
                    CollectionAssert.AreEquivalent(expected, actual.Select(p => p.Id).ToList());
                }
            }
            finally
            {
                AssemblySetup.ForceDeleteEducationDatabase("SSD");
            }
        }
 public void TestInitialize()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     ScheduledServiceManager logicManager = new ScheduledServiceManager(repositoryContainer);
     HttpContext context = new HttpContext(new HttpRequest("", "http://tempuri.org", ""), new HttpResponse(new StringWriter()));
     User = new EducationSecurityPrincipal(new UserRepository(EducationContext).Items.Where(s => s.UserKey == "Bob").Single());
     context.User = User;
     Target = new ServiceController(logicManager);
     ControllerContext controllerContext = new ControllerContext(new HttpContextWrapper(context), new RouteData(), Target);
     Target.ControllerContext = controllerContext;
 }
        public void GivenProviderWithUserAssociations_WhenDelete_ThenNoUserAssociationsToDeletedProvider()
        {
            int toDeleteId;
            using (EducationDataContext setupContext = new EducationDataContext())
            {
                Provider temp = new Provider
                {
                    Name = "halb halb halb",
                    IsActive = true,
                    UserRoles = setupContext.UserRoles.Where(u => u.Role.Name == SecurityRoles.Provider).ToList()
                };
                foreach (UserRole userRole in temp.UserRoles)
                {
                    userRole.Providers.Add(temp);
                }
                setupContext.Providers.Add(temp);
                setupContext.SaveChanges();
                toDeleteId = temp.Id;
            }

            Target.Delete(toDeleteId);

            Assert.IsFalse(EducationContext.UserRoles.Any(u => u.Providers.Select(p => p.Id).Contains(toDeleteId)));
        }
 public void InitializeTest()
 {
     _TestTransaction = new TransactionScope();
     Target = new EducationDataContext();
 }
        public void WhenDelete_ThenAssignedOfferingSetInactive()
        {
            Target.Delete(User, 3);

            using (EducationDataContext verificationContext = new EducationDataContext())
            {
                StudentAssignedOffering actual = verificationContext.StudentAssignedOfferings.Find(3);
                Assert.IsFalse(actual.IsActive);
            }
        }
        public void GivenANewUserIsAdded_WhenSaveChanges_ThenDatabaseContainsUser()
        {
            string userKey = Guid.NewGuid().ToString();
            Target.Users.Add(new User { UserKey = userKey, FirstName = "Mr.", LastName = "Blah", DisplayName = "blah", EmailAddress = "*****@*****.**" });

            Target.SaveChanges();

            using (EducationDataContext verifyContext = new EducationDataContext())
            {
                Assert.IsNotNull(verifyContext.Users.SingleOrDefault(u => u.UserKey == userKey));
            }
        }
 public void InitializeTest()
 {
     Context = new EducationDataContext();
     Target = new StudentRepository(Context);
 }
 public void InitializeTest()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     Target = new SchoolDistrictManager(repositoryContainer, new DataTableBinder(), new UserAuditor());
     User = new EducationSecurityPrincipal(EducationContext.Users.Include("UserRoles.Role").Single(u => u.UserKey == "Bob"));
     MockContext = MockHttpContextFactory.Create();
 }
 private static ServiceRequest CreateServiceRequestInDatabase(int creatingUserId, int priorityId)
 {
     using (EducationDataContext context = new EducationDataContext())
     {
         ServiceRequestFulfillment newServiceRequestFulfillment = new ServiceRequestFulfillment { FulfillmentStatusId = 1, Notes = "Test", CreatingUserId = 1 };
         ServiceRequest newRequestToEdit = new ServiceRequest { CreatingUserId = creatingUserId, PriorityId = priorityId, ServiceTypeId = 1, StudentId = 6, SubjectId = 2, FulfillmentDetails = new List<ServiceRequestFulfillment> { newServiceRequestFulfillment } };
         context.ServiceRequests.Add(newRequestToEdit);
         context.SaveChanges();
         return newRequestToEdit;
     }
 }
        public void GivenViewModelHasStudentId_AndStudentAssignedOffering_WhenPopulateViewModel_ThenAssignedOfferingContainsFullName()
        {
            int studentId = EducationContext.Students.Where(s => s.StudentAssignedOfferings.Any()).Select(s => s.Id).First();
            ServiceRequestModel viewModel = new ServiceRequestModel { StudentIds = new[] { studentId } };

            Target.PopulateViewModel(viewModel);

            using (EducationDataContext verificationContext = new EducationDataContext())
            {
                var expected = verificationContext.Students.Where(s => s.Id == studentId).Select(s => s.StudentAssignedOfferings.FirstOrDefault()).Select(a => new { Provider = a.ServiceOffering.Provider, Program = a.ServiceOffering.Program, ServiceType = a.ServiceOffering.ServiceType }).Single();

                StringAssert.Contains(viewModel.AssignedOfferings.First().Text, expected.Program.Name);
                StringAssert.Contains(viewModel.AssignedOfferings.First().Text, expected.Provider.Name);
                StringAssert.Contains(viewModel.AssignedOfferings.First().Text, expected.ServiceType.Name);
            }
        }
 public void InitializeTest()
 {
     _TestTransaction = new TransactionScope();
     try
     {
         IRepositoryContainer educationContainer = MockRepository.GenerateMock<IRepositoryContainer>();
         EducationDataContext = new EducationDataContext();
         educationContainer.Expect(m => m.Obtain<IUserRepository>()).Return(new UserRepository(EducationDataContext));
         educationContainer.Expect(m => m.Obtain<IEulaAgreementRepository>()).Return(new EulaAgreementRepository(EducationDataContext));
         MockWindsorContainer = MockRepository.GenerateMock<IWindsorContainer>();
         MockWindsorContainer.Expect(m => m.Resolve<IRepositoryContainer>()).Return(educationContainer);
         AccountManager = new AccountManager(MockWindsorContainer, MockRepository.GenerateMock<IEmailConfirmationManager>(), new DataTableBinder(), new UserAuditor());
         MockDependecyResolver = MockRepository.GenerateMock<IDependencyResolver>();
         MockDependecyResolver.Expect(m => m.GetService(typeof(IAccountManager))).Return(AccountManager);
         DependencyResolver.SetResolver(MockDependecyResolver);
     }
     catch (Exception)
     {
         _TestTransaction.Dispose();
         _TestTransaction = null;
         if (EducationDataContext != null)
         {
             EducationDataContext.Dispose();
             EducationDataContext = null;
         }
         throw;
     }
 }
        public void WhenInitializeDatabase_ThenFulfillmentStatusesPopulated()
        {
            List<string> expected = new List<string> { Statuses.Open, Statuses.Fulfilled, Statuses.Rejected };
            ResetDatabase();
            Target.Dispose();
            Target = new EducationDataContext();

            var actual = Target.FulfillmentStatuses.Select(f => f.Name).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
 public void InitializeTest()
 {
     _TestTransaction = new TransactionScope();
     Target           = new EducationDataContext();
 }
        public void WhenInitialize_ThenExpectedPropertiesAreProtected()
        {
            var expected = new List<Property>
            {
                new Property { EntityName = "SSD.Domain.Student", Name = "StudentKey" },
                new Property { EntityName = "SSD.Domain.Student", Name = "ServiceRequests" },
                new Property { EntityName = "SSD.Domain.Student", Name = "StudentAssignedOfferings" },
                new Property { EntityName = "SSD.Domain.ServiceOffering", Name = "StudentAssignedOfferings" }
            };
            ResetDatabase();
            Target.Dispose();
            Target = new EducationDataContext();

            var actual = Target.Properties.Where(p => p.IsProtected).ToList();

            Assert.IsTrue(expected.All(p => actual.Exists(a => a.Name == p.Name && a.EntityName == p.EntityName)));
            Assert.IsFalse(actual.Any(a => !expected.Exists(p => p.Name == a.Name && p.EntityName == a.EntityName)));
        }