コード例 #1
0
        public void EFLinqRepository_Delete_Throws_With_Invalid_ID()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);
            var dog        = new Dog
            {
                ID   = TestConstants.EF_InvalidDogId,
                Age  = TestConstants.EF_DeleteDogAge,
                Name = TestConstants.EF_DeleteDogName
            };

            //Act
            var success = false;

            try
            {
                repository.Delete(dog);
                _efUnitOfWork.Commit();
                success = true;
            }
            catch (Exception)
            {
            }

            //Assert
            Assert.IsFalse(success);
        }
コード例 #2
0
        public void EFLinqRepository_Update_Updates_Item_With_Correct_ID()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);
            var dog        = new Dog
            {
                ID   = TestConstants.EF_UpdateDogId,
                Age  = TestConstants.EF_UpdateDogAge,
                Name = TestConstants.EF_UpdateDogName
            };

            //Act
            repository.Update(dog);
            _efUnitOfWork.Commit();

            //Assert
            DataTable table = DataUtil.GetTable(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);

            foreach (DataRow row in table.Rows)
            {
                if ((int)row["ID"] == TestConstants.EF_UpdateDogId)
                {
                    Assert.AreEqual(TestConstants.EF_UpdateDogAge, row["Age"]);
                    Assert.AreEqual(TestConstants.EF_UpdateDogName, row["Name"]);
                }
            }
        }
コード例 #3
0
        public void EFLinqRepository_GetPage_Returns_Page_Of_Rows(int pageIndex, int pageSize)
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(pageIndex, pageSize);

            //Assert
            Assert.AreEqual(pageSize, dogs.PageSize);
        }
コード例 #4
0
        public void EFLinqRepository_GetAll_Returns_All_Rows(int count)
        {
            //Arrange
            SetUpDatabase(count);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            IEnumerable <Dog> dogs = repository.GetAll();

            //Assert
            Assert.AreEqual(count, dogs.Count());
        }
コード例 #5
0
        public void EFLinqRepository_Find_Returns_Instance_Of_Model_If_Valid_Property()
        {
            //Arrange
            SetUpDatabase(5);
            var dogName = _dogNames[2];

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dog = repository.Find((d) => d.Name == dogName).FirstOrDefault();

            //Assert
            Assert.IsInstanceOf <Dog>(dog);
        }
コード例 #6
0
        public void EFLinqRepository_Find_Returns_List_Of_Models_If_Valid_Property(string dogName, int count)
        {
            //Arrange
            SetUpDatabase(5);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.Find((d) => d.Name == dogName);

            //Assert
            Assert.IsInstanceOf <IEnumerable <Dog> >(dogs);
            Assert.AreEqual(count, dogs.Count());
        }
コード例 #7
0
        public void EFLinqRepository_GetPage_Returns_Correct_Page(int pageIndex, int pageSize, int firstId)
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(pageIndex, pageSize);

            //Assert
            var dog = dogs.First();

            Assert.AreEqual(firstId, dog.ID);
        }
コード例 #8
0
        public void EFLinqRepository_Find_Returns_Empty_List_If_InValid_Proeprty()
        {
            //Arrange
            SetUpDatabase(5);
            const string dogName = "Invalid";

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.Find((d) => d.Name == dogName);

            //Assert
            Assert.IsInstanceOf <IEnumerable <Dog> >(dogs);
            Assert.AreEqual(0, dogs.Count());
        }
コード例 #9
0
        public void EFLinqRepository_GetPage_Returns_List_Of_Models()
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(TestConstants.PAGE_First, TestConstants.PAGE_RecordCount);

            //Assert
            for (int i = 0; i < dogs.Count(); i++)
            {
                Assert.IsInstanceOf <Dog>(dogs[i]);
            }
        }
コード例 #10
0
        public void EFLinqRepository_GetPage_Returns_Models_With_Correct_Properties()
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(TestConstants.PAGE_First, TestConstants.PAGE_RecordCount);

            //Assert
            var dog = dogs.First();

            Assert.AreEqual(_dogAges[0], dog.Age.ToString());
            Assert.AreEqual(_dogNames[0], dog.Name);
        }
コード例 #11
0
        public void EFLinqRepository_GetAll_Returns_Models_With_Correct_Properties()
        {
            //Arrange
            SetUpDatabase(5);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetAll();

            //Assert
            var dog = dogs.First();

            Assert.AreEqual(_dogAges[0], dog.Age.ToString());
            Assert.AreEqual(_dogNames[0], dog.Name);
        }
コード例 #12
0
        public void EFLinqRepository_Find_Returns_Models_With_Correct_Properties(string dogName)
        {
            //Arrange
            SetUpDatabase(5);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.Find((d) => d.Name == dogName);

            //Assert
            foreach (Dog dog in dogs)
            {
                Assert.AreEqual(dogName, dog.Name);
            }
        }
