public bool Validate(Subscription subscription) { foreach (var term in subscription.Terms) { var termsWithDifferentPrice = subscription.Terms.Where(a => a.Price != term.Price); return termsWithDifferentPrice .Any(a => a.IsOverlapping(term)); } return false; }
public void ValiadteReturnsExpected( string startDate1, string endDate1, double price1, string startDate2, string endDate2, double price2, bool expected ) { // Fixture setup var subscription = new Subscription(); var term1 = createTerm(startDate1, endDate1, price1); var term2 = createTerm(startDate2, endDate2, price2); subscription.Terms.Add(term1); subscription.Terms.Add(term2); // Exercise system var sut = new RefactoredOverlappingSubscriptionTermWithConflictingPriceValidator(); var actual = sut.Validate(subscription); // Verify outcome Assert.Equal(expected, actual); // Teardown }
public bool Validate(Subscription subscription) { var hasOverlappingItems = false; foreach (var term in subscription.Terms) { var otherTerms = subscription.Terms.Where(a => a.Price != term.Price); if (otherTerms.Any()) { if ( ( !term.EndDate.HasValue && otherTerms.Any(a => term.StartDate < a.EndDate)) || (otherTerms.Where(a => !a.EndDate.HasValue).Any(a => a.StartDate < term.EndDate)) || (otherTerms.Any(a => term.StartDate <= a.EndDate && a.StartDate <= term.EndDate)) ) { hasOverlappingItems = true; break; } } } return hasOverlappingItems; }