public TodoListServiceTests() { _todolists = new Mock <IEntityStorage <Dse.TodoListItem, Guid> >(MockBehavior.Strict); _listTasks = new Mock <IEntityStorage <Dse.TodoListTask, Guid> >(MockBehavior.Strict); _storageContext = new Mock <IStorageContext>(MockBehavior.Strict); _mapper = new Mock <IMapper>(MockBehavior.Strict); _testService = new TodoListService(_storageContext.Object, _mapper.Object); _storageContext.SetupGet(s => s.TodoLists).Returns(_todolists.Object); _storageContext.SetupGet(s => s.Tasks).Returns(_listTasks.Object); _mapper.Setup(m => m.Map <List <TodoListItem> >(It.IsAny <IEnumerable <Dse.TodoListItem> >())).Returns <IEnumerable <Dse.TodoListItem> >(items => { return(items.Select(i => new TodoListItem { Id = i.Id, Name = i.Name, Description = i.Description }).ToList()); }); _mapper.Setup(m => m.Map <TodoListTask>(It.IsAny <Dse.TodoListTask>())).Returns <Dse.TodoListTask>(item => { return(new TodoListTask { Id = item.Id, Name = item.Name, Completed = item.Completed }); }); }
public void GetTodoItems_PaginationItems() { var repository = new Mock <ITodoListRepository>(); var mapperCfg = new MapperConfiguration(m => { m.AddMaps(typeof(TodoItemDtoModel).Assembly); }); var mapper = mapperCfg.CreateMapper(); var httpContext = new Mock <IIdentityService>(); httpContext.Setup(x => x.GetUserId()).Returns(1); var service = new TodoListService(repository.Object, httpContext.Object, mapper); var list = new List <TodoItem>() { new TodoItem { Id = 1, Text = "1", IsComplete = false, UserId = 1 }, new TodoItem { Id = 2, Text = "2", IsComplete = false, UserId = 1 }, new TodoItem { Id = 5, Text = "2", IsComplete = false, UserId = 1 }, }; repository.Setup(repo => repo.GetAll()).Returns(list.AsQueryable()); Assert.IsTrue(list.Count == service.GetAll(0).Count); Assert.AreEqual(list.FirstOrDefault().Text, service.GetAll(0).FirstOrDefault().Text); Assert.IsFalse(list.FirstOrDefault().Text == service.GetAll(0)[1].Text); repository.Verify(x => x.GetAll()); }
protected override async Task OnInitializedAsync() { TodoLists = await TodoListService.GetAllLists(); UpdateUserName(); AuthenticationStateProvider.AuthenticationStateChanged += (task) => UpdateUserName(); TodoListService.OnTodoListChange += OnTodoListChange; }
public void TodoItemIsDeleted() { var itemId = 1; var mockRepository = new Mock <ITodoListRepository>(); var mapper = new Mock <IMapper>(); var httpContext = new Mock <IIdentityService>(); var mockService = new TodoListService(mockRepository.Object, httpContext.Object, mapper.Object); mockService.RemoveItem(itemId); mockRepository.Verify(v => v.RemoveItem(It.IsAny <int>())); }
public async Task NotExistTodoItem_ReturnFalse(string id) { //arrange var todoListService = new TodoListService( mockTodoItemRepository.Object, mockLogger.Object); //act var result = await todoListService.RemoveTodoItem(id); //assert Assert.IsFalse(result.Success); Assert.AreEqual(Messages.TodoItemNotRemoved, result.Message); }
public async Task ReturnEmptyList(string username) { //arrange var todoListService = new TodoListService( mockTodoItemRepository.Object, mockLogger.Object); //act var result = await todoListService.GetTodoItemList(username); //assert Assert.IsTrue(result.Success); Assert.AreEqual(Messages.GetTodoItemList, result.Message); Assert.AreEqual(new List <TodoItemModel>(), result.Data); }
public void TodoItemIsUpdated() { var todoItem = new TodoItem { Id = 1, Text = "123", IsComplete = false, UserId = 3 }; var mockRepository = new Mock <ITodoListRepository>(); var mapper = new Mock <IMapper>(); var httpContext = new Mock <IIdentityService>(); var mockService = new TodoListService(mockRepository.Object, httpContext.Object, mapper.Object); mockService.UpdateItem(todoItem.Id, todoItem.Text, todoItem.IsComplete); mockRepository.Verify(v => v.UpdateItem(It.IsAny <TodoItem>())); }
public async Task ExistTodoItem_ReturnTodoItem(string id) { //arrange var todoListService = new TodoListService( mockTodoItemRepository.Object, mockLogger.Object); //act var result = await todoListService.GetTodoItem(id); //assert Assert.IsTrue(result.Success); Assert.AreEqual(Messages.ThereIsTodoItem, result.Message); Assert.AreEqual(Constants.TodoItem, result.Data); }
public void SearchList() { var options = new DbContextOptionsBuilder <TodoContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; using (var context = new TodoContext(options)) { var service = new TodoListService(context); TodoList list = new TodoList(); list.Name = "New list"; list.Id = 1; service.Create(list); Assert.Equal(service.GetById(1), list); } }
protected override async Task OnParametersSetAsync() { ListId ??= (await TodoListService.GetAllLists()).FirstOrDefault()?.Id; if (ListId == null) { var todoList = new Models.TodoList { Name = "First Todo List" }; await TodoListService.Add(todoList); ListId = todoList.Id; } TodoItems = new ObservableCollection <TodoItem>(await TodoItemService.GetList(ListId)); }
public void DeleteList() { var options = new DbContextOptionsBuilder <TodoContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; using (var context = new TodoContext(options)) { var service = new TodoListService(context); TodoList list = new TodoList(); list.Name = "New list"; list.Id = 1; service.Create(list); service.Delete(1); Assert.Equal(0, context.TodoLists.ToList().Count); } }
public void UpdateList() { var options = new DbContextOptionsBuilder <TodoContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; using (var context = new TodoContext(options)) { var service = new TodoListService(context); TodoList list = new TodoList(); list.Name = "New List"; list.Id = 1; service.Create(list); TodoList newList = new TodoList(); newList.Name = "Old list"; Assert.NotEqual(list, service.Update(1, newList)); } }
public async Task ReturnTrue(string username, TodoItem todoItem) { //arrange mockTodoItemRepository.Setup(x => x.UpsertTodoItem(It.IsAny <string>(), It.IsAny <TodoItem>())) .Returns((string Id, TodoItem todoItem) => { return(Task.FromResult(true)); }); var todoListService = new TodoListService( mockTodoItemRepository.Object, mockLogger.Object); //act var result = await todoListService.AddTodoItem(username, todoItem); //assert Assert.IsTrue(result.Success); }
private static TodoList GetTodoList(TodoListService store) { TodoList todoList; do { WriteLine(); Write("Veuillez saisir votre username: "******"Cet user n'a pas de To do list"); } Clear(); } while (todoList == null); return(todoList); }
public void Test_GetTodoLists() { //Arrange _mockTodoListRepository.Setup(x => x.GetAllTodoListAsync(op)).ReturnsAsync(_todoList); _mockUnitOfWork.Setup(e => e.TodoLists).Returns(_mockTodoListRepository.Object); var sut = new TodoListService(_mockUnitOfWork.Object); //Act TodoListsController todoListController = new TodoListsController(sut, _mapper); var result = todoListController.GetTodoLists(op).Result; var response = result.Result as OkObjectResult; List <TodoListDTO> items = (List <TodoListDTO>)response.Value; //Assert Assert.AreEqual(1, items[0].Id); Assert.AreEqual("Item 1", items[0].Description); Assert.AreEqual(2, items[1].Id); Assert.AreEqual("Item 2", items[1].Description); }
public UnitTest1() { todolist = new TodoListService(); }
public TodoListsController() { //simple demo, no real DI _todoListService = new TodoListService(); }
public void Delete(Models.TodoList todoList) { TodoListService.Delete(todoList); }
public void Update(Models.TodoList todoList) { TodoListService.Update(todoList); }
protected override async Task OnInitializedAsync() { TodoLists = await TodoListService.GetAllLists(); }
public async Task NewTodoList(Models.TodoList todoList) { await TodoListService.Add(todoList); }
public DashboardController(TodoItemService todoItemService, TodoListService todoListService) { _todoItemService = todoItemService; _todoListService = todoListService; }
public TodoItemController(TodoListService service1) { this.todoListService = service1; }
public TodoListServiceTests() { _sut = new TodoListService(_todoListRepository, _mapper, _claimService); }
public ItemsController(TodoListService service) { _service = service; }
public TodoListController(TodoListService service) { this.service = service; }
public TodoListController(TodoListService todoListService) { _todoListService = todoListService; }
public TodoListController() { todoList = new TodoListService(); }
public TodoListServiceTests() { _sut = new TodoListService(TodoListRepository, Mapper, ClaimService); }
public ToDoListController(TodoListService todoListService, CategoryService categoryService) { _todoListService = todoListService; _categoryService = categoryService; }