Inheritance: Controller
 public void Init()
 {
     this.cacheService = new HttpCacheService();
     this.animals = ObjectFactory.GetAnimalService();
     this.organizations = ObjectFactory.GetOrganizationService();
     this.controller = new HomeController(animals, organizations, cacheService);
 }
        public void SetUp()
        {
            _documents = new List<Document> {new Document()};
            var repository = MockRepository.GenerateMock<IRepository>();
            _homeController = new HomeController(repository);

            repository.Stub(x => x.All<Document>()).Return(_documents.AsQueryable());
        }
Esempio n. 3
0
        public void Should_return_a_view_for_the_index()
        {
            var controller = new HomeController(MockRepository.GenerateMock<ISharedSettings>());

            var result = controller.Index();

            Assert.IsInstanceOfType(typeof (ViewResult), result);
        }
        public void Smoke()
        {
            // arrange
            var posts = new Mock<IBlogPostsRepository>();
            var controller = new HomeController(posts.Object);

            // act / assert 
            Assert.That(controller, Is.Not.Null);
        }
        public void AcceptInvitation_Build_View_Model_Fail()
        {
            //Arrange
            var controller = new HomeController(RepositoryFactory, UserService, NotifyService, EventService);

            //Act
            var result = controller.AcceptInvitation(1, 1) as ViewResult;

            //Assert
            Assert.AreEqual(Constants.BASE_BUILD_VIEW_FAIL, result.ViewBag.StatusMessage);
        }
        public void Index()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.AreEqual("Welcome to Gallery 202/Westerville Artists Unit Administration!", result.ViewBag.Message);
        }
Esempio n. 7
0
        public void Index()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void About()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.About() as ViewResult;

            // Assert
            Assert.AreEqual("Your application description page.", result.ViewBag.Message);
        }
Esempio n. 9
0
        public void Index_should_display_three_upcoming_booked_presentations()
        {
            var controller = new HomeController { Session = documentStore.OpenSession() };
            var result = controller.Index() as ViewResult;
            var model = result.Model as IEnumerable<Presentation>;

            Assert.That(model.Count(), Is.EqualTo(3));
            Assert.That(model.All(x => x.Booked), Is.True);
            Assert.That(model.All(x => x.PresentationDate > DateTime.Today), Is.True);
            Assert.That(model.Select(x => x.PresentationDate),
                Is.EquivalentTo(model.OrderBy(x => x.PresentationDate).Select(x => x.PresentationDate)));
        }
Esempio n. 10
0
        public void LastArticleFromBlog_IfNoPostsInRepo_ReturnEmptyView()
        {
            // arrange
            var posts = new Mock<IBlogPostsRepository>();
            var controller = new HomeController(posts.Object);

            // act
            var result = controller.LastArticleFromBlog() as ViewResult;

            // assert
            Assert.That(result.ViewData.Model, Is.Null);
        }
Esempio n. 11
0
        public void SetUp()
        {
            var autoMapperConfig = new AutoMapperConfig();
            autoMapperConfig.Execute(typeof(HomeController).Assembly);
            var surveysServiceMock = new Mock<ISurveyService>();
            var userServiceMock = new Mock<IUserService>();

            userServiceMock
                .Setup(x => x.GetById(It.IsAny<string>()))
                .Returns(new User { Email = UserEmail, UserName = UserName, PasswordHash = "123" });

            surveysServiceMock
                .Setup(x => x.GetById(It.IsAny<string>()))
                .Returns(new Survey { Id = 1, Title = SurveyTitle, Author = userServiceMock.Object.GetById("dsds"), AuthorId = userServiceMock.Object.GetById("dsss").Id, IsPublic = true });

            this.controller = new HomeController(userServiceMock.Object, surveysServiceMock.Object);
        }
