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 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 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);
        }
        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");
        }