public void StateDoNotChangeWhenReducerThrowsException() { var store = new TodoStore(); store.Dispatch(new AddTodoAction() { text = "Learn Redux" }); store.Dispatch(new AddTodoAction() { text = "Start first project" }); store.Dispatch(new AddTodoAction() { text = "Ship products" }); Assert.AreEqual(3, store.GetState().todos.Count); try { store.Dispatch(new BuggyAction()); // Exception should have been thrown Assert.Fail(); } catch (System.Exception exception) { Assert.AreEqual("BuggyAction", exception.Message); } // The state should have been reserved on destructive action Assert.AreEqual(3, store.GetState().todos.Count); }
public void ToggleItemCompletionWithInvalidIndex() { var store = new TodoStore(); store.Dispatch(new AddTodoAction() { text = "Learn Redux" }); store.Dispatch(new AddTodoAction() { text = "Start first project" }); store.Dispatch(new AddTodoAction() { text = "Ship products" }); store.Dispatch(new ToggleTodoAction() { index = 3 }); // No effects store.Dispatch(new ToggleTodoAction() { index = -1 }); // No effects Assert.AreEqual(EVisibilityFilter.SHOW_ALL, store.GetState().visibilityFilter); Assert.AreEqual(3, store.GetState().todos.Count); Assert.AreEqual("Ship products", store.GetState().todos[2].text); Assert.AreEqual(false, store.GetState().todos[2].completed); }
public void ToggleVisibility() { var store = new TodoStore(); store.Dispatch(new SetVisibilityFilterAction() { filter = EVisibilityFilter.SHOW_COMPLETED }); Assert.AreEqual(EVisibilityFilter.SHOW_COMPLETED, store.GetState().visibilityFilter); }
public void AddFirstTodoItem() { var store = new TodoStore(); store.Dispatch(new AddTodoAction() { text = "Learn Redux" }); Assert.AreEqual(EVisibilityFilter.SHOW_ALL, store.GetState().visibilityFilter); Assert.AreEqual(1, store.GetState().todos.Count); Assert.AreEqual("Learn Redux", store.GetState().todos[0].text); Assert.AreEqual(false, store.GetState().todos[0].completed); }
public void ConfigureServices(IServiceCollection services) { // Add the Shared state to the DI container. services.AddSingleton <ISharedState>(x => new SharedState()); // Add a singleton ViewStore to the DI container. services.AddSingleton(x => { var vs = new ViewStore(); ((IReactiveObject)vs).SharedState = x.GetRequiredService <ISharedState>(); return(vs); }); // Add a singleton TodoStore to the DI container. services.AddSingleton(x => { var ts = new TodoStore(); ((IReactiveObject)ts).SharedState = x.GetRequiredService <ISharedState>(); return(ts); }); }
public void AddMoreTodoItems() { var store = new TodoStore(); store.Dispatch(new AddTodoAction() { text = "Learn Redux" }); store.Dispatch(new AddTodoAction() { text = "Start first project" }); store.Dispatch(new AddTodoAction() { text = "Ship products" }); Assert.AreEqual(EVisibilityFilter.SHOW_ALL, store.GetState().visibilityFilter); Assert.AreEqual(3, store.GetState().todos.Count); Assert.AreEqual("Ship products", store.GetState().todos[2].text); Assert.AreEqual(false, store.GetState().todos[2].completed); }
public void StoreShouldHaveDefaultState() { var store = new TodoStore(); Assert.AreEqual(null, store.GetState()); }
public TodoItemsController(TodoStore todoStore, IAuthorizationService authorizationService) { _todoStore = todoStore; _authorizationService = authorizationService; }
/// <summary> /// Creates a tenant, user on the tenant and some todos with tags /// </summary> public static async Task SeedData(this IServiceProvider services, ILogger log) { /** * Get registered services. */ var context = services.GetRequiredService <IDynamoDBContext>(); var idGenerator = services.GetRequiredService <IIdGenerator>(); var userRightsStore = services.GetRequiredService <IUserRightStore>(); var configuration = services.GetRequiredService <IConfiguration>(); /** * Setup the provisioning user */ var provisioningUser = new User { Id = TrustDefaults.ProvisioningId }; /** * Hand make up these because we want to inject the user with the provisioning user */ var tenantStore = new TenantStore( provisioningUser, context, idGenerator, userRightsStore, services.GetRequiredService <ILogger <TenantStore> >()); var userStore = new UserStore( provisioningUser, context, idGenerator, userRightsStore, services.GetRequiredService <ILogger <UserStore> >()); var tagStore = new TagStore( provisioningUser, context, idGenerator, userRightsStore, services.GetRequiredService <ILogger <TagStore> >()); var todoStore = new TodoStore( provisioningUser, context, idGenerator, userRightsStore, tagStore, tenantStore, services.GetRequiredService <ILogger <TodoStore> >()); // ensure the database is up and tables are created await services.GetRequiredService <IAmazonDynamoDB>() .WaitForAllTables(log); log.Info("[Seed] create sample data"); ////////////////////////// // Authentication // ============== // // A precreated user (in third-party system) [or decoded JWT through https://jwt.io // grab it from the Authorization header in a request] var knownAuth0Id = configuration.GetSection("TestSeedUser").Value; log.DebugFormat("[Seed] found seed user '{0}'", knownAuth0Id); var rootUser = (await userStore.GetByExternalId(TrustDefaults.KnownRootIdentifier)) .ThrowConfigurationErrorsExceptionIfNull(() => "Root user has not been configured"); ////////////////////////// // Seed a user // ============= // // Assume a known Auth0 (test) user, register a user and then link to tenant // var userData = new UserCreateData { Email = "*****@*****.**", Name = "test", ExternalId = knownAuth0Id }; // create seeed data if the user doesn't exist if ((await userStore.GetByExternalId(userData.ExternalId)).IsNull()) { log.Info($"[Seed] user {userData.Email}"); var userId = await userStore.Create( rootUser.Id, TrustDefaults.KnownHomeResourceId, userData, Permission.FullControl | Permission.Owner, CallerCollectionRights.User); ////////////////////////// // Seed a tenant // ============= // var tenantCreateData = new TenantCreateData { Code = "rewire.semanticlink.io", Name = "Rewire", Description = "A sample tenant (company/organisation)" }; log.Info($"[Seed] tenant '{tenantCreateData.Code}'"); var tenantId = await tenantStore.Create( rootUser.Id, TrustDefaults.KnownHomeResourceId, tenantCreateData, Permission.FullControl | Permission.Owner, CallerCollectionRights.Tenant); ////////////////////////// // Add user to tenant // ================== // if (!await tenantStore.IsRegisteredOnTenant(tenantId, userId)) { await tenantStore.IncludeUser( tenantId, userId, Permission.Get | Permission.Owner, CallerCollectionRights.Tenant); } log.Info($"[Seed] registered user '{userData.Email}' against tenant '{tenantCreateData.Code}'"); ////////////////////////// // Seed global tags // ============= // // create some global tags // var tagIds = (await Task.WhenAll( new[] { "Work", "Personal", "Grocery List" } .Select(tag => tagStore.Create( userId, TrustDefaults.KnownHomeResourceId, new TagCreateData { Name = tag }, Permission.Get, CallerCollectionRights.Tag) ))) .Where(result => result != null) .ToList(); log.InfoFormat("[Seed] tags: [{0}]", tagIds.ToCsvString(tagId => tagId)); ///////////////////////////////////// // Seed a named todo list // ====================== // var todoCreateData = new TodoCreateData { Parent = tenantId, Name = "Shopping Todo List", Type = TodoType.List }; var todoListId = await todoStore.Create( userId, tenantId, todoCreateData, Permission.FullControl | Permission.Owner, CallerCollectionRights.Todo); log.InfoFormat("[Seed] todo list [{0}]", todoListId); ////////////////////////// // Seed some todos // =============== // var createTodoDatas = new List <TodoCreateData> { new TodoCreateData { Name = "One Todo", Parent = todoListId, Type = TodoType.Item }, new TodoCreateData { Name = "Two Todo (tag)", Tags = new List <string> { tagIds.First() }, State = TodoState.Complete, Parent = todoListId, Type = TodoType.Item }, new TodoCreateData { Name = "Three Todo (tagged)", Tags = tagIds, Parent = todoListId, Type = TodoType.Item } }; var ids = await Task.WhenAll(createTodoDatas .Select(data => todoStore.Create( userId, userId, data, Permission.FullControl | Permission.Owner, CallerCollectionRights.Todo))); log.InfoFormat("[Seed] todos: [{0}]", ids.ToCsvString(id => id)); } else { log.Debug("[Seed] test data already setup"); } }
/// <summary> /// Initializes a new instance of the <see cref="Todo"/> class. /// </summary> /// <param name="store">The store this todo is connected to.</param> /// <param name="id">The Id of the Todo item.</param> public Todo(TodoStore store, Guid id) { this.Store = store; this.Id = id; }
public TodoListPageViewModel(TodoStore todoStore, TodoActions todoActions) { _todoStore = todoStore; _todoActions = todoActions; _todoStore.OnEmitted += TodoStore_OnEmitted; }