Example #1
0
        // Cities with correct id thus does exist
        public void TestCityExists()
        {
            var cities = new List <City>
            {
                new City {
                    Id = 1, Name = "Richmond", Description = "Small"
                },
                new City {
                    Id = 2, Name = "Vancouver", Description = "Big"
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <City> >();

            mockSet.As <IQueryable <City> >().Setup(m => m.Provider).Returns(cities.Provider);
            mockSet.As <IQueryable <City> >().Setup(m => m.Expression).Returns(cities.Expression);
            mockSet.As <IQueryable <City> >().Setup(m => m.ElementType).Returns(cities.ElementType);

            var mockContext = new Mock <CityInfoContext>();

            mockContext.Setup(m => m.Cities).Returns(mockSet.Object);

            var repo = new CityInfoRepository(mockContext.Object);

            Assert.True(repo.CityExists(1));
        }
Example #2
0
        // No cities thus does not exist
        public void TestCityExistsNoCities()
        {
            var cities = new List <City> {
            }.AsQueryable();

            var mockSet = new Mock <DbSet <City> >();

            mockSet.As <IQueryable <City> >().Setup(m => m.Provider).Returns(cities.Provider);
            mockSet.As <IQueryable <City> >().Setup(m => m.Expression).Returns(cities.Expression);
            mockSet.As <IQueryable <City> >().Setup(m => m.ElementType).Returns(cities.ElementType);

            var mockContext = new Mock <CityInfoContext>();

            mockContext.Setup(m => m.Cities).Returns(mockSet.Object);

            var repo = new CityInfoRepository(mockContext.Object);

            Assert.False(repo.CityExists(1));
        }