示例#1
0
 public ActionResult ClearFilters(MultimediaObjectsListViewModel model)
 {
     if (Session != null)
     {
         Session.Remove(FilterSettingsKey.MultimediaObjectsControllerFilterList.ToString());
         PageSettings.RemoveFromSession(PageSettingsKey.MultimediaObjectsPageSettings);
     }
     return(RedirectToAction("Index"));
 }
示例#2
0
        public void ObjectsControllerTestMethod()
        {
            /// mock dla obiektów
            Mock <IMultimediaObjectRepository> objectMock = new Mock <IMultimediaObjectRepository>();
            // objectMock.Setup(m => m.MultimediaObjects).Returns((MockData.Objects).AsQueryable());

            /// mock dla typów
            Mock <ITypeRepository> typeMock = new Mock <ITypeRepository>();
            // typeMock.Setup(m => m.Types).Returns((MockData.Types).AsQueryable());

            /// mock dla użytkowników
            Mock <IUsersRepository> usersMock = new Mock <IUsersRepository>();
            //usersMock.Setup(m => m.Users).Returns((MockData.Users).AsQueryable());

            /// Utworzenie kontrolera obiektów
            MultimediaObjectsController objectRepository = new MultimediaObjectsController(objectMock.Object, typeMock.Object, usersMock.Object);

            objectRepository.ItemsPerPage = 10;

            int mocObjectsCount = objectMock.Object.MultimediaObjects.Count();

            /// Wywołanie akcji Index
            ViewResult view = (ViewResult)objectRepository.Index(mocObjectsCount - 1, null, null, null);

            /// Weryfikacja wyników
            Assert.AreNotEqual(null, view.Model);
            MultimediaObjectsListViewModel model = view.Model as MultimediaObjectsListViewModel;

            Assert.IsInstanceOfType(model, typeof(MultimediaObjectsListViewModel));
            Assert.IsTrue(view.ViewName == "Index");
            Assert.AreEqual(mocObjectsCount - 1, 15);
            Assert.IsTrue(model.ItemsPerPage == 10);
            Assert.IsTrue(model.TotalPages == 2);
            // Assert.AreEqual(model.MultimediaObjects[0].Name, "autobus");

            ///// Wywołanie akcji listy priorytetów
            //RedirectToRouteResult redirection = (RedirectToRouteResult)objectRepository.List(new MultimediaObjectsListViewModel
            //{
            //	///Wszystkie obiekty przypisane do typów zawierających w nazwie 'Kwadrat'
            //	Filters = new MultimediaObjectListViewModelFilter
            //	{
            //		FilterType = "Kwadrat"
            //	}
            //});
            ///// Weryfikacja wyników
            //Assert.IsNotNull(redirection);
            //Assert.IsNotNull(redirection.RouteValues);
            //Assert.IsTrue(redirection.RouteValues.Count > 0);
            //Assert.IsTrue(redirection.RouteValues["action"].ToString() == "Index");

            view  = (ViewResult)objectRepository.Index(null, null, null, null);
            model = (MultimediaObjectsListViewModel)view.Model;

            ///W mock-u występują 4 elementy pasujące do warunku
            //      Assert.AreEqual(10, model.MultimediaObjects.Count);

            ///Powiązanie obiektów z kampaniami
            //objectMock.Setup(m => m.ObjectsToCampaign(7)).Returns(
            //	(from o in MockData.Objects
            //	 join cc in MockData.ObjectsCampaigns on o.ID equals cc.MultimediaObjectId
            //	 where cc.CampaignId == 7
            //	 select o.ID).ToList());
            //Assert.AreEqual(objectMock.Object.ObjectsToCampaign(7).Count, 3);
        }