示例#1
0
        public void RavenDBRepository_Add_Inserts_Item_Into_DataBase()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            using (IDocumentSession _ravenDB = RavenDBDocumentStore.Instance.OpenSession())
            {
                var repository = new RavenDBRepository<Dog>(_ravenDB, mockCache.Object);
                var dog = new Dog
                {
                    Age = TestConstants.PETAPOCO_InsertDogAge,
                    Name = TestConstants.PETAPOCO_InsertDogName
                };

                //Act
                repository.Add(dog);

                //The change is not persisted until the session's changes are saved
                _ravenDB.SaveChanges();
            }

            //Assert
            Thread.Sleep(5000);
            int actualCount;
            using (IDocumentSession session = RavenDBDocumentStore.Instance.OpenSession())
            {
                actualCount = session.Query<Dog>().Count();
            }
            Assert.AreEqual(TestConstants.PETAPOCO_RecordCount + 1, actualCount);
        }
示例#2
0
        public void RavenDBRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            using (IDocumentSession _ravenDB = RavenDBDocumentStore.Instance.OpenSession())
            {
                var repository = new RavenDBRepository<Dog>(_ravenDB, mockCache.Object);
                var dog = new Dog
                {
                    Age = TestConstants.PETAPOCO_InsertDogAge,
                    Name = TestConstants.PETAPOCO_InsertDogName
                };

                //Act
                repository.Add(dog);

                //The change is not persisted until the session's changes are saved
                _ravenDB.SaveChanges();
            }

            //Assert
            Thread.Sleep(5000);
            Dog newDog = GetLastItemAdded();
            Assert.AreEqual(TestConstants.PETAPOCO_InsertDogAge, newDog.Age);
            Assert.AreEqual(TestConstants.PETAPOCO_InsertDogName, newDog.Name);
        }
        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);
        }
        public void NPocoRepository_Add_Inserts_Item_Into_DataBase()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.NPOCO_RecordCount);

            var repository = new NPocoRepository<Dog>(_nPocoUnitOfWork, mockCache.Object);
            var dog = new Dog
                            {
                                Age = TestConstants.NPOCO_InsertDogAge,
                                Name = TestConstants.NPOCO_InsertDogName
                            };

            //Act
            repository.Add(dog);

            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.NPOCO_DatabaseName, TestConstants.NPOCO_TableName);
            Assert.AreEqual(TestConstants.NPOCO_RecordCount + 1, actualCount);
        }
        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);
        }
示例#6
0
        public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ColumnValues()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            var repository = new PetaPocoRepository<Dog>(_pecaPocoDb, mockCache.Object);
            var dog = new Dog
            {
                Age = TestConstants.PETAPOCO_InsertDogAge,
                Name = TestConstants.PETAPOCO_InsertDogName
            };

            //Act
            repository.Add(dog);

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

            Assert.AreEqual(TestConstants.PETAPOCO_InsertDogAge, row["Age"]);
            Assert.AreEqual(TestConstants.PETAPOCO_InsertDogName, row["Name"]);
        }
        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"]);
                }
            }
        }
        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);
        }
        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);
        }
        public void NPocoRepository_Update_Updates_Item_With_Correct_ID()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.NPOCO_RecordCount);

            var repository = new NPocoRepository<Dog>(_nPocoUnitOfWork, mockCache.Object);
            var dog = new Dog
            {
                ID = TestConstants.NPOCO_UpdateDogId,
                Age = TestConstants.NPOCO_UpdateDogAge,
                Name = TestConstants.NPOCO_UpdateDogName
            };

            //Act
            repository.Update(dog);

            //Assert
            DataTable table = DataUtil.GetTable(TestConstants.NPOCO_DatabaseName, TestConstants.NPOCO_TableName);
            foreach (DataRow row in table.Rows)
            {
                if ((int)row["ID"] == TestConstants.NPOCO_UpdateDogId)
                {
                    Assert.AreEqual(TestConstants.NPOCO_UpdateDogAge, row["Age"]);
                    Assert.AreEqual(TestConstants.NPOCO_UpdateDogName, row["Name"]);
                }
            }
        }
        public void PetaPocoRepository_Delete_Deletes_Item_From_DataBase_With_Correct_ID()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object);
            var dog = new Dog
                            {
                                ID = TestConstants.PETAPOCO_DeleteDogId,
                                Age = TestConstants.PETAPOCO_DeleteDogAge,
                                Name = TestConstants.PETAPOCO_DeleteDogName
                            };

            //Act
            repository.Delete(dog);

            //Assert
            DataTable table = DataUtil.GetTable(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName);
            foreach (DataRow row in table.Rows)
            {
                Assert.IsFalse((int)row["ID"] == TestConstants.PETAPOCO_DeleteDogId);
            }
        }
