예제 #1
0
        public void Search_Without_Location()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var services             = GetSampleServices();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <IQuery <IEnumerable <Service> > >()))
            .Returns(services);

            var categories = GetSampleCategories();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, IList <Category> > >()))
            .Returns(categories);

            var fileSystemMock        = new Mock <IFileSystem>();
            var geoCodingServicemMock = new Mock <IGeoCodingService>();

            var userLocation = PointFactory.Create(6.9319444, 79.8877778);
            var controller   = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName));
            controller.SetUserInfoWitLocation(userLocation);

            var model = new SearchModel {
                Terms = "Foo"
            };

            controller.Search(model);

            Assert.AreEqual(model, controller.ViewData.Model);
            Assert.AreEqual(userLocation, controller.ViewData[ViewDataKeys.UserLocation]);
        }
        public void Search_With_Location()
        {
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);
            var services = GetSampleServices();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<IQuery<IEnumerable<Service>>>()))
                .Returns(services);

            var categories = GetSampleCategories();
            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>()))
                .Returns(categories);

            var fileSystemMock = new Mock<IFileSystem>();
            var geoCodingServicemMock = new Mock<IGeoCodingService>();
            const string location = "Bar";
            var locationCood = PointFactory.Create(6.9419444, 79.8977778);
            geoCodingServicemMock.Setup(g => g.GetCoordinates(It.Is<string>(v => v == location)))
                .Returns(locationCood);

            var userLocation = PointFactory.Create(6.9319444, 79.8877778);
            var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName));
            controller.SetUserInfoWitLocation(userLocation);

            var model = new SearchModel { Terms = "Foo", Location = location };
            controller.Search(model);

            Assert.AreEqual(model, controller.ViewData.Model);
            Assert.AreEqual(locationCood, controller.ViewData[ViewDataKeys.UserLocation]);
        }