コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        public void CreateKeyedRepository_Returns_Expected_Type()
        {
            DbSession dbSession = GetSession();

            IKeyedRepository <int, Person> repository = dbSession.CreateKeyedRepository <int, Person>();

            Assert.IsNotNull(repository);
        }
コード例 #4
0
 public void CreateKeyedRepository_Returns_Expected_Type()
 {
     using (IDbSession dbSession = _dbSessionFactory.Create())
     {
         IKeyedRepository <int, Person> repository = dbSession.CreateKeyedRepository <int, Person>();
         Assert.IsNotNull(repository);
     }
 }
コード例 #5
0
 public NavigationController
 (
     IKeyedRepository <Guid, Page> pageRepository,
     IKeyedRepository <Guid, Role> roleRepository
 )
 {
     _pageRepository = pageRepository;
     _roleRepository = roleRepository;
 }
コード例 #6
0
 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;
 }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: AccountController.cs プロジェクト: dheindel/gpsnerd
 public AccountController(
     IFormsAuthentication formsAuthentication,
     IKeyedRepository<int, User> userRepository,
     IUnitOfWork unitOfWork,
     ILogger logger,
     DataService dataService)
     : base(logger, dataService)
 {
     _formsAuth = formsAuthentication;
     _unitOfWork = unitOfWork;
 }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
ファイル: DataService.cs プロジェクト: dheindel/gpsnerd
        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);
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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);
                }
            }
        }
コード例 #16
0
        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();
            }
        }
コード例 #17
0
        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();
            }
        }
コード例 #18
0
        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();
            }
        }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
 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;
 }
コード例 #21
0
        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();
            }
        }
コード例 #22
0
        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();
            }
        }
コード例 #23
0
        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();
            }
        }
コード例 #24
0
ファイル: UserService.cs プロジェクト: dheindel/gpsnerd
 public UserService(IKeyedRepository<int, User> userRepo)
 {
     _userRepo = userRepo;
     _validation = new UserValidator(userRepo);
 }
コード例 #25
0
ファイル: LocationService.cs プロジェクト: dheindel/gpsnerd
 public LocationService(IKeyedRepository<int, Location> locationRepo)
 {
     _repo = locationRepo;
     _validation = new LocationValidator();
 }
コード例 #26
0
 public PostController(IKeyedRepository<Post, Guid> postRepository, IKeyedRepository<Topic, Guid> topicRepository)
 {
     _postRepository = postRepository;
     _topicRepository = topicRepository;
 }
コード例 #27
0
 public AttachmentController(IKeyedRepository<Attachment, Guid> attachmentRepository,
                             IKeyedRepository<Entry, Guid> entryRepository)
 {
     _attachmentRepository = attachmentRepository;
     _entryRepository = entryRepository;
 }
コード例 #28
0
ファイル: TruckService.cs プロジェクト: dheindel/gpsnerd
 public TruckService(IKeyedRepository<int, Truck> truckRepo)
 {
     _truckRepo = truckRepo;
     _validation = new TruckValidator();
 }
コード例 #29
0
 public ForumController(IKeyedRepository<Forum, Guid> repository)
 {
     _repository = repository;
 }
コード例 #30
0
 public TopicController(IKeyedRepository<Topic, Guid> topicRepository, IKeyedRepository<Forum, Guid> forumRepository)
 {
     _topicRepository = topicRepository;
     _forumRepository = forumRepository;
 }
コード例 #31
0
 public static void Test(IKeyedRepository <TKey, TEntity> repo)
 {
     Test(repo, null);
 }
コード例 #32
0
        public static void Test(IKeyedRepository <TKey, TEntity> repo, List <string> protectedPropertyNames)
        {
            TEntity entity1 = Random <TEntity> .Create(protectedPropertyNames);

            Test(repo, protectedPropertyNames, entity1);
        }
コード例 #33
0
 public UsersController(IKeyedRepository <Guid, User> userRepository, IKeyedRepository <Guid, UserProfile> userProfileRepository, IKeyedRepository <Guid, Role> roleRepository)
 {
     _userRepository        = userRepository;
     _userProfileRepository = userProfileRepository;
     _roleRepository        = roleRepository;
 }