public void GetAll_Returns_A_List_Of_ToDos() { var controller = new TodoController(); var result = controller.GetAll(); Assert.That(result.Count, Is.EqualTo(1)); }
public async Task Get_All_Items() { var result = await ControllerUnderTest.GetAll() as OkObjectResult; var items = result.Value as List <TodoItem>; Assert.AreEqual(items.Count, 1); Assert.AreEqual(items[0].Id, 1); Assert.AreEqual(items[0].Name, "None"); }
async Task ListAllTodos() { Cli.DisplayLine("Called ListAllTodos()"); var todos = await todoctrl.GetAll(); foreach (var todo in todos) { Console.WriteLine($"{todo}"); } }
public async Task TodoGetAll_WithValidModel_Return_OkResult() { //Arrange //Act var result = await _controller.GetAll(); //Assert Assert.IsType <OkObjectResult>(result); }
public void Post_Saves_Todo() { var todo = new Todo(); var controller = new TodoController(); controller.Post(todo); var result = controller.GetAll(); Assert.That(result.Count, Is.EqualTo(2)); }
public void Index_ReturnsAListOfTodo() { var controller = new TodoController(_context, _logger.Object); var result = controller.GetAll(); Assert.False(result.ElementAt(0).IsComplete); Assert.Equal("Item1", result.ElementAt(0).Name); Assert.Equal(1, result.ElementAt(0).Id); Assert.Single(result); }
public void TestGetAll() { var ctrl = new TodoController(_context, _logger); var items = ctrl.GetAll(); var iter = items.GetEnumerator(); iter.MoveNext(); Assert.Equal(iter.Current.Name, "Item1"); iter.MoveNext(); Assert.Equal(iter.Current.Name, "Item2"); }
public void ShouldReturnAllTodoItems() { var expected = new List <TodoItem>(new TodoItem[] { new TodoItem { Id = 1, Name = "Mow the Lawn", IsComplete = false }, new TodoItem { Id = 2, Name = "Do the Dishes", IsComplete = false } }); CollectionAssert.AreEquivalent(expected, controller.GetAll().Value); }
public async Task GetAll_Returns_ListOfTodos() { var options = CreateDbContextOptions(); using (var todoApiDbContext = new TodoApiDbContext(options)) { var mockLogger = new Mock <ILogger <TodoController> >(); var todoController = new TodoController(mockLogger.Object, todoApiDbContext); var listOfTodosResult = await todoController.GetAll(); Assert.IsType <List <TodoItem> >(listOfTodosResult.Value); } }
public void WhenGetAllIsCalledThenAllTodoItemsInRepoAreReturned() { var item = new TodoItem { Id = 1, Name = "Something" }; repoMock.Setup(x => x.GetAll()).Returns(new List <TodoItem>() { item }); var actual = sut.GetAll(); Assert.Contains(item, actual.Value); }
public async Task GetReturnListOfTodo() { var mockRepo = new Mock <ITodoRepository>(); mockRepo.Setup(repo => repo.GetAll()) .Returns(Task.FromResult(GetTestTodoList())); var controller = new TodoController(mockRepo.Object); var result = await controller.GetAll(); var okResult = Assert.IsType <OkObjectResult>(result); var returnedResult = Assert.IsType <List <TodoItem> >(okResult.Value); Assert.Equal(1, returnedResult.Count()); }
public void GetAll_ShouldReturnOkHttpStatusCodeWithItems_InitializeCollection() { // Arrange var mockRepo = new Mock <ITodoRepository>(); mockRepo.Setup(repo => repo.GetAll()) .Returns(GetAllTodoItems()); var controller = new TodoController(mockRepo.Object); // Act var result = controller.GetAll(); // Assert Assert.IsType <ActionResult <IEnumerable <TodoItem> > >(result); }
public void TestGetAllTasks() { // Arrange var controller = new TodoController(_todoContext); // Act var response = controller.GetAll(); // Assert Assert.Equal(3, response.Count()); // // <PackageReference Include="FluentAssertions" Version="4.19.2" /> // // Assert // var okResult = result.Should().BeOfType<OkObjectResult>().Subject; // var persons = okResult.Value.Should().BeAssignableTo<IEnumerable<Person>>().Subject; // persons.Count().Should().Be(50); }
public void GetAllTest() { // Arrange var mockManager = new Mock <ITodoManager>(); mockManager.Setup(i => i.GetAll()).Returns(GetTestTodos); var controller = new TodoController(mockManager.Object); // Act var result = controller.GetAll(); // Assert var objectResult = Assert.IsType <ObjectResult>(result); var todos = Assert.IsAssignableFrom <IEnumerable <Todo> >(objectResult.Value); Assert.Equal(2, todos.Count()); }
public void Index_Returns_ListOf_Todo() { // Arrange var mockRepo = new Mock <ITodoRepository>(); mockRepo.Setup(repo => repo.GetAll()) .Returns(GetTestTodos()); var controller = new TodoController(mockRepo.Object); // Act var result = controller.GetAll(); // Assert Assert.Equal(2, result.Count()); Assert.Equal("Test One", result.FirstOrDefault().Name); }
public async Task GetAll_Logging_Working() { var options = CreateDbContextOptions(); using (var todoApiDbContext = new TodoApiDbContext(options)) { var mockLogger = new Mock <ILogger <TodoController> >(); var todoController = new TodoController(mockLogger.Object, todoApiDbContext); var listOfTodosResult = await todoController.GetAll(); mockLogger.Verify(x => x.Log( It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once); } }
public async void GetAll_IfAnyExist_ReturnObject() { var context = new Mock <DataContext>(); context.Setup(x => x.Todos).ReturnsDbSet(GetTodos()); var logger = Mock.Of <ILogger <TodoRepository> >(); var repo = new TodoRepository(context.Object, logger); var hub = new Mock <IHubContext <MainHub> >(); var controller = new TodoController(hub.Object, repo); var result = await controller.GetAll(); var content = result as OkObjectResult; Todo[] data = (Todo[])content.Value; Assert.True(data.Length > 0); }
public void CanGetAllTodos() { var options = new DbContextOptionsBuilder <HoneydewContext>() .UseInMemoryDatabase(databaseName: "testing") .Options; using (var context = new HoneydewContext(options)) { var tController = new TodoController(context); Todolist example = new Todolist() { Name = "example", Id = 9 }; Todo first = new Todo() { Name = "example", Belongs = example, Complete = true }; Todo second = new Todo() { Name = "example2", Belongs = example, Complete = false }; context.Todos.Add(first); context.Todos.Add(second); context.SaveChanges(); int count = 0; var results = tController.GetAll(); foreach (Todo t in results) { Assert.True(first == t || second == t); count++; } Assert.Equal(2, count); } }
public void TodoController_Index() { IEnumerable <TodoItem> res = _todoController.GetAll(); Assert.NotNull(res); }
protected override void Context() { _todoServiceMock = new Mock <ITodoService>(); _sut = new TodoController(_todoServiceMock.Object); _sut.GetAll().Wait(); }