public void CanDeleteEvent()
 {
     Event eventFromForm = new Event("mysubject", "mymessage", DateTime.Now);
     RedirectToRouteResult redirectResult = controller.Delete(eventFromForm.Id)
         .AssertActionRedirect().ToAction("Index");
     Assert.That(controller.TempData[FormMessages.MessageTypeSuccess], Is.EqualTo(FormMessages.DeleteSuccess));
 }
        public void CanCreateEvent()
        {
            Event eventFromForm = new Event("Title", "Desc", DateTime.Now);
            eventFromForm.StartTime = "11:00";
            eventFromForm.EndTime = "13:00";
            eventFromForm.Notes = "Some notes";

            RedirectToRouteResult redirectResult = controller.Create(eventFromForm)
                .AssertActionRedirect().ToAction("Index");
            Assert.That(controller.TempData[FormMessages.MessageTypeSuccess].ToString(), Is.EqualTo(FormMessages.SaveSuccess));
        }
        public void CanCreateEvent()
        {
            string eventTitle = "CVL";
            string eventDesc = "Junior CVL";
            DateTime eventDate = DateTime.Now;

            Event e = new Event(eventTitle, eventDesc, eventDate);

            Assert.That(e, Is.Not.Null);
            Assert.That(e.Title, Is.EqualTo(eventTitle));
            Assert.That(e.Description, Is.EqualTo(eventDesc));
            Assert.That(e.Date, Is.EqualTo(eventDate));
        }
        public ActionResult Create(Event @event)
        {
            if (ModelState.IsValid)
            {
                eventService.Insert(@event);
                eventService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);
                return RedirectToAction("Index");
            }

            return View(@event);
        }
        public void Insert()
        {
            Event newItem = new Event("s", "m", new DateTime());

            using (mock.Record())
            {
                Expect.Call(delegate { eventRepository.Insert(newItem); });
            }

            using (mock.Playback())
            {
                eventService.Insert(newItem);
            }
        }
        public ActionResult Delete(Event eventToDelete)
        {
            bool success = true;

            if (eventToDelete != null)
            {
                try
                {
                    eventService.Delete(eventToDelete);
                    eventService.Commit();
                }
                catch
                {
                    success = false;
                }
            }

            if (success)
                SuccessMessage(FormMessages.DeleteSuccess);
            else
                ErrorMessage(FormMessages.DeleteFail);

            return RedirectToAction("Index");
        }
        public ActionResult Edit(Event evt)
        {
            if (ModelState.IsValid)
            {
                eventService.Update(evt);
                eventService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);
                return RedirectToAction("Index");
            }

                return View(evt);
        }
        public void CannotCreateEventInvalidStartTime()
        {
            Event eventFromForm = new Event("Title", "Desc", DateTime.Now);
            eventFromForm.StartTime = "2:59";
            controller.ModelState.AddModelError("StartTime", FormMessages.FieldTwentyFourHour);

            ViewResult result = controller.Create(eventFromForm).AssertViewRendered();
            Assert.That(result.ViewData.ModelState.IsValid, Is.EqualTo(false));
            Assert.That(result.ViewData.ModelState["StartTime"].Errors[0].ErrorMessage, Is.EqualTo(FormMessages.FieldTwentyFourHour));
        }
        public void CannotUpdateInvalidEvent()
        {
            Event eventFromForm = new Event();
            controller.ModelState.AddModelError("Title", FormMessages.FieldMandatory);

            ViewResult result = controller.Edit(eventFromForm).AssertViewRendered();
            Assert.That(result.ViewData.Model as Event, !Is.Null);
            Assert.That(result.ViewData.ModelState.IsValid, Is.EqualTo(false));
            Assert.That(result.ViewData.ModelState["Title"].Errors[0].ErrorMessage, Is.EqualTo(FormMessages.FieldMandatory));
        }
 public static Event CreateEvent()
 {
     Event evt = new Event("Title", "Desc", DateTime.Now);
     EntityIdSetter.SetIdOf(evt, 1);
     return evt;
 }