示例#12
0
 private void SetUpDatabase(int count)
 {
     using (IDocumentSession _ravenDB = RavenDBDocumentStore.Instance.OpenSession())
     {
         for (int i = 0; i < count; i++)
         {
             var dog = new Dog
             {
                 ID = i + 1,
                 Age = Int32.Parse(_dogAges[i]),
                 Name = _dogNames[i]
             };
             _ravenDB.Store(dog);
         }
         _ravenDB.SaveChanges();
     }
 }
示例#13
0
        public void RavenDBRepository_Update_Updates_Item_With_Correct_ID()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            using (IDocumentSession _ravenDB = RavenDBDocumentStore.Instance.OpenSession())
            {
                var repository = new RavenDBRepository<Dog>(_ravenDB, mockCache.Object);
                var dog = new Dog
                {
                    ID = TestConstants.PETAPOCO_UpdateDogId,
                    Age = TestConstants.PETAPOCO_UpdateDogAge,
                    Name = TestConstants.PETAPOCO_UpdateDogName
                };

                //Act
                repository.Update(dog);
            }

            //Assert
            //DataTable table = DataUtil.GetTable(TestConstants.PETAPOCO_DatabaseName, TestConstants.PETAPOCO_TableName);
            //foreach (DataRow row in table.Rows)
            //{
            //    if ((int)row["ID"] == TestConstants.PETAPOCO_UpdateDogId)
            //    {
            //        Assert.AreEqual(row["Age"], TestConstants.PETAPOCO_UpdateDogAge);
            //        Assert.AreEqual(row["Name"], TestConstants.PETAPOCO_UpdateDogName);
            //    }
            //}
            Assert.IsTrue(false);
        }
示例#14
0
        public void RavenDBRepository_Update_Updates_Item_In_DataBase()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            using (IDocumentSession _ravenDB = RavenDBDocumentStore.Instance.OpenSession())
            {
                var repository = new RavenDBRepository<Dog>(_ravenDB, mockCache.Object);
                var dog = new Dog
                {
                    ID = TestConstants.PETAPOCO_UpdateDogId,
                    Age = TestConstants.PETAPOCO_UpdateDogAge,
                    Name = TestConstants.PETAPOCO_UpdateDogName
                };

                //Act
                repository.Update(dog);
            }

            //Assert
            //int actualCount = DataUtil.GetRecordCount(TestConstants.PETAPOCO_DatabaseName,
            //    TestConstants.PETAPOCO_TableName);
            //Assert.AreEqual(TestConstants.PETAPOCO_RecordCount, actualCount);
            Assert.IsTrue(false);
        }
        public void PetaPocoRepository_Add_Inserts_Item_Into_DataBase_With_Correct_ID()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object);
            var dog = new Dog
                            {
                                Age = TestConstants.PETAPOCO_InsertDogAge,
                                Name = TestConstants.PETAPOCO_InsertDogName
                            };

            //Act
            repository.Add(dog);

            //Assert
            int newId = DataUtil.GetLastAddedRecordID(TestConstants.PETAPOCO_DatabaseName,
                TestConstants.PETAPOCO_TableName, "ID");
            Assert.AreEqual(TestConstants.PETAPOCO_RecordCount + 1, newId);
        }
        public void PetaPocoRepository_Update_Updates_Item_In_DataBase()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.PETAPOCO_RecordCount);

            var repository = new PetaPocoRepository<Dog>(_petaPocoUnitOfWork, mockCache.Object);
            var dog = new Dog
            {
                ID = TestConstants.PETAPOCO_UpdateDogId,
                Age = TestConstants.PETAPOCO_UpdateDogAge,
                Name = TestConstants.PETAPOCO_UpdateDogName
            };

            //Act
            repository.Update(dog);

            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.PETAPOCO_DatabaseName,
                TestConstants.PETAPOCO_TableName);
            Assert.AreEqual(TestConstants.PETAPOCO_RecordCount, actualCount);
        }
        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"]);
        }
        public void NPocoRepository_Delete_Does_Nothing_With_Invalid_ID()
        {
            //Arrange
            var mockCache = new Mock<ICacheProvider>();
            SetUpDatabase(TestConstants.NPOCO_RecordCount);

            var repository = new NPocoRepository<Dog>(_nPocoUnitOfWork, mockCache.Object);
            var dog = new Dog
            {
                ID = TestConstants.NPOCO_InvalidDogId,
                Age = TestConstants.NPOCO_DeleteDogAge,
                Name = TestConstants.NPOCO_DeleteDogName
            };

            //Act
            repository.Delete(dog);

            //Assert
            //Assert
            int actualCount = DataUtil.GetRecordCount(TestConstants.NPOCO_DatabaseName,
                TestConstants.NPOCO_TableName);
            Assert.AreEqual(TestConstants.NPOCO_RecordCount, actualCount);
        }