public void Insert_Repos_SomeReposCountReturned()
        {
            //arrange
            var testContext       = CreateContextWithTestData();
            var repo              = new FakeGenericRepository(testContext);
            List <CarModels> list = new List <CarModels>
            {
                new CarModels {
                    CarModelID = 4, ManufactorID = 5, Name = "Four"
                },
                new CarModels {
                    CarModelID = 5, ManufactorID = 6, Name = "Five"
                },
                new CarModels {
                    CarModelID = 6, ManufactorID = 7, Name = "Six"
                }
            };
            var actualCount = repo.Get().Count();

            //act
            repo.Insert(list);
            var expectedCount = repo.Get().Count();
            var expected      = repo.GetByParam(x => x.CarModelID == 6);

            //asert
            Assert.AreEqual(actualCount + 3, expectedCount);
            Assert.AreEqual(list[2].Name, expected.Name);
        }
Ejemplo n.º 2
0
        public void TestConstructor_PassDbContext_ShouldCallDbSet()
        {
            var dbContext = new Mock <DbContext>();

            var repository = new FakeGenericRepository <Product>(dbContext.Object);

            Assert.AreSame(dbContext.Object.Set <Product>(), repository.DbSet);
        }
Ejemplo n.º 3
0
        public void TestConstructor_PassDbContext_ShouldSetPropertyCorrectly()
        {
            var dbContext = new Mock <DbContext>();

            var repository = new FakeGenericRepository <Product>(dbContext.Object);

            Assert.AreSame(dbContext.Object, repository.DbContext);
        }
        public void GetByParamAsynс_query_OneAsyncParametredQueryReturned()
        {
            //arrange
            var testContext = CreateContextWithTestData();
            var repo        = new FakeGenericRepository(testContext);
            //act
            var actual = repo.GetByParamAsynс(x => x.CarModelID > 1 && x.ManufactorID > 1);

            //asert
            Assert.AreNotEqual(actual, null);
        }
Ejemplo n.º 5
0
        public void GenericRepoConstructor_ShouldSetPropertyCorrectlyForDbSet()
        {
            //Arrange
            var techDbContext = new Mock <ITechrepoDbContext>();

            //Act
            var genericRepo = new FakeGenericRepository <AdvertCategory>(techDbContext.Object);

            //Act & Assert
            Assert.AreSame(techDbContext.Object.Set <AdvertCategory>(), genericRepo.DbSet);
        }
Ejemplo n.º 6
0
        public void GenericRepoConstructor_ShouldSetInstanceOfFakeGenericRepository()
        {
            //Arrange
            var techDbContext = new Mock <ITechrepoDbContext>();

            //Act
            var genericRepo = new FakeGenericRepository <AdvertCategory>(techDbContext.Object);

            //Assert
            Assert.IsInstanceOf <FakeGenericRepository <AdvertCategory> >(genericRepo);
        }
        public void GetByParam_Query_OneParametredQueryReturned()
        {
            //arrange
            var testContext = CreateContextWithTestData();
            var repo        = new FakeGenericRepository(testContext);
            int expectedId  = 3;

            //act
            var actual = repo.GetByParam(x => x.CarModelID > 1 && x.Name == "Three");

            //asert
            Assert.AreNotEqual(actual, null);
            Assert.AreEqual(actual.ManufactorID, expectedId);
        }
        public void Get_Repo_ReposelectionReturned()
        {
            //arrange
            var testContext = CreateContextWithTestData();
            var repo        = new FakeGenericRepository(testContext);
            var actualCount = 3;
            //act
            var entity        = repo.Get();
            var expectedCount = entity.Count();

            //asert
            Assert.AreNotEqual(entity, null);
            Assert.AreEqual(actualCount, expectedCount);
        }
        public void GetById_Repo_RepoSelectionReturned()
        {
            //arrange
            var testContext = CreateContextWithTestData();
            var repo        = new FakeGenericRepository(testContext);
            int id          = 1;

            //act
            var entity = repo.GetById(id);

            //assert
            Assert.AreNotEqual(entity, null);
            Assert.AreEqual(entity.CarModelID, id);
        }
        public void Delete_Repo_OneRepoMinusReturned()
        {
            //arrange
            var testContext = CreateContextWithTestData();
            var repo        = new FakeGenericRepository(testContext);
            int deletedID   = 2;

            //act
            var actual = repo.Get(x => x.CarModelID == deletedID);

            repo.Delete(deletedID);
            var expected = repo.Get(x => x.CarModelID == deletedID);

            //asert
            Assert.AreNotEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void ShouldCallFindMethod()
        {
            //Arrange
            var id            = 5;
            var techDbContext = new Mock <ITechrepoDbContext>();
            var dbSetMock     = new Mock <DbSet <AdvertCategory> >();

            techDbContext.Setup(t => t.Set <AdvertCategory>()).Returns(dbSetMock.Object);
            var genericRepo = new FakeGenericRepository <AdvertCategory>(techDbContext.Object);

            //Act
            genericRepo.GetById(id);

            //Assert
            dbSetMock.Verify(d => d.Find(id), Times.Once);
        }
        public void Update_Repo_OneRepoPlusReturned()
        {
            FakeGoodwillEntitesContext testContext = CreateContextWithTestData();
            var repo = new FakeGenericRepository(testContext);

            //arrange
            var    car      = repo.GetByParam(x => x.CarModelID == 1);
            string fakeName = "Alfasud1";

            //act
            car.Name = fakeName;
            repo.Update(car);
            testContext.SaveChanges();
            var newCar = repo.GetByParam(x => x.CarModelID == 1);

            //asert
            Assert.AreEqual(fakeName, newCar.Name);
        }
        public void Delete_Repos_SomeReposDeleteReturned()
        {
            //arrange
            var testContext       = CreateContextWithTestData();
            var repo              = new FakeGenericRepository(testContext);
            List <CarModels> list = new List <CarModels>
            {
                new CarModels {
                    CarModelID = 3, ManufactorID = 4, Name = "Three"
                }
            };

            //act
            var actual = repo.Get(x => x.CarModelID == 3);

            repo.Delete(list);
            var expected = repo.Get(x => x.CarModelID == 3);

            //asert
            Assert.AreNotEqual(expected, actual);
        }
        public void Update_Repos_SomeReposCountReturned()
        {
            //arrange
            var    testContext  = CreateContextWithTestData();
            var    repo         = new FakeGenericRepository(testContext);
            string expectedName = "change";
            var    car          = repo.Get(x => x.CarModelID >= 2);

            foreach (var c in car)
            {
                c.Name = expectedName;
            }

            //act
            repo.Update(car);
            testContext.SaveChanges();
            var newCar = repo.Get(x => x.CarModelID >= 2);

            //asert
            Assert.AreNotEqual(car, newCar);
        }
        public void Insert_Repo_RepoPlusOneReturned()
        {
            //arrange
            var testContext = CreateContextWithTestData();
            var repo        = new FakeGenericRepository(testContext);
            var model       = new CarModels
            {
                Name         = "four",
                CarModelID   = 4,
                ManufactorID = 5
            };
            var actualCount = repo.Get().Count();

            //act
            repo.Insert(model);
            var expectedCount  = repo.Get().Count();
            var expectedRecord = repo.GetByParam(x => x.CarModelID == 4);

            //asert
            Assert.AreEqual(actualCount + 1, expectedCount);
            Assert.AreEqual(expectedRecord.Name, model.Name);
        }