/// <summary> /// Validates the <paramref name="filter"/> then applies as a filter to the reference data <paramref name="coll"/>. /// </summary> /// <typeparam name="TColl">The collection <see cref="System.Type"/>.</typeparam> /// <typeparam name="TItem">The item <see cref="System.Type"/>.</typeparam> /// <param name="coll">The reference data collection.</param> /// <param name="filter">The <see cref="ReferenceDataFilter"/>.</param> /// <param name="includeInactive">Indicates whether to include inactive (<see cref="ReferenceDataBase.IsActive"/> equal <c>false</c>) entries.</param> /// <returns>The filtered collection and corresponding ETag.</returns> public static async Task <ReferenceDataFilterResult <TItem> > ApplyFilterAsync <TColl, TItem>(TColl coll, ReferenceDataFilter filter, bool includeInactive = false) where TColl : ReferenceDataCollectionBase <TItem>, new() where TItem : ReferenceDataBase, new() { Check.NotNull(coll, nameof(coll)); Check.NotNull(filter, nameof(filter)); if (!filter.Codes.Any() && string.IsNullOrEmpty(filter.Text) && !includeInactive) { return new ReferenceDataFilterResult <TItem>(coll.ActiveList) { ETag = coll.ETag } } ; // Validate the arguments. (await Validator.ValidateAsync(filter).ConfigureAwait(false)).ThrowOnError(); // Apply the filter. var items = includeInactive ? coll.AllList : coll.ActiveList; var list = items .WhereWhen(x => filter.Codes.Contains(x.Code, StringComparer.OrdinalIgnoreCase), filter.Codes != null && filter.Codes.FirstOrDefault() != null) .WhereWildcard(x => x.Text, filter.Text); return(new ReferenceDataFilterResult <TItem>(list) { ETag = ETagGenerator.Generate(list) }); } }
public void Generate() { var p = new Person { First = "Jane", Last = "Doe" }; Assert.AreEqual("\"2I0QhKAlJMdHjCAocBhQeuzmze73jSnnWqyOkofhRn4=\"", ETagGenerator.Generate(p)); Assert.AreEqual("\"471H/SShWDDr5wOVpMnhcu00Fw3nhOHN1aE8VNpXCsY=\"", ETagGenerator.Generate(p, "XYZ")); }
public void Generate() { var p = new Person { First = "Jane", Last = "Doe" }; Assert.AreEqual("XCmFjH2zioLOelNdmU8hEQ==", ETagGenerator.Generate(p)); Assert.AreEqual("E9ik+Agqes6hzHMezoJigw==", ETagGenerator.Generate(p, "XYZ")); }