Ejemplo n.º 1
0
        public void Add_View_Tests_If_Return_correct_view()
        {
            try
            {
                var serviceMock = new Mock <MyWeb.OfferReference.IOfferService>();
                serviceMock.Setup(x => x.CreateServiceOffer(It.IsAny <Offer>())).Returns(true);

                var ctr    = new ServiceOfferController(serviceMock.Object);
                var result = (ViewResult)ctr.Add().Result;

                Assert.AreEqual("Add", result.ViewName);
            }

            catch
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 2
0
        public void Add_View_Tests_If_Rederict_to_Action()
        {
            try
            {
                var controllerContext = new Mock <ControllerContext>();
                var principal         = new Moq.Mock <IPrincipal>();
                principal.SetupGet(x => x.Identity.Name).Returns("uname");
                //principal.SetupGet(x => x.Identity.GetUserId()).Returns("uname");
                controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
                WorkingHoursOfOfferModel[] array = { new WorkingHoursOfOfferModel() };
                AddOfferModel    model           = new AddOfferModel();
                ManageOfferModel manageOffers    = new ManageOfferModel();
                manageOffers.Author      = "2";
                manageOffers.Category    = Category.Architecture;
                manageOffers.Description = "2222222222222222";
                manageOffers.Id          = 22;
                manageOffers.RatePerHour = 111;
                manageOffers.Subcategory = SubCategory.InteriorDesign;
                manageOffers.Title       = "my titlee";
                model.ManageOffers       = manageOffers;
                model.WorkingDays        = array.AsEnumerable <WorkingHoursOfOfferModel>();
                var serviceMock = new Mock <MyWeb.OfferReference.IOfferService>();
                serviceMock.Setup(x => x.CreateServiceOfferAsync(It.IsAny <Offer>())).ReturnsAsync(true);

                var ctr = new ServiceOfferController(serviceMock.Object);
                ctr.ControllerContext = controllerContext.Object;
                var task   = ctr.Add(model);//Task<actionRsult>>
                var result = task.Result;
                Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
                RedirectToRouteResult routeResult = result as RedirectToRouteResult;
                Assert.AreEqual(routeResult.RouteValues["action"], "Index");
            }
            catch
            {
                Assert.Fail();
            }
        }