public async Task TrySubscribeToData_works_when_using_matching_types() { var factory = new DataLoaderBuilderFactory(b => b .TrySubscribeToData <ITestData>((data, setter) => data.Subscribe(s => setter.SetData(data))) ); var builder = factory .CreateTyped <MyData>() .WithName("Loader") .WithLoadMethod(Load); var dataLoader = builder.Build(); // The recipe is applicable when a SubscribeToDataTrigger has been added to the DataLoader. Assert.Contains(dataLoader.Triggers, t => t is SubscribeToDataTrigger); var data = await dataLoader.Load(CancellationToken.None); Assert.True(data.IsSubscribed); async Task <MyData> Load(CancellationToken ct, IDataLoaderRequest request) { return(new MyData()); } }
public async Task TrySubscribeToData_doesnt_work_when_using_non_matching_types() { var factory = new DataLoaderBuilderFactory(b => b .TrySubscribeToData <ITestData>((data, setter) => data.Subscribe(s => setter.SetData(data))) ); var builder = factory .CreateTyped <string>() .WithName("Loader") .WithLoadMethod(Load); var dataLoader = builder.Build(); // The triggers must not contain the SubscribeToDataTrigger because the recipe doesn't apply for a DataLoader of string. Assert.DoesNotContain(dataLoader.Triggers, t => t is SubscribeToDataTrigger); async Task <string> Load(CancellationToken ct, IDataLoaderRequest request) { return(string.Empty); } }
private static IDataLoader <MyData> GetHappyPathDataLoader() { var factory = new DataLoaderBuilderFactory(b => b .TrySubscribeToData <ITestData>((data, setter) => data.Subscribe(s => setter.SetData(data))) ); var builder = factory .CreateTyped <MyData>() .WithEmptySelector(state => state.Data?.Message == null) .WithName("Loader") .WithLoadMethod(Load); var dataLoader = builder.Build(); return(dataLoader); async Task <MyData> Load(CancellationToken ct, IDataLoaderRequest request) { return(new MyData()); } }