public void Should_persist_the_lea_mapping_without_explicitly_adding_that_mapping_to_the_databaseContext() { using (var context = new SqlServerUsersContext(ConnectionString)) { //Arrange var lea = new ApplicationEducationOrganization { EducationOrganizationId = leaId }; var client = new ApiClient(true) { Name = clientName }; client.ApplicationEducationOrganizations.Add(lea); //Act context.Clients.Add(client); context.SaveChangesForTest(); //Assert var clientFromDb = context.Clients.Where(x => x.Name == clientName) .Include(x => x.ApplicationEducationOrganizations) .Single(); int[] leas = clientFromDb.ApplicationEducationOrganizations.Select(x => x.EducationOrganizationId) .ToArray(); leas.ShouldBe( new[] { leaId }); } }
public void Should_create_lea_association() { //Arrange var vendor = new Vendor { VendorName = vendorName }; vendor.CreateApplication(appName, ClaimSetName); var educationOrganizationAssociation = vendor.Applications.AsEnumerable() .ElementAt(0) .CreateApplicationEducationOrganization(leaId); using (var context = new SqlServerUsersContext(ConnectionString)) { vendor.Applications.AsEnumerable() .ElementAt(0) .OperationalContextUri = "uri://ed-fi-api-host.org"; context.ApplicationEducationOrganizations.AddOrUpdate(educationOrganizationAssociation); context.Vendors.Add(vendor); context.SaveChangesForTest(); //Act var application = context.Applications.Where(app => app.ApplicationName == appName) .Include(x => x.ApplicationEducationOrganizations) .Single(); var applicationLocalEducationAgencies = application.ApplicationEducationOrganizations.ToArray(); applicationLocalEducationAgencies.Length.ShouldBe(1); applicationLocalEducationAgencies[0] .EducationOrganizationId.ShouldBe(leaId); } }
public void Should_create_application() { //Arrange var vendor = new Vendor { VendorName = vendorName }; vendor.CreateApplication(appName, ClaimSetName); using (var context = new SqlServerUsersContext(ConnectionString)) { vendor.Applications.AsEnumerable() .ElementAt(0) .OperationalContextUri = "uri://ed-fi-api-host.org"; context.Vendors.Add(vendor); context.SaveChangesForTest(); //Act var vendorFromDb = context.Vendors.Where(v => v.VendorName == vendorName) .Include(x => x.Applications) .Single(); //Assert vendorFromDb.ShouldNotBeNull(); vendorFromDb.Applications.Count.ShouldBe(1); vendorFromDb.Applications.ToList()[0] .ApplicationName.ShouldBe(appName); } }
public void Should_persist_the_lea_mapping_without_explicitly_adding_that_mapping_to_the_databaseContext() { using (var context = new SqlServerUsersContext(ConnectionString)) { //Arrange var lea = new ApplicationEducationOrganization { EducationOrganizationId = leaId }; var application = new Application { ApplicationName = appName }; application.ApplicationEducationOrganizations.Add(lea); application.OperationalContextUri = "uri://ed-fi-api-host.org"; //Act context.Applications.Add(application); context.SaveChangesForTest(); //Assert var applicationFromDb = context.Applications.Where(x => x.ApplicationName == appName) .Include(x => x.ApplicationEducationOrganizations) .Single(); int[] leas = applicationFromDb.ApplicationEducationOrganizations.Select(x => x.EducationOrganizationId) .ToArray(); leas.ShouldBe( new[] { leaId }); } }
protected void Delete <T>( Func <SqlServerUsersContext, IDbSet <T> > dbObject, Func <SqlServerUsersContext, IQueryable <T> > filter) where T : class { using (var context = new SqlServerUsersContext()) { foreach (var tDelete in filter(context)) { dbObject(context) .Remove(tDelete); } context.SaveChangesForTest(); } }
public void Should_persist_the_user_to_the_database() { using (var context = new SqlServerUsersContext(ConnectionString)) { //Arrange var user = new User { Email = emailAddress }; //Act context.Users.Add(user); context.SaveChangesForTest(); //Assert context.Users.Count(x => x.Email == emailAddress) .ShouldBe(1); } }