Exemple #1
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 #2
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);
        }
        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 #4
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 #5
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 #6
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 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 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);
        }
        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);
        }
        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>()));
        }