public Commitment UpdateCommitment(Commitment updatedCommitment) { var result = context.Commitments.Find(updatedCommitment.Id); if (result == null) throw new CommitmentNotFoundException(); result.StartDate = updatedCommitment.StartDate; result.EndDate = updatedCommitment.EndDate; result.Status = updatedCommitment.Status; result.PersonIsCheckedIn = updatedCommitment.PersonIsCheckedIn; result.VolunteerType = updatedCommitment.VolunteerType; result.ClusterId = updatedCommitment.ClusterId; context.SaveChanges(); return result; }
public void AddCommitment(Commitment newCommitment) { context.Commitments.Add(newCommitment); context.SaveChanges(); }
public void WhenVolunteersExistForMultipleDisastersReturnCorrectDisaster() { initializeDisasterCollection(disasterWithCommitments, disasterWithNoCommitments); initializeVolunteerCollection(personWithCommitments, personWithNoCommitments); var secondCommitment = new Commitment { DisasterId = disasterWithNoVolunteersID, Id = 102, PersonId = personWithNoCommitmentsID, StartDate = new DateTime(2013, 8, 15), EndDate = new DateTime(2013, 8, 20) }; initializeCommitmentCollection(commitment, secondCommitment); var underTest = new AdminService(mockService.Object); var result = underTest.GetVolunteers(disasterWithCommitments); Assert.AreEqual(1, result.Count()); }
public void UpdateCommitment(Commitment commitment) { if (commitment == null) throw new ArgumentNullException("commitment", "Commitment cannot be null"); ourService.UpdateCommitment(commitment); }
public void GetVolunteersByDate_FiltersToOnlyCheckedInClusterCoordinators() { var checkedInNonCoordinatorCommitment = new Commitment { DisasterId = disasterWithCommitments.Id, PersonId = personWithNoCommitmentsID, Id = 102, StartDate = new DateTime(2013, 8, 10), EndDate = new DateTime(2013, 8, 15) }; var clusterCoordinator = new ClusterCoordinator { Id = 1001, DisasterId = disasterWithCommitments.Id, PersonId = checkedInPersonID, }; initializeDisasterCollection(disasterWithCommitments); initializeVolunteerCollection(personWithCommitments, checkedInPerson, personWithNoCommitments); initializeCommitmentCollection(commitment, checkedInCommitment, checkedInNonCoordinatorCommitment); mockService.Setup(ds => ds.ClusterCoordinators).Returns(new[] { clusterCoordinator }.AsQueryable()); var underTest = new AdminService(mockService.Object); var result = underTest.GetVolunteersForDate(disasterWithCommitments, new DateTime(2013, 08, 12), clusterCoordinatorsOnly: true, checkedInOnly: true); Assert.AreEqual(1, result.Count()); }
public void GetVolunteersForDisasterUnfilteredByDateReturnsExpectedRecords() { var personWithDifferentCommitmentDateRange = personWithNoCommitments; const int personWithDifferentCommitmentDateRangeId = personWithNoCommitmentsID; initializeDisasterCollection(disasterWithCommitments); initializeVolunteerCollection(personWithCommitments, personWithDifferentCommitmentDateRange); var secondCommitment = new Commitment { DisasterId = disasterWithVolunteersID, Id = 102, PersonId = personWithDifferentCommitmentDateRangeId, StartDate = new DateTime(2013, 9, 15), EndDate = new DateTime(2013, 9, 20) }; initializeCommitmentCollection(commitment, secondCommitment); var systemUnderTest = new AdminService(mockService.Object); var result = systemUnderTest.GetVolunteersForDisaster(disasterWithCommitments.Id, null); var actual = result as IList<Person> ?? result.ToList(); Assert.AreEqual(2, actual.Count()); Assert.IsTrue(actual.FirstOrDefault(p => p.Id == personWithCommitments.Id) != null, "Could not find first expected Person."); Assert.IsTrue(actual.FirstOrDefault(p => p.Id == personWithDifferentCommitmentDateRange.Id) != null, "Could not find second expected Person."); }
public void GetVolunteersForDisasterFilteredByDateReturnsExpectedRecord() { var personWithDifferentCommitmentDateRange = personWithNoCommitments; const int personWithDifferentCommitmentDateRangeId = personWithNoCommitmentsID; initializeDisasterCollection(disasterWithCommitments); initializeVolunteerCollection(personWithCommitments, personWithDifferentCommitmentDateRange); var secondCommitmentOutOfDateRange = new Commitment { DisasterId = disasterWithVolunteersID, Id = 102, PersonId = personWithDifferentCommitmentDateRangeId, StartDate = new DateTime(2013, 9, 15), EndDate = new DateTime(2013, 9, 20) }; initializeCommitmentCollection(commitment, secondCommitmentOutOfDateRange); var systemUnderTest = new AdminService(mockService.Object); var result = systemUnderTest.GetVolunteersForDisaster(disasterWithCommitments.Id, new DateTime(2013, 8, 12)); var actual = result as IList<Person> ?? result.ToList(); Assert.AreEqual(1, actual.Count()); Assert.AreEqual(actual.First().Id, personWithCommitmentsID); }
public void Checkout_ValidCommitment_CorrectlyCheckin_And_RedirectsToIndex() { // Arrange const int commitmentId = 42; const int personId = 54; Person person = new Person { Id = personId }; Commitment commitment = new Commitment { Id = commitmentId }; _volunteerService.Setup(x => x.FindByUserId(It.IsAny<int>())) .Returns(person); _volunteerService.Setup(x => x.RetrieveCommitments(personId, It.IsAny<bool>())) .Returns(new List<Commitment> { commitment }.AsQueryable()); // Act var response = _controllerUnderTest.Checkout(commitmentId); // Assert var result = response as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); _volunteerService.Verify(x => x.UpdateCommitment(It.Is<Commitment>(c => c.PersonIsCheckedIn == false))); }
public Commitment AddCommitment(Commitment newCommitment) { Commitment result = context.Commitments.Add(newCommitment); context.SaveChanges(); return result; }