Exemplo n.º 1
0
        public List <ToDoList> GetLists()
        {
            ToDoListRepository toDoListRepository = new ToDoListRepository();
            List <ToDoList>    lists = toDoListRepository.GetObjectsList(currentUser.userId);

            return(lists);
        }
        public async void UpdateToDoItemHandler_IsVerifiable_ReturnsNotNullResult()
        {
            //Arrange
            var itemToUpdate = new ToDoListItem {
                Id = Guid.Parse("7a73db1a-f0a8-4937-a229-b9787ea2c54f"), Completed = true, Name = "test"
            };

            var _serviceContextMock = new Mock <IServiceContext>();

            _serviceContextMock.Setup(a => a.UpdateToDoItemStatus(itemToUpdate)).Verifiable();
            _serviceContextMock.Setup(a => a.GetToDoListItemAsync(itemToUpdate.Id)).Returns(GetToDoListItemFromFileAsync(itemToUpdate.Id)).Verifiable();

            JsonPatchDocument <ToDoItemUpdationDto> patch = new JsonPatchDocument <ToDoItemUpdationDto>();

            patch.Replace(e => e.Completed, !itemToUpdate.Completed);

            var command = new UpdateToDoListItemStatusCommand();

            command.Id         = itemToUpdate.Id;
            command.UpdateItem = patch;

            IToDoListRepository             _todoListRepository = new ToDoListRepository(_serviceContextMock.Object);
            UpdateToDoListItemStatusHandler handler             = new UpdateToDoListItemStatusHandler(_todoListRepository, _mapper);

            //Act
            var _handler = await handler.Handle(command, new System.Threading.CancellationToken());

            //Assert - verify able to call UpdateToDoListItemStatusHandler
            Assert.NotNull(handler);
        }
        public async void DeleteItemHandler_IsVerifiable_ReturnsNotNullResult()
        {
            var itemToDelete = new ToDoListItem {
                Id = Guid.Parse("7a73db1a-f0a8-4937-a229-b9787ea2c54f"), Completed = true, Name = "test"
            };

            //Arrange
            var _serviceContextMock = new Mock <IServiceContext>();

            _serviceContextMock.Setup(a => a.DeleteToDoItem(It.IsAny <ToDoListItem>())).Verifiable();
            _serviceContextMock.Setup(a => a.GetToDoListItemAsync(itemToDelete.Id)).Verifiable();

            DeleteToDoItemCommand command = new DeleteToDoItemCommand();

            command.Id = Guid.NewGuid();

            IToDoListRepository _todoListRepository = new ToDoListRepository(_serviceContextMock.Object);

            DeleteToDoItemHandler handler = new DeleteToDoItemHandler(_todoListRepository, _mapper);

            //Act
            var _handler = await handler.Handle(command, new System.Threading.CancellationToken());

            //Assert
            Assert.NotNull(handler);
        }
        public async Task <IEnumerable <ToDoListViewModel> > Handle(ListToDoListQuery request, CancellationToken cancellationToken)
        {
            var toDoLists = await ToDoListRepository.List();

            var viewModels = toDoLists.Select(x => new ToDoListViewModel(x)).ToList();

            return(viewModels);
        }
        public async Task <ToDoListViewModel> Handle(CreateToDoListCommand request, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Received request to create To Do List {request.Name}");

            ToDoList newToDoList = (ToDoList)request;

            var response = await ToDoListRepository.Insert(newToDoList);

            return(new ToDoListViewModel(response));
        }
Exemplo n.º 6
0
        public void CreateToDoList(string listName)
        {
            ToDoListRepository toDoListRepository = new ToDoListRepository();

            ToDoList newList = new ToDoList();

            newList.listName = listName;
            newList.userId   = currentUser.userId;

            toDoListRepository.Insert(newList);
        }
        public void ProcessRequest(HttpContext context)
        {
            var ToDoList = new ToDoListRepository().GetList();
            var result   = new {
                iTotalRecords        = ToDoList.Count,
                iTotalDisplayRecords = ToDoList.Count,
                aaData = ToDoList
            };
            JavaScriptSerializer jss = new JavaScriptSerializer();

            context.Response.Write(jss.Serialize(result));
        }
        public async Task <ToDoListViewModel> Handle(GetToDoListQuery request, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Received request for To Do List by ID: '{request.Id}'");

            var toDoList = await ToDoListRepository.Get(request.Id);

            if (toDoList == null)
            {
                throw new NotFoundException(request.Id, typeof(ToDoList));
            }

            return(new ToDoListViewModel(toDoList));
        }
Exemplo n.º 9
0
        public void RemoveToDoList(ToDoList deletedList)
        {
            ToDoListRepository toDoListRepository = new ToDoListRepository();

            toDoListRepository.Delete(deletedList);

            //Items also will be deleted from related list.
            ToDoItemRepository toDoItemRepository = new ToDoItemRepository();
            List <ToDoItem>    toDoItems          = GetItems(deletedList);

            foreach (ToDoItem item in toDoItems)
            {
                toDoItemRepository.Delete(item);
            }
        }
        public async Task <bool> Handle(DeleteToDoListCommand request, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Received request to delete ame To Do List {request.Id}");

            var toDoList = await ToDoListRepository.Get(request.Id);

            if (toDoList == null)
            {
                throw new NotFoundException(request.Id, typeof(ToDoList));
            }

            await ToDoListRepository.Delete(toDoList.Id);

            return(true);
        }
        public async Task <ToDoListViewModel> Handle(UpdateToDoListDescriptionCommand request, CancellationToken cancellationToken)
        {
            Logger.LogInformation($"Received request to update description for To Do List {request.Id} to {request.Description}");

            var toDoList = await ToDoListRepository.Get(request.Id);

            if (toDoList == null)
            {
                throw new NotFoundException(request.Id, typeof(ToDoList));
            }

            toDoList.Description = request.Description;

            var response = await ToDoListRepository.Update(toDoList);

            return(new ToDoListViewModel(response));
        }
        public void ToDoListRepository_Update_ShouldReturnUpdatedEntity()
        {
            var listToChange = new Order()
            {
                Id   = 1,
                Name = "name"
            };
            var dbData = new List <Order>()
            {
                listToChange,
                new Order()
                {
                    Id   = 2,
                    Name = "name"
                },
                new Order()
                {
                    Id   = 3,
                    Name = "name"
                }
            }.AsQueryable();

            var newList = new Order()
            {
                Id   = 1,
                Name = "nameChanged"
            };
            var dbSetMock = new Mock <DbSet <Order> >();

            dbSetMock.As <IQueryable <Order> >().Setup(x => x.Provider).Returns(dbData.Provider);
            dbSetMock.As <IQueryable <Order> >().Setup(x => x.Expression).Returns(dbData.Expression);
            dbSetMock.As <IQueryable <Order> >().Setup(x => x.ElementType).Returns(dbData.ElementType);
            dbSetMock.As <IQueryable <Order> >().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator());
            var dbContextMock = new Mock <ApplicationDbContext>();

            dbContextMock.Setup(x => x.Set <Order>()).Returns(dbSetMock.Object);
            var repo   = new ToDoListRepository(dbContextMock.Object);
            var result = repo.Update(newList);

            Assert.AreEqual(newList.Name, result.Name);
        }
Exemplo n.º 13
0
        public async void GetToDoItemsHandler_IsVerifiable_ReturnsNotNullResult()
        {
            //Arrange
            var _serviceContextMock = new Mock <IServiceContext>();

            _serviceContextMock.Setup(a => a.GetToDoListItemsAsync()).Returns(GetToDoListItemsFromFileAsync()).Verifiable();

            //Act
            IToDoListRepository _todoListRepository = new ToDoListRepository(_serviceContextMock.Object);

            GetAllItemsHandler handler = new GetAllItemsHandler(_todoListRepository, _mapper);

            GetAllItemsQuery query = new GetAllItemsQuery();

            //Act
            var result = await handler.Handle(query, new System.Threading.CancellationToken());

            //Assert
            Assert.NotNull(result);
            Assert.Single(result);
        }
Exemplo n.º 14
0
        private Engine()
        {
            // Read config file
            _configuration          = ConfigInitializer.InitConfig();
            _connectionStringCreate = _configuration.GetConnectionString("Create");
            _connectionStringEdit   = _configuration.GetConnectionString("Edit");

            InitializeDb(_connectionStringCreate, _connectionStringEdit);

            UserRepository     userRepositiry     = new UserRepository(_connectionStringEdit);
            ToDoListRepository toDoListRepository = new ToDoListRepository(_connectionStringEdit);

            _userService     = new UserService(userRepositiry);
            _toDoListService = new ToDoListService(toDoListRepository);

            _reader = new ConsoleReader();
            _writer = new ConsoleWriter();

            _userController     = new UserController(_userService, _writer, _reader);
            _toDoListController = new ToDoListController(_toDoListService, _userService, _writer, _reader);

            _menu = new Menu(_writer, _reader, _userController, _toDoListController);
        }
Exemplo n.º 15
0
        public async void CreateItemsHandler_IsVerifiable_ReturnsNotNullResult()
        {
            //Arrange
            var _serviceContextMock = new Mock <IServiceContext>();

            _serviceContextMock.Setup(a => a.AddToDoListItemAsync(It.IsAny <ToDoListItem>())).Verifiable();

            CreateToDoItemCommand command = new CreateToDoItemCommand();

            command.Name      = "Test";
            command.Completed = false;

            IToDoListRepository _todoListRepository = new ToDoListRepository(_serviceContextMock.Object);

            CreateToDoItemHandler handler = new CreateToDoItemHandler(_todoListRepository, _mapper);

            //Act
            var result = await handler.Handle(command, new System.Threading.CancellationToken());

            //Assert
            Assert.IsType <Guid>(result.Id);
            Assert.Matches(command.Name, result.Name);
            Assert.Equal(command.Completed, result.Completed);
        }
Exemplo n.º 16
0
 public void Setup()
 {
     _repository         = new Repository <ToDoList>(DBContext);
     _toDoListRepository = new ToDoListRepository(_repository, Mapper);
 }
        public void ToDoListRepository_Update_ShouldReturnUpdatedEntity()
        {
            var listToChange = new Order()
            {
                Id = 1,
                Name = "name"
            };
            var dbData = new List<Order>()
            {
                listToChange,
                new Order()
                {
                    Id = 2,
                    Name ="name"
                },
                new Order()
                {
                    Id = 3,
                    Name ="name"
                }
            }.AsQueryable();

            var newList = new Order()
            {
                Id = 1,
                Name = "nameChanged"
            };
            var dbSetMock = new Mock<DbSet<Order>>();
            dbSetMock.As<IQueryable<Order>>().Setup(x => x.Provider).Returns(dbData.Provider);
            dbSetMock.As<IQueryable<Order>>().Setup(x => x.Expression).Returns(dbData.Expression);
            dbSetMock.As<IQueryable<Order>>().Setup(x => x.ElementType).Returns(dbData.ElementType);
            dbSetMock.As<IQueryable<Order>>().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator());
            var dbContextMock = new Mock<ApplicationDbContext>();
            dbContextMock.Setup(x => x.Set<Order>()).Returns(dbSetMock.Object);
            var repo = new ToDoListRepository(dbContextMock.Object);
            var result = repo.Update(newList);

            Assert.AreEqual(newList.Name, result.Name);
        }
Exemplo n.º 18
0
 public ToDoListService(ToDoListRepository toDoListRepository)
 {
     _toDoListRepository = toDoListRepository;
 }
Exemplo n.º 19
0
 public ToDoListService(ToDoListRepository repo)
 {
     _repo = repo;
 }