示例#1
0
        public void GetItemById()
        {
            GetReady();
            var actRes   = controller.GetById(1);
            var response = actRes.ExecuteAsync(CancellationToken.None).Result;

            Assert.IsNotNull(response.Content);
        }
示例#2
0
        public async Task GetById_ReturnsExpectedItem()
        {
            // Arrange
            var id   = ObjectId.GenerateNewId().ToString();
            var item = new Item();

            var itemDto = new Faker <ItemDto>()
                          .RuleFor(x => x.Name, f => f.Commerce.Product())
                          .RuleFor(x => x.Id, f => id)
                          .RuleFor(x => x.Description, f => f.Lorem.Paragraph())
                          .RuleFor(x => x.Owner, f => f.Name.FindName())
                          .RuleFor(x => x.Tags, f => f.Lorem.Words().ToList())
                          .Generate();

            _itemsServiceMock.Setup(x => x.GetById(id)).ReturnsAsync(item);
            _mapperMock.Setup(x => x.Map <ItemDto>(item)).Returns(itemDto);

            // Act
            var result = await _itemsController.GetById(id) as OkObjectResult;

            // Assert
            Assert.That(result, Is.Not.Null);
            var value = result.Value;

            Assert.That(value, Is.EqualTo(itemDto));
        }
示例#3
0
        public async Task GetById_ReturnsNotFound_GivenInvalidId()
        {
            var controller = new ItemsController(_context);

            var result = await controller.GetById(99);

            Assert.IsType <NotFoundResult>(result);
        }
示例#4
0
        public async Task Should_get_an_item_by_id()
        {
            //Act
            var result = await _itemsController.GetById(_itemId);

            //Assert
            await _itemService.Received(1).GetById(_itemId);

            result.Should().BeOfType <OkObjectResult>();
        }
示例#5
0
        public async Task GetById_ReturnsItem_GivenValidId()
        {
            var controller = new ItemsController(_context);

            var result = await controller.GetById(2);

            var objectResult = Assert.IsType <ObjectResult>(result);
            var task         = Assert.IsAssignableFrom <Item>(objectResult.Value);

            Assert.Equal("Item 2", task.Description);
        }