public void Create_Adds_Entities_To_The_Table() { int currentCount; const int numToAdd = 3; using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); // create currentCount = repo.All().Count(); for (int i = 0; i < numToAdd; i++) { Assert.IsTrue(repo.Add(CreatePerson())); } dbSession.Commit(); } using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); int newCount = repo.All().Count(); Assert.IsTrue(currentCount + numToAdd == newCount); } }
public void Create_Adds_A_List_Of_Entities_To_The_Table() { int startCount; const int numToAdd = 3; List <Person> localList = new List <Person>(); for (int i = 0; i < numToAdd; i++) { localList.Add(CreatePerson()); } using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); // create startCount = repo.All().Count(); Assert.IsTrue(repo.Add(localList)); dbSession.Commit(); } using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); int finalCount = repo.All().Count(); Assert.IsTrue(finalCount == startCount + numToAdd); } }
public void CreateKeyedRepository_Returns_Expected_Type() { DbSession dbSession = GetSession(); IKeyedRepository <int, Person> repository = dbSession.CreateKeyedRepository <int, Person>(); Assert.IsNotNull(repository); }
public void CreateKeyedRepository_Returns_Expected_Type() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <int, Person> repository = dbSession.CreateKeyedRepository <int, Person>(); Assert.IsNotNull(repository); } }
public NavigationController ( IKeyedRepository <Guid, Page> pageRepository, IKeyedRepository <Guid, Role> roleRepository ) { _pageRepository = pageRepository; _roleRepository = roleRepository; }
public override void RunBeforeAnyTests() { base.RunBeforeAnyTests(); _pageRepository = kernel.Get <IKeyedRepository <Guid, Page> >(); _pagePermissionRepository = kernel.Get <IKeyedRepository <Guid, PagePermission> >(); _roleRepository = kernel.Get <IKeyedRepository <Guid, Role> >(); _portal = Lightweight.Business.Providers.Portal.PortalProviderManager.Provider.GetCurrentPortal(); _navigationProvider = Lightweight.Business.Providers.Navigation.NavigationProviderManager.Provider; }
public static void Test(IKeyedRepository <TKey, TEntity> repo, List <string> protectedPropertyNames, TEntity seed) { // Get the inital count int countBefore = repo.All().Count(); // Look for the seed.Id item in the DB; if found, refresh up to 5 times then error. int loopCount = 0; while (true) { var item = repo.FindBy(seed.Id); if (item == null) { break; } if (loopCount > 4) { Assert.Fail("Can't find a unique new key for: " + repo.GetType().Name); return; } seed = Random <TEntity> .UpdateSpecifiedProperties(seed, new List <string> { "Id" }); loopCount += 1; } // add repo.Insert(seed); int countAfter = repo.All().Count(); Assert.IsTrue(countBefore + 1 == countAfter); // read TEntity entity2 = repo.FindBy(seed.Id); //Assert.IsTrue(seed.Equals(entity2)); Assert.IsTrue(Comparison.PublicInstancePropertiesEqual(seed, entity2, protectedPropertyNames)); // update protectedPropertyNames.Add("Id"); // Make sure Id is now in the list. seed = Random <TEntity> .Update(seed, protectedPropertyNames); repo.Update(seed); TEntity entity3 = repo.FindBy(seed.Id); Assert.IsFalse(Comparison.PublicInstancePropertiesEqual(entity2, seed, protectedPropertyNames)); Assert.IsTrue(Comparison.PublicInstancePropertiesEqual(entity3, seed, protectedPropertyNames)); // delete repo.Delete(seed.Id); countAfter = repo.All().Count(); Assert.IsTrue(countAfter == countBefore); }
public AccountController( IFormsAuthentication formsAuthentication, IKeyedRepository<int, User> userRepository, IUnitOfWork unitOfWork, ILogger logger, DataService dataService) : base(logger, dataService) { _formsAuth = formsAuthentication; _unitOfWork = unitOfWork; }
public void Delete_Returns_True_And_Removes_A_List_Of_Entities_If_Found() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>(); int expected = repo.All().Count() - _persons.Count; Assert.IsTrue(repo.Delete(_persons)); Assert.IsTrue(repo.All().Count() == expected); } }
public void Read_Returns_Null_If_Id_Does_Not_Exist() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); Person shouldBeNull = repo.FindBy(Guid.NewGuid()); Assert.IsNull(shouldBeNull); dbSession.Commit(); } }
private void AddTestData() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); for (int i = 0; i < 5; i++) { repo.Add(CreatePerson()); } dbSession.Commit(); } }
public void Commit_And_Rollback_Work() { Person person = new Person { Id = Guid.NewGuid(), FirstName = Guid.NewGuid().ToString(), LastName = Guid.NewGuid().ToString() }; // Rollback using (DbSession dbSession = GetSession()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); repo.Add(person); dbSession.Rollback(); } using (DbSession dbSession = GetSession()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); Assert.IsNull(repo.FindBy(person.Id)); } // Commit using (DbSession dbSession = GetSession()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); repo.Add(person); dbSession.Commit(); } using (DbSession dbSession = GetSession()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); Assert.IsNotNull(repo.FindBy(person.Id)); } // Cleanup using (DbSession dbSession = GetSession()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); repo.Delete(person); dbSession.Commit(); } }
public DataService(IKeyedRepository<int, User> userRepo, IKeyedRepository<int, Truck> truckRepo, IKeyedRepository<int, Location> locationRepo, IUnitOfWork unitOfWork) { _userRepo = userRepo; _truckRepo = truckRepo; _locationRepo = locationRepo; _unitOfWork = unitOfWork; Users = new UserService(userRepo); Trucks = new TruckService(truckRepo); Locations = new LocationService(locationRepo); }
public void Delete_Returns_False_If_Does_Not_Exist_And_Does_Not_Modify_List() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); int countBefore = repo.All().Count(); Person doesNotExist = new Person { FirstName = "I do not exist", LastName = "I do not exist" }; Assert.IsFalse(repo.Delete(doesNotExist)); Assert.IsTrue(repo.All().Count() == countBefore); } }
public void Delete_Returns_True_And_Removes_Entity_If_Found() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>(); int expectedCount = repo.All().Count(); foreach (Person person in _persons) { Assert.IsTrue(repo.All().Count() == expectedCount--); Assert.IsTrue(repo.Delete(person)); Assert.IsTrue(repo.All().Count() == expectedCount); } } }
private void CleanUp() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); // delete what we created foreach (Person person in _persons) { repo.Delete(person); } dbSession.Commit(); } }
public void All_Returns_Expected() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); List <Person> all = repo.All().ToList(); Assert.IsTrue(all.Count >= _persons.Count); foreach (Person person in _persons) { Assert.IsTrue(all.IndexOf(person) != -1); } dbSession.Commit(); } }
public void Update_Returns_True_And_Modifies_Exising() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); int countBefore = repo.All().Count(); Person person1Updated = repo.FindBy(_persons[0].Id); person1Updated.LastName = Guid.NewGuid().ToString(); Assert.IsTrue(repo.Update(person1Updated)); Assert.AreNotEqual(person1Updated, _persons[0]); Assert.IsTrue(repo.All().Count() == countBefore); dbSession.Commit(); } }
public void Update_Returns_False_If_Does_Not_Exist_And_Does_Not_Modify_List() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>(); int countBefore = repo.All().Count(); Person doesNotExist = new Person { FirstName = "Julio", LastName = "Gonzalas" }; Assert.IsFalse(repo.Update(doesNotExist)); Assert.IsTrue(repo.All().Count() == countBefore); dbSession.Commit(); } }
public PageController( IKeyedRepository <Guid, Page> pageRepository, IKeyedRepository <Guid, PageWidget> pageWidgetRepository, IKeyedRepository <Guid, Module> moduleRepository, IKeyedRepository <Guid, PagePermission> pagePermissionRepository, IKeyedRepository <Guid, User> userRepository, IKeyedRepository <Guid, Role> roleRepository ) { _pageRepository = pageRepository; _pageWidgetRepository = pageWidgetRepository; _moduleRepository = moduleRepository; _pagePermissionRepository = pagePermissionRepository; _userRepository = userRepository; _roleRepository = roleRepository; }
public void Read_Finds_Exising() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>(); foreach (Person person in _persons) { Person copy = repo.FindBy(person.Id); Assert.IsNotNull(copy); Assert.IsTrue(copy.Equals(person)); } dbSession.Commit(); } }
public void Create_Adds_Entities_To_The_Table() { using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>(); // create int expectedCount = repo.All().Count(); for (int i = 0; i < 3; i++) { Assert.IsTrue(repo.All().Count() == expectedCount++); Assert.IsTrue(repo.Add(CreatePerson())); Assert.IsTrue(repo.All().Count() == expectedCount); } dbSession.Commit(); } }
public void Create_Adds_A_List_Of_Entities_To_The_Table() { List <Person> localList = new List <Person>(); for (int i = 0; i < 3; i++) { localList.Add(CreatePerson()); } using (IDbSession dbSession = _dbSessionFactory.Create()) { IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>(); // create int countBefore = repo.All().Count(); Assert.IsTrue(repo.Add(localList)); Assert.IsTrue(repo.All().Count() == countBefore + localList.Count); dbSession.Commit(); } }
public UserService(IKeyedRepository<int, User> userRepo) { _userRepo = userRepo; _validation = new UserValidator(userRepo); }
public LocationService(IKeyedRepository<int, Location> locationRepo) { _repo = locationRepo; _validation = new LocationValidator(); }
public PostController(IKeyedRepository<Post, Guid> postRepository, IKeyedRepository<Topic, Guid> topicRepository) { _postRepository = postRepository; _topicRepository = topicRepository; }
public AttachmentController(IKeyedRepository<Attachment, Guid> attachmentRepository, IKeyedRepository<Entry, Guid> entryRepository) { _attachmentRepository = attachmentRepository; _entryRepository = entryRepository; }
public TruckService(IKeyedRepository<int, Truck> truckRepo) { _truckRepo = truckRepo; _validation = new TruckValidator(); }
public ForumController(IKeyedRepository<Forum, Guid> repository) { _repository = repository; }
public TopicController(IKeyedRepository<Topic, Guid> topicRepository, IKeyedRepository<Forum, Guid> forumRepository) { _topicRepository = topicRepository; _forumRepository = forumRepository; }
public static void Test(IKeyedRepository <TKey, TEntity> repo) { Test(repo, null); }
public static void Test(IKeyedRepository <TKey, TEntity> repo, List <string> protectedPropertyNames) { TEntity entity1 = Random <TEntity> .Create(protectedPropertyNames); Test(repo, protectedPropertyNames, entity1); }
public UsersController(IKeyedRepository <Guid, User> userRepository, IKeyedRepository <Guid, UserProfile> userProfileRepository, IKeyedRepository <Guid, Role> roleRepository) { _userRepository = userRepository; _userProfileRepository = userProfileRepository; _roleRepository = roleRepository; }