public void Add_SessionFound_AddsUserToSession(int id)
        {
            _mockSessionRepository.Setup(s => s.GetById(id)).Returns(_dummyContext.Sessions.First(s => s.SessionId == id));
            var result = Assert.IsType <RedirectToActionResult>(_sessionController.Add(id, user1));

            Assert.Equal("Details", result?.ActionName);
            _mockUserRepository.Verify(m => m.SaveChanges(), Times.Once);
            Session session = _dummyContext.Sessions.First(s => s.SessionId == id);

            Assert.Contains(user1, session.UserSessions.Select(us => us.User));
        }
Example #2
0
        public void should_add_a_session_when_posting_to_add_action()
        {
            var theTalkId = 5;
            var theTalk   = new Talk();

            var theVenueId = 9;
            var theVenue   = new Venue();

            var talkService = new Mock <ITalkService>();

            talkService.Setup(x => x.GetTalk(theTalkId)).Returns(theTalk);

            var venueService = new Mock <IVenueService>();

            venueService.Setup(x => x.GetVenue(theVenueId)).Returns(theVenue);

            var sessionService = new Mock <ISessionService>();


            var model = new AddSessionViewModel
            {
                TalkId    = theTalkId,
                VenueId   = theVenueId,
                StartDate = DateTime.Now,
                StartTime = 6,
            };

            var sessionController = new SessionController(sessionService.Object, talkService.Object, venueService.Object);

            var result = sessionController.Add(model);

            Assert.IsType <SessionListViewModel>(((ViewResult)result).Model);
        }
Example #3
0
        public void should_return_a_view_with_an_AddSessionViewModel()
        {
            var sessionService = new Mock <ISessionService>();
            var talkService    = new Mock <ITalkService>();
            var venueService   = new Mock <IVenueService>();
            var controller     = new SessionController(sessionService.Object, talkService.Object, venueService.Object);

            var result = controller.Add();

            Assert.NotNull(result);
            Assert.IsType <AddSessionViewModel>(((ViewResult)result).Model);
        }