Пример #1
0
        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
                });
            });
        }
Пример #2
0
        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());
        }
Пример #3
0
        protected override async Task OnInitializedAsync()
        {
            TodoLists = await TodoListService.GetAllLists();

            UpdateUserName();
            AuthenticationStateProvider.AuthenticationStateChanged += (task) => UpdateUserName();
            TodoListService.OnTodoListChange += OnTodoListChange;
        }
Пример #4
0
        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>()));
        }
Пример #5
0
        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);
        }
Пример #7
0
        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>()));
        }
Пример #8
0
        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);
        }
Пример #9
0
        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));
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
        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));
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
 public UnitTest1()
 {
     todolist = new TodoListService();
 }
 public TodoListsController()
 {
     //simple demo, no real DI
     _todoListService = new TodoListService();
 }
Пример #18
0
 public void Delete(Models.TodoList todoList)
 {
     TodoListService.Delete(todoList);
 }
Пример #19
0
 public void Update(Models.TodoList todoList)
 {
     TodoListService.Update(todoList);
 }
Пример #20
0
 protected override async Task OnInitializedAsync()
 {
     TodoLists = await TodoListService.GetAllLists();
 }
Пример #21
0
 public async Task NewTodoList(Models.TodoList todoList)
 {
     await TodoListService.Add(todoList);
 }
Пример #22
0
 public DashboardController(TodoItemService todoItemService, TodoListService todoListService)
 {
     _todoItemService = todoItemService;
     _todoListService = todoListService;
 }
 public TodoItemController(TodoListService service1)
 {
     this.todoListService = service1;
 }
Пример #24
0
 public TodoListServiceTests()
 {
     _sut = new TodoListService(_todoListRepository, _mapper, _claimService);
 }
Пример #25
0
 public ItemsController(TodoListService service)
 {
     _service = service;
 }
Пример #26
0
 public TodoListController(TodoListService service)
 {
     this.service = service;
 }
Пример #27
0
 public TodoListController(TodoListService todoListService)
 {
     _todoListService = todoListService;
 }
 public TodoListController()
 {
     todoList = new TodoListService();
 }
 public TodoListServiceTests()
 {
     _sut = new TodoListService(TodoListRepository, Mapper, ClaimService);
 }
Пример #30
0
 public ToDoListController(TodoListService todoListService, CategoryService categoryService)
 {
     _todoListService = todoListService;
     _categoryService = categoryService;
 }