public async Task GetTodos_ReturnsAnOkResultWithTodosArray()
        {
            // Arrange
            var expectedTodos = new List <TodoDTO>()
            {
                new TodoDTO()
                {
                    Id = 1, Name = "Todo 1", IsComplete = true
                }
            };

            var mockService = new Mock <ITodosService>();

            mockService.Setup(ts => ts.GetAllTodosAsync()).ReturnsAsync(expectedTodos);

            var controller = new TodosController(mockService.Object);

            // Action
            var actualTodos = await controller.GetTodos();

            // Assert
            Assert.NotNull(actualTodos);
            Assert.Single(actualTodos);
            Assert.Equal(expectedTodos[0].Id, actualTodos.ToList()[0].Id);
            Assert.Equal(expectedTodos[0].Name, actualTodos.ToList()[0].Name);
            Assert.Equal(expectedTodos[0].IsComplete, actualTodos.ToList()[0].IsComplete);
        }
Esempio n. 2
0
        public void Get_Todos()
        {
            var mockMediator = new Mock <IMediator>();

            mockMediator
            .Setup(t => t.Send(It.IsAny <GetTodosQuery>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new List <Todo> {
                new Todo
                {
                    Id   = 1000,
                    Task = "Write unit test",
                    Done = true
                }
            }));
            var controller = new TodosController(mockMediator.Object);


            var result = controller.GetTodos();


            var okResult = Assert.IsType <OkObjectResult>(result);
            var todos    = Assert.IsType <List <Todo> >(okResult.Value);

            Assert.Single(todos);
        }
Esempio n. 3
0
        public async Task GetTodosTest()
        {
            // Arrange
            init();
            mockRepo.Setup(repo => repo.GetTodos(SortingType.TimeDESC)).Returns(Task.FromResult(GetTestTodos()));

            // Act
            IActionResult result = await controller.GetTodos(null, false);


            // Assert
            var OkObject = Assert.IsType <OkObjectResult>(result);
            var todos    = Assert.IsAssignableFrom <List <TodoView> >(
                OkObject.Value);

            Assert.Equal(3, todos.Count());
        }
Esempio n. 4
0
        public void GetTodos()
        {
            var toDoListId = 1;

            var result = _controller.GetTodos(toDoListId) as ObjectResult;

            Assert.True(result != null, "result is null");
            Assert.True(result.StatusCode == 200, "Status code is not OK");
            Assert.True((result.Value as List <Todo>).Count == 2, "TaDos quantity is not correct");
        }
        public void GetTodosTest()
        {
            var mockSet = new Mock <DbSet <Todo> >();
            //mockSet.SetupData(GetTestTodos());

            var mockContext = new Mock <TodoContext>();

            mockContext.Setup(c => c.Todos).Returns(() => mockSet.Object);

            var controller = new TodosController(mockContext.Object);

            var result = controller.GetTodos();

            Assert.NotNull(result);
        }
Esempio n. 6
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                await UsersController.GetUsers();

                UsersController.SaveUsersToDB();
                _logger.LogInformation("Saved Users");

                await PostsController.GetPosts();

                PostsController.SavePostsToDB();
                _logger.LogInformation("Saved Posts");

                await CommentsController.GetComments();

                CommentsController.SaveCommentsToDB();
                _logger.LogInformation("Saved Comments");

                await AlbumsController.GetAlbums();

                AlbumsController.SaveAlbumsToDB();
                _logger.LogInformation("Saved Albums");

                await PhotosController.GetPhotos();

                PhotosController.SavePhotosToDB();
                _logger.LogInformation("Saving Photos");

                await TodosController.GetTodos();

                TodosController.SaveTodosToDB();
                _logger.LogInformation("Saving Todos");

                await Task.Delay(DelayInSeconds * 1000, stoppingToken);
            }
        }