コード例 #13
0
        public void EFLinqRepository_GetAll_Returns_List_Of_Models()
        {
            //Arrange
            var mockCache = new Mock <ICacheProvider>();

            SetUpDatabase(5);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetAll().ToList();

            //Assert
            for (int i = 0; i < dogs.Count(); i++)
            {
                Assert.IsInstanceOf <Dog>(dogs[i]);
            }
        }
コード例 #14
0
        public void EFLinqRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ID()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);
            var dog = new Dog
                            {
                                Age = TestConstants.EF_InsertDogAge,
                                Name = TestConstants.EF_InsertDogName
                            };

            //Act
            repository.Add(dog);
            _efUnitOfWork.Commit();

            //Assert
            int newId = DataUtil.GetLastAddedRecordID(TestConstants.EF_DatabaseName, TestConstants.EF_TableName, "ID");
            Assert.AreEqual(TestConstants.EF_RecordCount + 1, newId);
        }
コード例 #15
0
        public void EFLinqRepository_Add_Inserts_Item_Into_DataBase()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);
            var dog = new Dog
                            {
                                Age = TestConstants.EF_InsertDogAge,
                                Name = TestConstants.EF_InsertDogName
                            };

            //Act
            repository.Add(dog);
            _efUnitOfWork.Commit();

            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);
            Assert.AreEqual(TestConstants.EF_RecordCount + 1, actualCount);
        }
コード例 #16
0
        public void EFLinqRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ID()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);
            var dog        = new Dog
            {
                Age  = TestConstants.EF_InsertDogAge,
                Name = TestConstants.EF_InsertDogName
            };

            //Act
            repository.Add(dog);
            _efUnitOfWork.Commit();

            //Assert
            int newId = DataUtil.GetLastAddedRecordID(TestConstants.EF_DatabaseName, TestConstants.EF_TableName, "ID");

            Assert.AreEqual(TestConstants.EF_RecordCount + 1, newId);
        }
コード例 #17
0
        public void EFLinqRepository_Add_Inserts_Item_Into_DataBase()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);
            var dog        = new Dog
            {
                Age  = TestConstants.EF_InsertDogAge,
                Name = TestConstants.EF_InsertDogName
            };

            //Act
            repository.Add(dog);
            _efUnitOfWork.Commit();

            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);

            Assert.AreEqual(TestConstants.EF_RecordCount + 1, actualCount);
        }
コード例 #18
0
        public void EFLinqRepository_Delete_Deletes_Item_From_DataBase()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);
            var dog        = new Dog
            {
                ID   = TestConstants.EF_DeleteDogId,
                Age  = TestConstants.EF_DeleteDogAge,
                Name = TestConstants.EF_DeleteDogName
            };

            //Act
            repository.Delete(dog);
            _efUnitOfWork.Commit();

            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);

            Assert.AreEqual(TestConstants.EF_RecordCount - 1, actualCount);
        }
コード例 #19
0
        public void EFLinqRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository <Dog>(_efUnitOfWork, _cache.Object);
            var dog        = new Dog
            {
                Age  = TestConstants.EF_InsertDogAge,
                Name = TestConstants.EF_InsertDogName
            };

            //Act
            repository.Add(dog);
            _efUnitOfWork.Commit();

            //Assert
            DataTable table = DataUtil.GetTable(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);
            DataRow   row   = table.Rows[table.Rows.Count - 1];

            Assert.AreEqual(TestConstants.EF_InsertDogAge, row["Age"]);
            Assert.AreEqual(TestConstants.EF_InsertDogName, row["Name"]);
        }
コード例 #20
0
        public void EFLinqRepository_Find_Returns_List_Of_Models_If_Valid_Property(string dogName, int count)
        {
            //Arrange
            SetUpDatabase(5);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.Find((d) => d.Name == dogName);

            //Assert
            Assert.IsInstanceOf<IEnumerable<Dog>>(dogs);
            Assert.AreEqual(count, dogs.Count());
        }
コード例 #21
0
        public void EFLinqRepository_Delete_Deletes_Item_From_DataBase()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);
            var dog = new Dog
                            {
                                ID = TestConstants.EF_DeleteDogId,
                                Age = TestConstants.EF_DeleteDogAge,
                                Name = TestConstants.EF_DeleteDogName
                            };

            //Act
            repository.Delete(dog);
            _efUnitOfWork.Commit();

            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);
            Assert.AreEqual(TestConstants.EF_RecordCount - 1, actualCount);
        }
コード例 #22
0
        public void EFLinqRepository_Find_Returns_Empty_List_If_InValid_Proeprty()
        {
            //Arrange
            SetUpDatabase(5);
            const string dogName = "Invalid";

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.Find((d) => d.Name == dogName);

            //Assert
            Assert.IsInstanceOf<IEnumerable<Dog>>(dogs);
            Assert.AreEqual(0, dogs.Count());
        }
コード例 #23
0
        public void EFLinqRepository_Find_Returns_Instance_Of_Model_If_Valid_Property()
        {
            //Arrange
            SetUpDatabase(5);
            var dogName = _dogNames[2];

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dog = repository.Find((d) => d.Name == dogName).FirstOrDefault();

            //Assert
            Assert.IsInstanceOf<Dog>(dog);
        }
