async Task ITask.PerformAsAsync(Actor actor) { IToDoRepository repo = actor.GetService <IToDoRepository>(); repo.AddToDoItem(item); await repo.CommitAsync(); }
public async Task AUserShouldSeeOnlyTheirTasks() { var contentRoot = Path.Combine(Directory.GetCurrentDirectory(), "../../../../../src/WebSite"); var webHostBuilder = new WebHostBuilder() .UseContentRoot(contentRoot) .UseEnvironment(EnvironmentName.Development) .ConfigureAppConfiguration((hostingContext, config) => { var env = hostingContext.HostingEnvironment; config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); if (env.IsDevelopment()) { var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); if (appAssembly != null) { config.AddUserSecrets(appAssembly, optional: true); } } config.AddEnvironmentVariables(); }) .UseStartup <TestStartup>(); Server = new TestServer(webHostBuilder); IToDoRepository repo = Server.Host.Services.GetService(typeof(IToDoRepository)) as IToDoRepository; TestData.InitialToDos.ForEach(item => repo.AddToDoItem(item)); await repo.CommitAsync(); var client = Server.CreateClient(); var response = await client.GetAsync(Uris.Home); var content = await response.Content.ReadAsStringAsync(); var parser = new HtmlParser(); var document = await parser.ParseAsync(content); var listItems = document.QuerySelectorAll($"{Html.Ul}#todolist>li"); Assert.NotEmpty(listItems); var items = TestData.InitialToDos.Select(item => item.Title); foreach (var li in listItems) { Assert.Contains(li.InnerHtml, items); } }
// AddToDoItem public async Task AddToDoItem(int listId, string text) { await toDoRepository.AddToDoItem(listId, text); // notify list count updates var allLists = await toDoRepository.GetLists(); var listUpdate = await toDoRepository.GetList(listId); // notify list viewers on update var groupName = ListIdToGroupName(listId); await Clients.Group("Counts").SendAsync("UpdatedToDoList", allLists); await Clients.Group(groupName).SendAsync("UpdatedListData", listUpdate); }
public async Task AddToDoItem(ToDoItem toDoItem) { await _repository.AddToDoItem(toDoItem); }