Пример #1
0
        public async Task Index()
        {


            HttpContext.Current = new HttpContext(
                                                    new HttpRequest("", "http://tempuri.org", ""),
                                                    new HttpResponse(new StringWriter())
            );


            UnityConfig.RegisterComponents();

            System.Web.HttpContext.Current.Items["BusinessLocator"] = new BusinessLocator(UnityConfig.UnityContainer);


            BookmarkController ctrl = new BookmarkController();

            ViewResult vr = await ctrl.Index() as ViewResult;

            //on verifie que le nombre de bookmarks retourné est 6
            Assert.IsTrue(((ViewModelBookmarks)vr.Model).ListBkm.Count == 6);

        }
Пример #2
0
        public async Task Create()
        {

            HttpContext.Current = new HttpContext(
                                        new HttpRequest("", "http://tempuri.org", ""),
                                        new HttpResponse(new StringWriter())
            );


            UnityConfig.RegisterComponents();

            System.Web.HttpContext.Current.Items["BusinessLocator"] = new BusinessLocator(UnityConfig.UnityContainer);


            BookmarkController ctrl = new BookmarkController();

            var mock = new Mock<ControllerContext>();
            mock.SetupGet(x => x.HttpContext.User.Identity.Name).Returns("SOMEUSER");
            mock.SetupGet(x => x.HttpContext.Request.IsAuthenticated).Returns(true);
            ctrl.ControllerContext = mock.Object;


            Bookmark bkm = new Bookmark();
            bkm.Id = 7;
            bkm.Description = "Pour acheter des produits d'occasion pas loin de chez soi";
            bkm.Title = "Site d'achat en ligne";
            bkm.Url = "http://www.leboncoin.fr/";
            Keyword kw1 = new Keyword() { Id = 19, Bookmark = bkm, BookmarkId = bkm.Id, Word = "ecommerce" };
            Keyword kw2 = new Keyword() { Id = 20, Bookmark = bkm, BookmarkId = bkm.Id, Word = "coin" };
            Keyword kw3 = new Keyword() { Id = 21, Bookmark = bkm, BookmarkId = bkm.Id, Word = "occasion" };

            bkm.Keywords.Add(kw1);

            bkm.Keywords.Add(kw2);

            bkm.Keywords.Add(kw3);

            await ctrl.Create(new ViewModelBookmark(bkm));

            //on verifie que le nombre de bookmarks retourné est 7
            ViewResult vr = await ctrl.Index() as ViewResult;

            Assert.IsTrue(((ViewModelBookmarks)vr.Model).ListBkm.Count == 7);

        }