Esempio n. 12
0
        public void LastArticleFromBlog_ThereArePostsInRepo_ReturnsLastPost()
        {
            // arrange
            var posts = new Mock<IBlogPostsRepository>();
            var controller = new HomeController(posts.Object);

            var postsInRepo = CreatePostsList();
            posts.Setup(p => p.BlogPosts).Returns(postsInRepo.AsQueryable());

            // act
            var result = controller.LastArticleFromBlog() as ViewResult;

            // assert
            var post = result.ViewData.Model as LastArticleFromBlogModel;
            Assert.That(post, Is.Not.Null);
            Assert.That(post.Title, Is.EqualTo("Second"));
        }
        public void Index()
        {
            // Arrange
            var controller = new HomeController ();

            // Act
            var result = (ViewResult)controller.Index ();

            var mvcName = typeof(Controller).Assembly.GetName ();
            var isMono = Type.GetType ("Mono.Runtime") != null;

            var expectedVersion = mvcName.Version.Major;
            var expectedRuntime = isMono ? "Mono" : ".NET";

            // Assert
            Assert.AreEqual (expectedVersion, result.ViewData ["Version"]);
            Assert.AreEqual (expectedRuntime, result.ViewData ["Runtime"]);
        }
        public void AcceptInvitation_Fail()
        {
            //Arrange
            var eventId = 1;
            var accepteeId = 10;
            var theEvent = GetTestEventDataModel(eventId);
            theEvent.Coordinator = new Person { PersonId = 1, FirstName = "Billy", LastName = "Bob" };
            var theInvitee = GetTestInviteeDataModel(accepteeId);
            var controller = new HomeController(RepositoryFactory, UserService, NotifyService, EventService);

            A.CallTo(() => EventRepo.GetAll()).Returns(new List<Event> { theEvent }.AsQueryable());
            A.CallTo(() => PersonRepo.GetAll()).Returns(new List<Person> { theInvitee }.AsQueryable());
            var result = controller.AcceptInvitation(eventId, accepteeId) as ViewResult;
            var viewModel = result.Model as InvitationDetailsViewModel;

            //Act
            A.CallTo(() => PersonRepo.SubmitChanges()).Throws(new Exception("Oh crap... error!"));
            result = controller.AcceptInvitation(viewModel) as ViewResult;

            //Assert
            Assert.AreEqual(result.ViewBag.StatusMessage, Constants.BASE_ACCEPT_INVITATION_FAIL);
        }
