public void GetItems_ShouldReturnNullIfUserIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(GetItems_ShouldReturnNullIfUserIsNotFound)); var repository = new TodoItemRepository(dbContext); // Act var result = repository.GetItems(3, new PagingParameters()); // Assert Assert.Null(result); }
public MssqlWorker(DbContext context) { if(context == null) throw new ArgumentNullException(nameof(context)); _context = context; ItemRepository = new TodoItemRepository(context); ListRepository = new TodoListRepository(context); ProfileRepository = new UserProfileRepository(context); UserRepository = new UserRepository(context); LogRepository = new LoggerRepository(context); }
public TodoItemRepositoryTests() { _repositoryMock = new Mock <IRepository <TodoItem, Guid> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock .Setup(x => x.GetRepository <TodoItem>()) .Returns(_repositoryMock.Object); _repository = new TodoItemRepository(unitOfWorkMock.Object); }
public void DeleteItem_ShouldReturnFalseIfItemIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(DeleteItem_ShouldReturnFalseIfItemIsNotFound)); var repository = new TodoItemRepository(dbContext); // Act var result = repository.DeleteItem(1, 20); // Assert Assert.False(result); }
public MainViewModel(TodoItemRepository repository) { // On item added and updated we need event for these. repository.OnItemAdded += (sender, item) => Items.Add(CreateTodoItemViewModel(item)); repository.OnItemUpdated += (sender, item) => Task.Run(async() => await LoadData()); this.repository = repository; Task.Run(async() => { await LoadData(); }); }
//GET /api/TodoItem /// <summary> /// Retrieves all todo items for the current user /// </summary> /// <returns></returns> public async Task <IHttpActionResult> Get() { /* * Note: when using User.Identity.GetLoginId(), make sure that the ID is the same! * When logging on using the cookie, the ID will be the value of the NameIdentifier claim (email address in this case). * When logging on using the bearer token, the ID will be the actual user ID. */ var data = await TodoItemRepository.FindByUserNameAsync(User.Identity.Name); //Transforms each Domain.TodoItem into a Models.Output.TodoItem return(Ok(data.Select(Models.Output.TodoItem.Project))); }
public void GetItemLabels_ShouldGetItemLabels() { // Arrange var dbContext = SetupDatabase(nameof(GetItemLabels_ShouldGetItemLabels)); var repository = new TodoItemRepository(dbContext); // Act var result = repository.GetItemLabels(1, 1); // Assert Assert.NotNull(result); Assert.Equal("Today", result[0].Name); }
public TodoService(TodoManager todoManager, TodoItemRepository todoItemRepository) { this.TodoManager = todoManager; this.TodoItemRepository = todoItemRepository; this.TodoManager.ChangedAsObservable .Throttle(TimeSpan.FromMilliseconds(10)) .ObserveOnUIDispatcher() .Subscribe(x => { this.TodoItemRepository.Save(x); }); }
public MainViewModel(TodoItemRepository repository) { // mi aggancio all'evento onItemAdded e quando lo ricevo aggiungo un elemento nella lista repository.OnItemAdded += (sender, item) => Items.Add(CreateTodoItemViewModel(item)); // mi aggancio all'evento onItemUpdate e in questo caso, quando un elemento è aggiornato // procedo a ricaricare la lista. repository.OnItemUpdate += (sender, item) => Task.Run(async() => await LoadData()); // mi aggancio all'evento remove del repository , quando scatta l'evento procedo ad eseguire loaddata repository.OnItemRemove += (sender, item) => Task.Run(async() => await LoadData()); this.repository = repository; Task.Run(async() => await LoadData()); }
public async Task GetAllByListIdAsync_Should_Return_All_Todo_Items_From_A_List() { // Arrange var todoItems = Builder <TodoItem> .CreateListOfSize(10).Build().ToList(); TodoItemRepository.GetAllAsync(Arg.Any <Expression <Func <TodoItem, bool> > >()).Returns(todoItems); // Act var result = await _sut.GetAllByListIdAsync(Guid.NewGuid()); // Assert result.Should().HaveCount(10); await TodoItemRepository.Received().GetAllAsync(Arg.Any <Expression <Func <TodoItem, bool> > >()); }
public async Task <IHttpActionResult> MarkAsDone(string id) { var todoItem = await TodoItemRepository.FindByIdAsync(id); if (todoItem == null) { return(NotFound()); } todoItem.Done = true; await TodoItemRepository.UpdateAsync(todoItem); return(Ok()); }
public MssqlWorker(DbContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } _context = context; ItemRepository = new TodoItemRepository(context); ListRepository = new TodoListRepository(context); ProfileRepository = new UserProfileRepository(context); UserRepository = new UserRepository(context); LogRepository = new LoggerRepository(context); }
public TodoController(ILogger <TodoController> logger, TodoItemRepository todoItemRepository) { _logger = logger; _todoItemRepository = todoItemRepository; if (_todoItemRepository.GetCount() == 0) { _todoItemRepository.Insert(new Domain.Entities.TodoItem { Name = "测试1", IsComplete = false }); _todoItemRepository.Insert(new Domain.Entities.TodoItem { Name = "测试2", IsComplete = false }); } }
public MainViewModel(TodoItemRepository repository) { this.repository = repository; Task.Run(async() => await LoadData()); repository.OnItemAdded += (sender, item) => { Items.Add(CreateTodoItemViewModel(item)); }; repository.OnItemUpdated += (sender, item) => { Task.Run(async() => await LoadData()); }; }
public void DeleteItem_ShouldDeleteItem() { // Arrange var dbContext = SetupDatabase(nameof(DeleteItem_ShouldDeleteItem)); var repository = new TodoItemRepository(dbContext); // Act var result = repository.DeleteItem(1, 1); // Assert Assert.True(result); var item = dbContext.TodoItems.FirstOrDefault(t => t.Id == 1); Assert.Null(item); }
public void DeleteLabel_ShouldReturnFalseIfItemIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(DeleteLabel_ShouldReturnFalseIfItemIsNotFound)); var repository = new TodoItemRepository(dbContext); var input = new DeleteLabelDto { ParentId = 30 }; // Act var result = repository.DeleteLabel(3, input); // Assert Assert.False(result); }
public void UpdateLabel_ShouldReturnNullIfItemIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(UpdateLabel_ShouldReturnNullIfItemIsNotFound)); var repository = new TodoItemRepository(dbContext); var input = new UpdateLabelDto { ParentId = 30 }; // Act var result = repository.UpdateLabel(3, input); // Assert Assert.Null(result); }
public List <User> GetMatchingUsersFromDomain(string searchString) { try { List <User> userList = new List <User>(); TodoItemRepository repo = new TodoItemRepository(); using (var pc = new PrincipalContext(ContextType.Domain, _domain)) { UserPrincipal qbeUser = new UserPrincipal(pc); qbeUser.DisplayName = string.Format("*{0}*", searchString); PrincipalSearcher srch = new PrincipalSearcher(qbeUser); foreach (var found in srch.FindAll()) { UserPrincipal user = (found as UserPrincipal); if (user != null) { //Infusion hack: remove users that start with ext- or that have - or _ in their username if (user.SamAccountName.Contains("-") || user.SamAccountName.Contains("_")) { continue; } User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName); if (dbUser == null) { dbUser = new DomanUserLoginProvider(_domain).CreateUser(user.SamAccountName); if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username)) { repo.Add <User>(dbUser); } } if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username)) { userList.Add(dbUser); } } } } repo.SaveChanges(); return(userList); } catch (Exception ex) { Log.Error("Cannot connect to domain", ex); return(null); } }
public void CreateItem_ShouldReturnNullIfListIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(CreateItem_ShouldReturnNullIfListIsNotFound)); var repository = new TodoItemRepository(dbContext); var input = new CreateTodoItemDto { TodoListId = 10, Description = "Cheese" }; // Act var result = repository.CreateItem(1, input); // Assert Assert.Null(result); }
public async Task DeleteAsync_Should_Delete_Entity_From_Database() { // Arrange var todoItem = Builder <TodoItem> .CreateNew().With(c => c.Id = Guid.NewGuid()).Build(); TodoItemRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoItem, bool> > >()).Returns(todoItem); TodoItemRepository.DeleteAsync(Arg.Any <TodoItem>()).Returns(todoItem); // Act var result = await _sut.DeleteAsync(Guid.NewGuid()); // Assert result.Id.Should().Be(todoItem.Id); await TodoItemRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoItem, bool> > >()); await TodoItemRepository.Received().DeleteAsync(Arg.Any <TodoItem>()); }
public void CreateLabel_ShouldReturnNullIfItemIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(CreateLabel_ShouldReturnNullIfItemIsNotFound)); var repository = new TodoItemRepository(dbContext); var input = new CreateLabelDto { ParentId = 20, Label = "Cheese" }; // Act var result = repository.CreateLabel(1, input); // Assert Assert.Null(result); }
public void UpdateLabel_ShouldReturnNullIfLabelIsNotFound() { // Arrange var dbContext = SetupDatabase(nameof(UpdateLabel_ShouldReturnNullIfLabelIsNotFound)); var repository = new TodoItemRepository(dbContext); var input = new UpdateLabelDto { ParentId = 1, CurrentValue = "test1", NewValue = "test2" }; // Act var result = repository.UpdateLabel(1, input); // Assert Assert.Null(result); }
public void GetItems_ShouldReturnItems() { // Arrange var dbContext = SetupDatabase(nameof(GetItems_ShouldReturnItems)); var repository = new TodoItemRepository(dbContext); var input = new PagingParameters { Search = "code" }; // Act var result = repository.GetItems(1, input); // Assert Assert.NotNull(result); Assert.Single(result.PageContent); Assert.Equal("Code review", result.PageContent[0].Description); }
//POST /api/TodoItem /// <summary> /// Creates a new Todo Item for this user (using POST because we're generating an ID) /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <IHttpActionResult> Post(TodoItemModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var todoItem = new TodoItem { User = await UserManager.FindByNameAsync(User.Identity.Name), Description = model.Description, Done = false }; await TodoItemRepository.CreateAsync(todoItem); return(CreatedAtRoute("DefaultApi", new { todoItem.Id }, Models.Output.TodoItem.Project(todoItem))); }
public void Get_ById_ReturnsArgumentException() { // Arrange var repository = new TodoItemRepository(_dbContextFixture.TodoSampleDbContext); var unitOfWork = new Mock <IUnitOfWork>(); var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new TodoItemProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); var todoItemService = new TodoItemService(repository, unitOfWork.Object, mapper); // Act Assert Assert.Throws <ArgumentException>(() => todoItemService.Get(2)); }
private void ExecuteAddCommand(string title) { try { var index = this.Items.IndexOf(this.SelectedItem); var item = new TodoItemViewModel(TodoItemRepository.GetDefault().Factory(title: title)); // Set the ListId item.TodoItem.ListId = TodoList.Id; // Add to repo TodoItemRepository.GetForToDoListId(TodoList.Id).InsertItem(item.TodoItem); // Insert into ViewModel collection this.Items.Insert((index > -1) ? index : 0, item); this.SelectedItem = item; } catch { this.SelectedItem = null; } }
public void CreateItem_ShouldCreateItem() { // Arrange var dbContext = SetupDatabase(nameof(CreateItem_ShouldCreateItem)); var repository = new TodoItemRepository(dbContext); var input = new CreateTodoItemDto { TodoListId = 1, Description = "Cheese" }; // Act var result = repository.CreateItem(1, input); // Assert Assert.NotNull(result); var item = dbContext.TodoItems.FirstOrDefault(t => t.Description == "Cheese"); Assert.NotNull(item); }
public void DeleteLabel_ShouldDeleteLabel() { // Arrange var dbContext = SetupDatabase(nameof(DeleteLabel_ShouldDeleteLabel)); var repository = new TodoItemRepository(dbContext); var input = new DeleteLabelDto { ParentId = 1, Label = "Today" }; // Act var result = repository.DeleteLabel(1, input); // Assert Assert.True(result); var item = dbContext.Labels.FirstOrDefault(t => t.Id == 1); Assert.Null(item); }
public void CreateLabel_ShouldCreateLabel() { // Arrange var dbContext = SetupDatabase(nameof(CreateLabel_ShouldCreateLabel)); var repository = new TodoItemRepository(dbContext); var input = new CreateLabelDto { ParentId = 1, Label = "Test label" }; // Act var result = repository.CreateLabel(1, input); // Assert Assert.NotNull(result); var item = dbContext.Labels.FirstOrDefault(t => t.Name == "Test label"); Assert.NotNull(item); }
public void UpdateItem_ShouldUpdateItem() { // Arrange var dbContext = SetupDatabase(nameof(UpdateItem_ShouldUpdateItem)); var repository = new TodoItemRepository(dbContext); var input = new TodoItemDto { Id = 1, Description = "Cheese" }; // Act var result = repository.UpdateItem(1, input); // Assert Assert.NotNull(result); var item = dbContext.TodoItems.FirstOrDefault(t => t.Id == 1); Assert.Equal("Cheese", item.Description); }
public async void SaveTodoItemButton_Click() { if (TodoItems.Any(t => t.Id == TodoItem.Id)) { await ManageAppointment(); await TodoItemRepository.Update(TodoItem); } else { await ManageAppointment(); await TodoItemRepository.Create(TodoItem); } if (NavigationService.CanGoBack) { NavigationService.GoBack(); } }