Esempio n. 1
0
        // No cities, thus no point of interest
        public void TestGetPointNoCities()
        {
            var cities = new List <City> {
            }.AsQueryable();

            var points = new List <PointOfInterest> {
            }.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 mockSetP = new Mock <DbSet <PointOfInterest> >();

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

            var mockContext = new Mock <CityInfoContext>();

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

            var repo = new CityInfoRepository(mockContext.Object);

            Assert.Null(repo.GetPointOfInterestForCity(1, 1));
        }
Esempio n. 2
0
        // Cities with existing city id, no points of interest
        public void TestGetPointNoPoints()
        {
            var cities = new List <City>
            {
                new City {
                    Id = 1, Name = "Richmond", Description = "Small"
                },
                new City {
                    Id = 2, Name = "Vancouver", Description = "Big"
                }
            }.AsQueryable();

            var points = new List <PointOfInterest> {
            }.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 mockSetP = new Mock <DbSet <PointOfInterest> >();

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

            var mockContext = new Mock <CityInfoContext>();

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

            var repo = new CityInfoRepository(mockContext.Object);

            Assert.Null(repo.GetPointOfInterestForCity(1, 1));
        }
Esempio n. 3
0
        // Cities with existing city id, correct poi id
        public void TestGetPoint()
        {
            PointOfInterest poi1 = new PointOfInterest
            {
                Id          = 1,
                Name        = "Downtown",
                Description = "Lots of food",
                CityId      = 1
            };

            PointOfInterest poi2 = new PointOfInterest
            {
                Id          = 2,
                Name        = "Stanley Park",
                Description = "Lots to do",
                CityId      = 1
            };

            PointOfInterest poi3 = new PointOfInterest
            {
                Id          = 3,
                Name        = "Science World",
                Description = "Lots of science",
                CityId      = 2
            };

            PointOfInterest poi4 = new PointOfInterest
            {
                Id          = 4,
                Name        = "UBC",
                Description = "School",
                CityId      = 2
            };

            var cities = new List <City>
            {
                new City {
                    Id = 1, Name = "Richmond", Description = "Small"
                },
                new City {
                    Id = 2, Name = "Vancouver", Description = "Big"
                }
            }.AsQueryable();

            var points = new List <PointOfInterest> {
                poi1, poi2, poi3, poi4
            }.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 mockSetP = new Mock <DbSet <PointOfInterest> >();

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

            var mockContext = new Mock <CityInfoContext>();

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

            var repo = new CityInfoRepository(mockContext.Object);

            Assert.Equal(2, repo.GetPointOfInterestForCity(1, 2).Id);
            Assert.Equal("Stanley Park", repo.GetPointOfInterestForCity(1, 2).Name);
            Assert.Equal("Lots to do", repo.GetPointOfInterestForCity(1, 2).Description);
            Assert.Equal(1, repo.GetPointOfInterestForCity(1, 2).CityId);
        }