Esempio n. 15
0
        public void Index_should_display_three_upcoming_booked_presentations()
        {
            var presentations = new[]
                                    {
                                        new Presentation { Booked = true, PresentationDate = DateTime.Today.AddMonths(-1)},
                                        new Presentation { Booked = true, PresentationDate = DateTime.Today},
                                        new Presentation { Booked = true, PresentationDate = DateTime.Today.AddMonths(1)},
                                        new Presentation { Booked = true, PresentationDate = DateTime.Today.AddMonths(2)},
                                        new Presentation { Booked = true, PresentationDate = DateTime.Today.AddMonths(3)},
                                    };

            PrepareSession(presentations);

            var controller = new HomeController(documentStore.OpenSession());
            var result = controller.Index() as ViewResult;
            var model = result.Model as IEnumerable<Presentation>;

            Assert.That(model.Count(), Is.EqualTo(3));
            Assert.That(model.All(x => x.Booked), Is.True);
            Assert.That(model.All(x => x.PresentationDate > DateTime.Today.AddDays(-7)), Is.True);
            Assert.That(model.Select(x => x.PresentationDate),
                Is.EquivalentTo(model.OrderBy(x => x.PresentationDate).Select(x => x.PresentationDate)));
        }
        public void AcceptInvitation_Build_View_Model_Success()
        {
            //Arrage
            var eventId = 1;
            var accepteeId = 10;
            var theEvent = GetTestEventDataModel(eventId);
            theEvent.Coordinator = new Person { PersonId = 1, FirstName = "Billy", LastName = "Bob"};
            var theInvitee = GetTestInviteeDataModel(accepteeId);
            var controller = new HomeController(RepositoryFactory, UserService, NotifyService, EventService);

            //Act
            A.CallTo(() => EventRepo.GetAll()).Returns(new List<Event> { theEvent }.AsQueryable());
            A.CallTo(() => PersonRepo.GetAll()).Returns(new List<Person> { theInvitee }.AsQueryable());
            var result = controller.AcceptInvitation(eventId, accepteeId) as ViewResult;

            //Assert
            Assert.AreEqual(result.ViewBag.StatusMessage, string.Empty);
            Assert.AreEqual(((InvitationDetailsViewModel)result.Model).MyFoodItems.ToList().Count, 2);
            Assert.AreEqual(((InvitationDetailsViewModel)result.Model).MyGames.ToList().Count, 2);
            Assert.AreEqual(((InvitationDetailsViewModel)result.Model).AllEventFoodItems.Count, 0);
            Assert.AreEqual(((InvitationDetailsViewModel)result.Model).AllEventGames.Count, 0);
            Assert.AreNotEqual(((InvitationDetailsViewModel)result.Model).WillBringTheseFoodItems, null);
            Assert.AreNotEqual(((InvitationDetailsViewModel)result.Model).WillBringTheseGames, null);
        }
 public void SetUp()
 {
     _controller = new HomeController();
 }
        public void AcceptInvitation_Succeed()
        {
            //Arrange
            var eventId = 1;
            var accepteeId = 10;
            var theEvent = GetTestEventDataModel(eventId);
            theEvent.Coordinator = new Person { PersonId = 1, Email = "*****@*****.**", FacebookId = "00000"};
            var theInvitee = GetTestInviteeDataModel(accepteeId);
            theInvitee.MyRegisteredFriends = new List<Person>();
            var controller = new HomeController(RepositoryFactory, UserService, NotifyService, EventService);

            var newFoodItems = new List<FoodItemViewModel>
                {
                    new FoodItemViewModel { FoodItemId = 10, Title = "Twizzlers", Description = "Tasty red candy"},
                    new FoodItemViewModel { FoodItemId = 11, Title = "Milk Duds", Description = "Zero nutritional value"},
                };

            var newGames = new List<GameViewModel>
                {
                    new GameViewModel { GameId = 10, Title = "Citeis and Knights", Description = "A great expansion"},
                    new GameViewModel { GameId = 11, Title = "Star Craft", Description = "Lan parties only"},
                };

            A.CallTo(() => EventRepo.GetAll()).Returns(new List<Event> { theEvent }.AsQueryable());
            A.CallTo(() => PersonRepo.GetAll()).Returns(new List<Person> { theInvitee }.AsQueryable());
            A.CallTo(() => FoodRepo.GetAll()).Returns(new List<FoodItem>().AsQueryable());
            A.CallTo(() => GameRepo.GetAll()).Returns(new List<Game>().AsQueryable());
            var result = controller.AcceptInvitation(eventId, accepteeId) as ViewResult;
            var viewModel = result.Model as InvitationDetailsViewModel;

            //Act
            newFoodItems.ForEach(x => viewModel.WillBringTheseFoodItems.Add(x));
            newGames.ForEach(x => viewModel.WillBringTheseGames.Add(x));
            var redirectResult = controller.AcceptInvitation(viewModel) as RedirectToRouteResult;

            //Assert
            //That submit changes is called
            A.CallTo(() => EventRepo.SubmitChanges()).MustHaveHappened();
            A.CallTo(() => PersonRepo.SubmitChanges()).MustHaveHappened();

            //That the route values are what we expect.
            Assert.AreEqual(redirectResult.RouteValues["action"], "Index");
            Assert.AreEqual(redirectResult.RouteValues["message"].ToString(), "AcceptInvitationSuccess");
        }
        public void Index_Build_View_Model_Fail()
        {
            //Arrange
            A.CallTo(() => PersonRepo.GetAll()).Throws(new Exception("I can't find the database!"));
            var controller = new HomeController(RepositoryFactory, UserService, NotifyService, EventService);

            //Act
            var result = controller.Index(null) as ViewResult;

            //Assert
            Assert.AreEqual(Constants.BASE_BUILD_VIEW_FAIL, result.ViewBag.StatusMessage);
        }
        public void Index_Build_View_Model_Succeed()
        {
            //Arrange
            var eventOne = new Event {EventId = 1, Title = "Test event 1"};
            var eventTwo = new Event {EventId = 2, Title = "Test event 2"};
            var hostingEvent = new Event { EventId = 3, Title = "My own event"};
            var personResults = new List<Person>
                {
                    new Person{PersonId = 1,
                        FirstName = "Joe",
                        LastName = "Smith",
                        MyEvents = new List<Event> {hostingEvent},
                        MyInvitations = new List<Event> { eventOne, eventTwo },
                        AmAttending = new List<Event> { eventOne },
                        HaveDeclined = new List<Event> { eventTwo }
                    }
                };
            A.CallTo(() => PersonRepo.GetAll()).Returns(personResults.AsQueryable());
            A.CallTo(() => UserService.GetCurrentUserId("")).Returns(1);
            var controller = new HomeController(RepositoryFactory, UserService, NotifyService, EventService);

            //Act
            var result = controller.Index(null) as ViewResult;
            var model = result.Model as HomeViewModel;

            //Assert
            var acceptedInvitationsCount = model.MyInvitations.Count(x => x.HasAccepted == true && x.HasDeclined == false);
            var declinedInvitationsCount = model.MyInvitations.Count(x => x.HasAccepted == false && x.HasDeclined == true);
            Assert.AreEqual(string.Empty, result.ViewBag.StatusMessage);
            Assert.AreEqual(model.MyEvents.Count, 1);
            Assert.AreEqual(model.MyInvitations.Count, 2);
            Assert.AreEqual(model.HaveDeclined.Count, 1);
            Assert.AreEqual(model.AmAttending.Count, 1);
            Assert.AreEqual(acceptedInvitationsCount, 1);
            Assert.AreEqual(declinedInvitationsCount, 1);
        }
