Ejemplo n.º 1
0
        public void  Test_Index_Show_All_Offers_Which_Contains_searching_string(string searchingString, int foundOffers)
        {
            Offer[] array = { new Offer {
                                  Title = "Cleaning at your house", IsAvailable = true
                              },
                              new Offer {
                                  Title = "Very good Cleaning", IsAvailable = true
                              },
                              new Offer {
                                  Title = "GaRDening", IsAvailable = true
                              },
                              new Offer {
                                  Title = "gardening", IsAvailable = true
                              },
                              new Offer {
                                  Title = "garden", IsAvailable = true
                              } };


            var serviceMock = new Mock <MyWeb.OfferReference.IOfferService>();

            serviceMock.Setup(x => x.GetAllOffersAsync()).ReturnsAsync(array);
            var userProxyMock  = new Mock <MyWeb.UserReference1.IUserService>();
            var orderProxyMock = new Mock <MyWeb.OrderReference.IOrderService>();

            userProxyMock.Setup(x => x.FindUser(It.IsAny <string>())).Returns(new User
            {
                ID = 12,
            });

            var controllerContext = new Mock <ControllerContext>();
            var principal         = new Moq.Mock <IPrincipal>();

            principal.SetupGet(x => x.Identity.IsAuthenticated).Returns(true);
            //principal.SetupGet(x => x.Identity.GetUserId()).Returns("uname");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            var ctr = new ServiceOfferController(serviceMock.Object, userProxyMock.Object, orderProxyMock.Object);

            ctr.ControllerContext = controllerContext.Object;
            var result = ctr.Index(searchingString, 1, false, null).Result as ViewResult;
            PagedList <ManageOfferModel> model = (PagedList <ManageOfferModel>)result.Model;

            Assert.AreEqual(foundOffers, model.Count);
        }
Ejemplo n.º 2
0
        public void Test_Index_Show_All_Offers()
        {
            Offer[] array = { new Offer {
                                  IsAvailable = true
                              }, new Offer{
                                  IsAvailable = true
                              }, new Offer{
                                  IsAvailable = true
                              } };
            var     all = array.AsQueryable <Offer>();

            var serviceMock = new Mock <MyWeb.OfferReference.IOfferService>();

            serviceMock.Setup(x => x.GetAllOffersAsync()).ReturnsAsync(array);
            var userProxyMock  = new Mock <MyWeb.UserReference1.IUserService>();
            var orderProxyMock = new Mock <MyWeb.OrderReference.IOrderService>();

            userProxyMock.Setup(x => x.FindUser(It.IsAny <string>())).Returns(new User
            {
                ID = 12,
            });

            var controllerContext = new Mock <ControllerContext>();
            var principal         = new Moq.Mock <IPrincipal>();

            principal.SetupGet(x => x.Identity.IsAuthenticated).Returns(true);
            //principal.SetupGet(x => x.Identity.GetUserId()).Returns("uname");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            var ctr = new ServiceOfferController(serviceMock.Object, userProxyMock.Object, orderProxyMock.Object);

            ctr.ControllerContext = controllerContext.Object;
            var result = ctr.Index(null, 1, false, null).Result as ViewResult;
            PagedList <ManageOfferModel> model = (PagedList <ManageOfferModel>)result.Model;

            Assert.AreEqual(3, model.Count);
        }