Exemple #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 Authenticated_User_UserInfo()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var userInfoMock         = new Mock <UserInfo>();

            var controller = new FakeBaseController(nHbernateContextMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Home/", UserName));
            controller.Session[SessionKeys.User] = userInfoMock.Object;

            var userInfo = controller.GetUserInfo();

            Assert.IsNotNull(userInfo);
            Assert.AreEqual(userInfoMock.Object, userInfo);
        }
Exemple #3
0
        public void Details_Of_Nonexisting_Service()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, Service> >()))
            .Returns((Service)null);

            var controller = new ServicesController(nHbernateContextMock.Object, null, null);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/10", UserName));
            controller.SetUserInfo();

            var result = controller.Details(10);
            var view   = result as ViewResult;

            Assert.AreEqual("ServiceNotFound", view.ViewName);
        }
Exemple #4
0
        public void Details_Of_Existing_Service()
        {
            var service              = GetSampleServices()[0];
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, Service> >()))
            .Returns(service);

            var controller = new ServicesController(nHbernateContextMock.Object, null, null);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Details/1", UserName));
            controller.SetUserInfo();

            var result = controller.Details(1);

            Assert.AreEqual(service, controller.ViewData.Model);
        }
Exemple #5
0
        public void Category_Browse()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var categoryBrowseModel  = new CategoryBrowseModel();
            var services             = GetSampleServices();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <QueryByCategory>()))
            .Returns(services);

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

            var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Category/1/", UserName));
            controller.SetUserInfo();

            controller.Category(categoryBrowseModel);

            Assert.AreEqual(services, controller.ViewData[ViewDataKeys.Services]);
        }
Exemple #6
0
        public void Create_Post_valid()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var createServiceModel   = new CreateServiceModel();
            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 controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Create/", UserName));
            controller.SetUserInfo();

            controller.Create(createServiceModel);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand>()));
        }
Exemple #7
0
        public void ServicesNearLocation()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var services             = GetSampleServices();

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

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

            var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/ServicesNearLocation", UserName));
            controller.SetUserInfo();

            var jsonResult = controller.ServicesNearLocation(1.337, 3.37);

            dynamic json = jsonResult.Data;

            Assert.AreEqual(2, json.Count);
        }
        public void Authenticated_User_New_SessionAction_Executing()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, User> >()))
            .Returns(new Client {
                Email = "*****@*****.**", Name = UserName
            });

            var actionExecutingContextMock = new Mock <ActionExecutingContext>();

            var controller = new FakeBaseController(nHbernateContextMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Home/", UserName));

            controller.ExecuteOnActionExecuting(actionExecutingContextMock.Object);

            Assert.AreEqual(1, controller.Session.Count);
            var userInfo = (UserInfo)controller.Session[SessionKeys.User];

            Assert.AreEqual(UserName, userInfo.Name);
        }