public void Create_Event_ModelState_Not_Valid()
        {
            //Arrange
            var viewModel = new EditEventViewModel();
            var contoller = new EventController(RepositoryFactory, EventService, UserService, NotifyService);

            var modelBinder = new ModelBindingContext
            {
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => viewModel, viewModel.GetType()),
                ValueProvider = new NameValueCollectionValueProvider(new NameValueCollection(), CultureInfo.InvariantCulture)
            };

            var binder = new DefaultModelBinder().BindModel(new ControllerContext(), modelBinder);
            contoller.ModelState.Clear();
            contoller.ModelState.Merge(modelBinder.ModelState);
            //Act
            var result = contoller.Create(viewModel) as ViewResult;

            //Assert
            Assert.AreEqual(result.ViewData.ModelState.Count, 6);
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }
        public void Edit_Event_ModelState_Not_Valid()
        {
            //Arrange
            var theHost = new Person
            {
                PersonId = 1,
                FirstName = "Billy",
                LastName = "Bob",
                MyFoodItems = new List<FoodItem>(),
                MyGames = new List<Game>()
            };
            var theEvent = GetTestEventDataModel(1);
            var viewModel = new EditEventViewModel(theEvent);
            var contoller = new EventController(RepositoryFactory, EventService, UserService, NotifyService);

            var modelBinder = new ModelBindingContext
            {
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => viewModel, viewModel.GetType()),
                ValueProvider = new NameValueCollectionValueProvider(new NameValueCollection(), CultureInfo.InvariantCulture)
            };

            A.CallTo(() => EventRepo.GetAll()).Returns(new List<Event> { theEvent }.AsQueryable());
            A.CallTo(() => PersonRepo.GetAll()).Returns(new List<Person> { theHost }.AsQueryable());
            A.CallTo(() => UserService.GetCurrentUserId("")).Returns(1);

            //Act

            //None of these should be null
            viewModel.Title = string.Empty;
            viewModel.Description = string.Empty;
            viewModel.Location = string.Empty;
            viewModel.StartDate = null;
            viewModel.StartTime = string.Empty;
            viewModel.EndTime = string.Empty;

            //Set model binding
            var binder = new DefaultModelBinder().BindModel(new ControllerContext(), modelBinder);
            contoller.ModelState.Clear();
            contoller.ModelState.Merge(modelBinder.ModelState);

            //Get the result
            var result = contoller.Edit(viewModel) as ViewResult;

            //Assert
            Assert.AreEqual(result.ViewData.ModelState.Count, 6);
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }