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);
        }
Exemple #2
0
        public void SaveRead()
        {
            var          repository = new TodoListRepository(_sessionFactory);
            const string listName   = "My Todo List";
            var          todoList   = new TodoList {
                Name = listName
            };
            var listId    = repository.Save(todoList);
            var retrieved = repository.GetById(listId);

            Assert.AreEqual(listName, retrieved.Name);
        }
        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 async Task GetAllAsync_Should_Return_All_Todo_Lists()
    {
        //Arrange
        var todoLists = Builder <TodoList> .CreateListOfSize(10).Build().ToList();

        TodoListRepository.GetAllAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoLists);

        //Act
        var result = await _sut.GetAllAsync();

        //Assert
        result.Should().HaveCount(10);
        ClaimService.Received().GetUserId();
        await TodoListRepository.Received().GetAllAsync(Arg.Any <Expression <Func <TodoList, bool> > >());
    }
Exemple #5
0
        public void SaveRead_WithOneItem()
        {
            var          repository = new TodoListRepository(_sessionFactory);
            const string listName   = "My Todo List";
            var          todoList   = new TodoList {
                Name = listName
            };

            todoList.Items.Add(new TodoListItem {
                Title = "Buy Milk", TodoList = todoList
            });
            var listId    = repository.Save(todoList);
            var retrieved = repository.GetById(listId);

            Assert.AreEqual(1, retrieved.Items.Count);
        }
    public async Task CreateAsync_Should_Add_New_Entity_To_Database()
    {
        //Arrange
        var createTodoListModel = Builder <CreateTodoListModel> .CreateNew().Build();

        var todoList = Mapper.Map <TodoList>(createTodoListModel);

        todoList.Id = Guid.NewGuid();

        TodoListRepository.AddAsync(Arg.Any <TodoList>()).Returns(todoList);

        //Act
        var result = await _sut.CreateAsync(createTodoListModel);

        //Assert
        result.Id.Should().Be(todoList.Id);
        await TodoListRepository.Received().AddAsync(Arg.Any <TodoList>());
    }
    public async Task UpdateAsync_Should_Throw_Exception_If_Todo_List_Does_Not_Belong_To_HimAsync()
    {
        //Arrange
        var updateTodoListModel = Builder <UpdateTodoListModel> .CreateNew().Build();

        var todoList = Builder <TodoList> .CreateNew().Build();

        TodoListRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoList);

        //Act
        Func <Task> callUpdateAsync = async() => await _sut.UpdateAsync(Guid.NewGuid(), updateTodoListModel);

        //Assert
        await callUpdateAsync.Should().ThrowAsync <BadRequestException>()
        .WithMessage("The selected list does not belong to you");

        await TodoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >());

        ClaimService.Received().GetUserId();
    }
    public async Task CreateAsync_Should_Add_New_Entity_To_Database()
    {
        // Arrange
        var createTodoItemModel = Builder <CreateTodoItemModel> .CreateNew().Build();

        var todoList = Builder <TodoList> .CreateNew().Build();

        var todoItem = Builder <TodoItem> .CreateNew().With(ti => ti.Id = Guid.NewGuid()).Build();

        TodoListRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoList);
        TodoItemRepository.AddAsync(Arg.Any <TodoItem>()).Returns(todoItem);

        // Act
        var result = await _sut.CreateAsync(createTodoItemModel);

        // Assert
        result.Id.Should().Be(todoItem.Id);
        await TodoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >());

        await TodoItemRepository.Received().AddAsync(Arg.Any <TodoItem>());
    }
    public async Task DeleteAsync_Should_Delete_Entity_From_Database()
    {
        //Arrange
        var todoListId = Guid.NewGuid();
        var todoList   = Builder <TodoList> .CreateNew()
                         .With(tl => tl.CreatedBy = new Guid().ToString())
                         .With(tl => tl.Id        = todoListId)
                         .Build();

        TodoListRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoList);
        TodoListRepository.DeleteAsync(Arg.Any <TodoList>()).Returns(todoList);

        //Act
        var result = await _sut.DeleteAsync(Guid.NewGuid());

        //Assert
        result.Id.Should().Be(todoListId);
        await TodoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >());

        await TodoListRepository.Received().DeleteAsync(Arg.Any <TodoList>());
    }
    public async Task UpdateAsync_Should_Update_Existing_Entity_From_DatabaseAsync()
    {
        //Arrange
        var updateTodoListModel = Builder <UpdateTodoListModel> .CreateNew().Build();

        var todoListId = Guid.NewGuid();
        var todoList   = Builder <TodoList> .CreateNew()
                         .With(tl => tl.CreatedBy = new Guid().ToString())
                         .With(tl => tl.Id        = todoListId)
                         .Build();

        TodoListRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoList);
        TodoListRepository.UpdateAsync(Arg.Any <TodoList>()).Returns(todoList);

        //Act
        var result = await _sut.UpdateAsync(todoListId, updateTodoListModel);

        //Assert
        result.Id.Should().Be(todoListId);
        await TodoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >());

        ClaimService.Received().GetUserId();
        await TodoListRepository.Received().UpdateAsync(Arg.Any <TodoList>());
    }
Exemple #11
0
 public TodoListService()
 {
     todoListRepository = new TodoListRepository();
 }
 public TodoListsController(TodoListRepository todoListRepository, IMapper mapper)
 {
     _todoListRepository = todoListRepository;
     _mapper             = mapper;
 }