public void GivenViewModelGenerated_WhenRemoveProvider_ThenViewContainsViewModel()
        {
            RemoveApprovedProviderModel expected = new RemoveApprovedProviderModel();
            MockLogicManager.Expect(m => m.GenerateRemoveProviderViewModel(1, 1)).Return(expected);

            PartialViewResult result = Target.RemoveProvider(1, 1) as PartialViewResult;

            result.AssertGetViewModel(expected);
        }
 public ActionResult RemoveProvider(RemoveApprovedProviderModel viewModel)
 {
     LogicManager.RemoveProvider(viewModel);
     return Json(true);
 }
        public void GivenValidViewModel_WhenRemoveProviderPost_ThenLogicManagerRemovesProvider_AndJsonSuccessResultReturned()
        {
            RemoveApprovedProviderModel viewModel = new RemoveApprovedProviderModel();

            JsonResult result = Target.RemoveProvider(viewModel) as JsonResult;

            MockLogicManager.AssertWasCalled(m => m.RemoveProvider(viewModel));
            result.AssertGetData(true);
        }
        public void GivenValidStudentId_AndValidProviderId_AndProviderIsNotApproveByStudent_WhenRemoveProvider_ThenThrowEntityNotFoundException()
        {
            var viewModel = new RemoveApprovedProviderModel { ProviderId = 1, StudentId = 1 };

            Target.ExpectException<EntityNotFoundException>(() => Target.RemoveProvider(viewModel));
        }
        public void GivenValidStudentId_AndValidProviderId_AndProviderIsApproveByStudent_WhenRemoveProvider_ThenProviderApprovalRemoved_AndSaved()
        {
            var viewModel = new RemoveApprovedProviderModel { ProviderId = 2, StudentId = 4 };
            Student expectedStudent = Repositories.MockStudentRepository.Items.Where(s => s.Id == viewModel.StudentId).Single();
            Provider expectedProvider = Repositories.MockProviderRepository.Items.Where(p => p.Id == viewModel.ProviderId).Single();

            Target.RemoveProvider(viewModel);

            Repositories.MockStudentRepository.AssertWasCalled(m => m.DeleteLink(expectedStudent, expectedProvider));
            Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save());
        }
        public void GivenValidStudentId_AndValidProviderId_AndProviderIsApproveByStudent_WhenGenerateRemoveProviderViewModel_ThenViewModelContainsEntityState()
        {
            var expected = new RemoveApprovedProviderModel { ProviderId = 1, StudentId = 2, ProviderName = "YMCA", StudentName = "Jain, Nidhi Quizzno" };

            RemoveApprovedProviderModel actual = Target.GenerateRemoveProviderViewModel(2, 1);

            Assert.AreEqual(expected.ProviderId, actual.ProviderId);
            Assert.AreEqual(expected.ProviderName, actual.ProviderName);
            Assert.AreEqual(expected.StudentId, actual.StudentId);
            Assert.AreEqual(expected.StudentName, actual.StudentName);
        }
        public void GivenInvalidStudentId_WhenRemoveProvider_ThenThrowEntityNotFoundException()
        {
            var viewModel = new RemoveApprovedProviderModel { ProviderId = 2, StudentId = 100 };

            Target.ExpectException<EntityNotFoundException>(() => Target.RemoveProvider(viewModel));
        }
 public void RemoveProvider(RemoveApprovedProviderModel viewModel)
 {
     var student = StudentRepository.Items.Include(s => s.ApprovedProviders).SingleOrDefault(s => s.Id == viewModel.StudentId);
     if (student == null)
     {
         throw new EntityNotFoundException("Student with specified identifier was not found.");
     }
     var provider = student.ApprovedProviders.SingleOrDefault(p => p.Id == viewModel.ProviderId);
     if (provider == null)
     {
         throw new EntityNotFoundException("Provider could not be found associated with specified student.");
     }
     StudentRepository.DeleteLink(student, provider);
     RepositoryContainer.Save();
 }