public IEnumerable <ISearchStrategy <object, Event> > Create(SearchParamsDTO searchParams) { var searchStrategies = new List <ISearchStrategy <object, Event> >(); if (searchParams.From != null && searchParams.From.HasValue && searchParams.To != null && searchParams.To.HasValue) { var param = new FromToParam(searchParams.From.Value, searchParams.To.Value); searchStrategies.Add(new DateSearchStrategy(param)); } else if (searchParams.From != null && searchParams.From.HasValue) { var param = new FromToParam(searchParams.From.Value, DateTime.MaxValue); searchStrategies.Add(new DateSearchStrategy(param)); } else if (searchParams.To != null && searchParams.To.HasValue) { var param = new FromToParam(DateTime.MinValue, searchParams.To.Value); searchStrategies.Add(new DateSearchStrategy(param)); } else if (searchParams.Data != null && !string.IsNullOrEmpty(searchParams.Data)) { searchStrategies.Add(new DataSearchStrategy(searchParams.Data)); } return(searchStrategies); }
public void DateSearchStrategy_OnlyFrom_Test() { var fromToParam = new FromToParam(DateTime.Now.AddYears(-1), DateTime.MaxValue); // Arrange var dataSearchStrategy = new DateSearchStrategy(fromToParam); // Act var result = 0; foreach (var @event in _events) { result += dataSearchStrategy.Compare(@event) ? 1 : 0; } // Assert Assert.Equal(3, result); }
public void DateSearchStrategy_Wrong_Test() { var fromToParam = new FromToParam(DateTime.MinValue, DateTime.MinValue); // Arrange var dataSearchStrategy = new DateSearchStrategy(fromToParam); // Act var result = 0; foreach (var @event in _events) { result += dataSearchStrategy.Compare(@event) ? 1 : 0; } // Assert Assert.Equal(0, result); }
public DateSearchStrategy(FromToParam value) : base(value) { }