コード例 #24
0
        public void EFLinqRepository_GetAll_Returns_All_Rows(int count)
        {
            //Arrange
            SetUpDatabase(count);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            IEnumerable<Dog> dogs = repository.GetAll();

            //Assert
            Assert.AreEqual(count, dogs.Count());
        }
コード例 #25
0
        public void EFLinqRepository_Find_Returns_Models_With_Correct_Properties(string dogName)
        {
            //Arrange
            SetUpDatabase(5);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.Find((d) => d.Name == dogName);

            //Assert
            foreach (Dog dog in dogs)
            {
                Assert.AreEqual(dogName, dog.Name);
            }
        }
コード例 #26
0
        public void EFLinqRepository_GetAll_Returns_Models_With_Correct_Properties()
        {
            //Arrange
            SetUpDatabase(5);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetAll();

            //Assert
            var dog = dogs.First();
            Assert.AreEqual(_dogAges[0], dog.Age.ToString());
            Assert.AreEqual(_dogNames[0], dog.Name);
        }
コード例 #27
0
        public void EFLinqRepository_GetAll_Returns_List_Of_Models()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(5);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetAll().ToList();

            //Assert
            for (int i = 0; i < dogs.Count(); i++)
            {
                Assert.IsInstanceOf<Dog>(dogs[i]);
            }
        }
コード例 #28
0
        public void EFLinqRepository_GetPage_Returns_List_Of_Models()
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(TestConstants.PAGE_First, TestConstants.PAGE_RecordCount);

            //Assert
            for (int i = 0; i < dogs.Count(); i++)
            {
                Assert.IsInstanceOf<Dog>(dogs[i]);
            }
        }
コード例 #29
0
        public void EFLinqRepository_GetPage_Returns_Page_Of_Rows(int pageIndex, int pageSize)
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(pageIndex, pageSize);

            //Assert
            Assert.AreEqual(pageSize, dogs.PageSize);
        }
コード例 #30
0
        public void EFLinqRepository_GetPage_Returns_Models_With_Correct_Properties()
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(TestConstants.PAGE_First, TestConstants.PAGE_RecordCount);

            //Assert
            var dog = dogs.First();
            Assert.AreEqual(_dogAges[0], dog.Age.ToString());
            Assert.AreEqual(_dogNames[0], dog.Name);
        }
コード例 #31
0
        public void EFLinqRepository_GetPage_Returns_Correct_Page(int pageIndex, int pageSize, int firstId)
        {
            //Arrange
            SetUpDatabase(TestConstants.PAGE_TotalCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);

            //Act
            var dogs = repository.GetPage(pageIndex, pageSize);

            //Assert
            var dog = dogs.First();
            Assert.AreEqual(firstId, dog.ID);
        }
コード例 #32
0
        public void EFLinqRepository_Update_Updates_Item_With_Correct_ID()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);
            var dog = new Dog
                            {
                                ID = TestConstants.EF_UpdateDogId,
                                Age = TestConstants.EF_UpdateDogAge,
                                Name = TestConstants.EF_UpdateDogName
                            };

            //Act
            repository.Update(dog);
            _efUnitOfWork.Commit();

            //Assert
            DataTable table = DataUtil.GetTable(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);
            foreach (DataRow row in table.Rows)
            {
                if ((int)row["ID"] == TestConstants.EF_UpdateDogId)
                {
                    Assert.AreEqual(TestConstants.EF_UpdateDogAge, row["Age"]);
                    Assert.AreEqual(TestConstants.EF_UpdateDogName, row["Name"]);
                }
            }
        }
コード例 #33
0
        public void EFLinqRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);
            var dog = new Dog
                            {
                                Age = TestConstants.EF_InsertDogAge,
                                Name = TestConstants.EF_InsertDogName
                            };

            //Act
            repository.Add(dog);
            _efUnitOfWork.Commit();

            //Assert
            DataTable table = DataUtil.GetTable(TestConstants.EF_DatabaseName, TestConstants.EF_TableName);
            DataRow row = table.Rows[table.Rows.Count - 1];

            Assert.AreEqual(TestConstants.EF_InsertDogAge, row["Age"]);
            Assert.AreEqual(TestConstants.EF_InsertDogName, row["Name"]);
        }
コード例 #34
0
        public void EFLinqRepository_Delete_Throws_With_Invalid_ID()
        {
            //Arrange
            SetUpDatabase(TestConstants.EF_RecordCount);

            var repository = new EFLinqRepository<Dog>(_efUnitOfWork, _cache.Object);
            var dog = new Dog
                            {
                                ID = TestConstants.EF_InvalidDogId,
                                Age = TestConstants.EF_DeleteDogAge,
                                Name = TestConstants.EF_DeleteDogName
                            };

            //Act
            var success = false;
            try
            {
                repository.Delete(dog);
                _efUnitOfWork.Commit();
                success = true;
            }
            catch (Exception)
            {
                
            }

            //Assert
            Assert.IsFalse(success);
        }