Esempio n. 21
0
 public void TestMethod1()
 {
     var controller = new HomeController();
     var result = controller.Index();
 }
        private HomeController GetMockHomeController(string lang = "English")
        {
            //Setup Mock objects
            var authorityRepository = new Mock<IAuthorityRepository>();
            var establishmentRepository = new Mock<IEstablishmentRepository>();
            var ratingKeyRepository = new Mock<IRatingKeyRepository>();
            var httpContextMock = new Mock<HttpContextBase>(MockBehavior.Loose);
            var controllerMock = new Mock<ControllerBase>(MockBehavior.Loose);
            var routeData = new RouteData();
            //Mock model in different language
            if (!lang.Equals("English"))
            {
                _ratings = _ratings.Select(x =>
                {
                    x.RatingName = $"{x.RatingName}_WELSH";
                    return x;
                }).ToList();
            }

            //Mock 
            authorityRepository.Setup(x => x.GetAuthorities(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(Task.FromResult(_authorities));
            ratingKeyRepository.Setup(x => x.GetRatingKeys(It.IsAny<string>(), It.IsAny<string>()))
                .Returns(Task.FromResult(_ratingKeyViewModel));

            establishmentRepository.Setup(x => x.GetRating(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, string>>(),It.IsAny<string>())).Returns(Task.FromResult((IEnumerable<RatingViewModel>)_ratings));
            routeData.Values.Add("language", lang);

            

            var controllerContext = new ControllerContext(httpContextMock.Object, routeData, controllerMock.Object);

            var homeController = new HomeController(authorityRepository.Object, establishmentRepository.Object,
                ratingKeyRepository.Object)
            { ControllerContext = controllerContext };
            return homeController;
        }