public void TestCreate() { var today = DateTime.Now.Date; var appState = AppStateType.Create(new AppStateSnapshot { SearchInProgress = true, SortOrder = SortOrder.Price, SearchCriteria = new SearchCriteriaSnapshot() { FromAirport = "LHR", ToAirport = "SEA", OutboundDate = today, ReturnDate = today.AddDays(7) } }); Assert.True(appState.SearchInProgress); Assert.NotNull(appState.SearchCriteria); Assert.Equal("LHR", appState.SearchCriteria.FromAirport); Assert.Equal("SEA", appState.SearchCriteria.ToAirport); Assert.Equal(today, appState.SearchCriteria.OutboundDate); Assert.Equal(today.AddDays(7), appState.SearchCriteria.ReturnDate); }
public void TestOnAction3() { var store = AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new ITodoSnapshot[] { new TodoSnapshot { Title = "Get coffee" } } }); var list = new List <(int, string)>(); store.OnAction((ISerializedActionCall call) => { var snapshot = store.GetSnapshot <AppStateSnapshot>(); list.Add((snapshot.Todos.Length, snapshot.Todos[0].Title)); }); store.Todos[0].Edit("Learn Blazor"); Assert.Single(list); Assert.Equal(1, list[0].Item1); Assert.Equal("Learn Blazor", list[0].Item2); }
public static void AddFlightFinder(this IServiceCollection services) { services.AddSingleton <JsonConverter, JsonTypeConverter <IAirportSnapshot, AirportSnapshot> >(); services.AddSingleton <JsonConverter, JsonTypeConverter <ISearchCriteriaSnapshot, SearchCriteriaSnapshot> >(); services.AddSingleton <JsonConverter, JsonTypeConverter <IFlightSegmentSnapshot, FlightSegmentSnapshot> >(); services.AddSingleton <JsonConverter, JsonTypeConverter <IItinerarySnapshot, ItinerarySnapshot> >(); services.AddSingleton <JsonConverter, JsonTypeConverter <IAppStateSnapshot, AppStateSnapshot> >(); services.AddScoped((_) => AppStateType.Create(new AppStateSnapshot { SearchInProgress = false, SortOrder = SortOrder.Price, SearchCriteria = new SearchCriteriaSnapshot() { FromAirport = "LHR", ToAirport = "SEA", OutboundDate = DateTime.Now.Date, ReturnDate = DateTime.Now.Date.AddDays(7) } })); services.AddScoped <IAppService, AppService>(); }
public void TestOnAction2() { var store = AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new ITodoSnapshot[] { new TodoSnapshot { Title = "Get coffee" } } }); var list = new List <int>(); store.OnAction((ISerializedActionCall call) => { var snapshot = store.GetSnapshot <AppStateSnapshot>(); list.Add(snapshot.Todos.Length); }); store.AddTodo("Learn Blazor"); Assert.Single(list); Assert.Equal(2, list[0]); }
public void TestEditTodo() { var store = AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new ITodoSnapshot[] { new TodoSnapshot { Title = "Get coffee" } } }); Assert.Equal("Get coffee", store.Todos[0].Title); store.Todos[0].Edit("Learn Blazor"); Assert.Equal(1, store.TotalCount); Assert.Equal("Learn Blazor", store.Todos[0].Title); store.Todos[0].Edit("Learn Blazor"); Assert.Equal("Learn Blazor", store.Todos[0].Title); }
public void TestStore() { var store = AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new ITodoSnapshot[] { new TodoSnapshot { Title = "Get coffee" } } }); Assert.NotNull(store); Assert.Equal(Filter.All, store.Filter); Assert.Equal("Get coffee", store.Todos[0].Title); store.Todos[0].Edit("Get Filter Coffee"); Assert.Equal("Get Filter Coffee", store.Todos[0].Title); store.Todos[0].Toggle(); Assert.True(store.Todos[0].Done); store.Todos[0].Remove(); Assert.Empty(store.Todos); Assert.Equal(0, store.TotalCount); }
public void TestTodoCounts() { var store = AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new ITodoSnapshot[] { new TodoSnapshot { Title = "Get coffee", Done = true }, new TodoSnapshot { Title = "Learn Blazor" } } }); Assert.Equal(2, store.FilteredTodos.Count); Assert.Equal(2, store.TotalCount); Assert.Equal(1, store.ActiveCount); Assert.Equal(1, store.CompletedCount); store.Todos[1].Toggle(); Assert.Equal(2, store.FilteredTodos.Count); store.SetFilter(Filter.Active); Assert.Equal(Filter.Active, store.Filter); Assert.Equal(0, store.FilteredTodos.Count); store.SetFilter(Filter.Completed); Assert.Equal(Filter.Completed, store.Filter); Assert.Equal(2, store.FilteredTodos.Count); Assert.Equal(0, store.ActiveCount); Assert.Equal(2, store.CompletedCount); }
public static void TryAddTodoDesktop(this IServiceCollection services) { services.AddSingleton((_) => AppStateType.Create(new Dictionary <string, object> { { "Filter", Filter.All }, { "Todos", new Dictionary <string, object>[] { new Dictionary <string, object> { { "Title", "Get coffee" } }, new Dictionary <string, object> { { "Title", "Learn Blazor" } } } } })); }
public void TestTodoClearCompleted() { var store = AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new ITodoSnapshot[] { new TodoSnapshot { Title = "Get coffee" }, new TodoSnapshot { Title = "Learn Blazor" } } }); Assert.Equal(2, store.FilteredTodos.Count); Assert.Equal(2, store.ActiveCount); Assert.Equal(0, store.CompletedCount); store.Todos[0].Toggle(); Assert.Equal(1, store.ActiveCount); Assert.Equal(1, store.CompletedCount); store.ClearCompleted(); Assert.Equal(1, store.FilteredTodos.Count); Assert.Equal(1, store.ActiveCount); Assert.Equal(0, store.CompletedCount); Assert.Equal("Learn Blazor", store.Todos[0].Title); }
public static void TryAddTodoApp(this IServiceCollection services) { services.TryAddJsonConverter <JsonTypeConverter <ITodoSnapshot, TodoSnapshot> >(); services.TryAddJsonConverter <JsonTypeConverter <IAppStateSnapshot, AppStateSnapshot> >(); services.TryAddSingleton((_) => AppStateType.Create(new AppStateSnapshot { Filter = Filter.All, Todos = new TodoSnapshot[] { new TodoSnapshot { Title = "Get coffee" }, new TodoSnapshot { Title = "Learn Blazor" } } })); }