public ActionResult DeleteConfirmed(int id) { Assistance assistance = assistanceRepository.GetAssistanceByID((int)id); assistanceRepository.DeleteAssistance(id); assistanceRepository.Save(); return(RedirectToAction("Index")); }
public void Init() { #region Dummy Assistance List assistances = new List <Assistance> { new Assistance { AssistanceID = 1, assistanceDate = new DateTime(2016, 01, 01), ClientID = 1 }, new Assistance { AssistanceID = 2, assistanceDate = new DateTime(2015, 01, 01), ClientID = 1 }, new Assistance { AssistanceID = 3, assistanceDate = new DateTime(2016, 02, 01), ClientID = 1 }, new Assistance { AssistanceID = 4, assistanceDate = new DateTime(2016, 01, 01), ClientID = 2 }, new Assistance { AssistanceID = 5, assistanceDate = new DateTime(2015, 01, 01), ClientID = 2 }, new Assistance { AssistanceID = 6, assistanceDate = new DateTime(2016, 02, 01), ClientID = 2 }, new Assistance { AssistanceID = 7, assistanceDate = new DateTime(2016, 01, 01), ClientID = 3 }, new Assistance { AssistanceID = 8, assistanceDate = new DateTime(2015, 01, 01), ClientID = 3 }, new Assistance { AssistanceID = 9, assistanceDate = new DateTime(2016, 02, 01), ClientID = 3 }, new Assistance { AssistanceID = 10, assistanceDate = new DateTime(2015, 01, 01), ClientID = 4 }, new Assistance { AssistanceID = 11, assistanceDate = new DateTime(2016, 02, 01), ClientID = 4 }, new Assistance { AssistanceID = 12, assistanceDate = new DateTime(2015, 01, 01), ClientID = 5 }, new Assistance { AssistanceID = 13, assistanceDate = new DateTime(2016, 02, 01), ClientID = 5 }, new Assistance { AssistanceID = 14, assistanceDate = new DateTime(2016, 02, 01), ClientID = 6 }, new Assistance { AssistanceID = 15, assistanceDate = new DateTime(2016, 02, 01), ClientID = 6 }, new Assistance { AssistanceID = 16, assistanceDate = new DateTime(2016, 02, 01), ClientID = 6 }, new Assistance { AssistanceID = 17, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8 }, new Assistance { AssistanceID = 18, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8 }, new Assistance { AssistanceID = 19, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8 }, new Assistance { AssistanceID = 20, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8 }, new Assistance { AssistanceID = 21, assistanceDate = new DateTime(2016, 02, 01), ClientID = 8 }, new Assistance { AssistanceID = 22, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7 }, new Assistance { AssistanceID = 23, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7 }, new Assistance { AssistanceID = 24, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7 } }; #endregion #region Dummy New Assistance newAssistance = new Assistance { AssistanceID = 25, assistanceDate = new DateTime(2016, 02, 01), ClientID = 7 }; #endregion #region Repositories assistanceRepository = Mock.Create <IAssistanceRepository>(); #endregion #region JustMock Assistances Arrange Mock.Arrange(() => assistanceRepository.GetAssistances()).Returns(assistances); Mock.Arrange(() => assistanceRepository.GetAssistanceByID(ASSISTANCE_ID_TO_USE)) .Returns(assistances.Where(a => a.AssistanceID == ASSISTANCE_ID_TO_USE).FirstOrDefault()); Mock.Arrange(() => assistanceRepository.InsertAssistance(newAssistance)) .DoInstead(() => assistances.Add(newAssistance)) .MustBeCalled(); Mock.Arrange(() => assistanceRepository.DeleteAssistance(ASSISTANCE_ID_TO_USE)) .DoInstead(() => assistances.Remove(assistances.Where(a => a.AssistanceID == ASSISTANCE_ID_TO_USE).FirstOrDefault())); Mock.Arrange(() => assistanceRepository.Save()).DoNothing(); #endregion #region Controller creation controller = new AssistancesController(assistanceRepository); #endregion }