Example #1
0
        public async Task Get_ReturnsNotFound_WhenIdNotExist()
        {
            // Arrange
            var id             = Guid.NewGuid();
            var classUnderTest = new LunchController(_lunchService.Object, _mapper);

            _lunchService.Setup(a => a.GetByIdAsync(It.Is <Guid>(g => g == id)))
            .ReturnsAsync(null as Lunch);

            // Assert
            var result = await classUnderTest.Get(id);

            // Act
            Assert.IsType <NotFoundResult>(result);

            _lunchService.Verify(a => a.GetByIdAsync(It.Is <Guid>(g => g == id)), Times.Once);
        }
Example #2
0
        public async Task Get_ReturnsALunch()
        {
            // Arrange
            var id    = Guid.NewGuid();
            var lunch = GetSampleLunch(id);

            var classUnderTest = new LunchController(_lunchService.Object, _mapper);

            _lunchService.Setup(a => a.GetByIdAsync(It.Is <Guid>(g => g == id)))
            .ReturnsAsync(lunch);

            // Act
            var result = await classUnderTest.Get(id);

            // Assert
            var okResult    = Assert.IsType <OkObjectResult>(result);
            var lunchResult = Assert.IsType <LunchDto>(okResult.Value);

            Assert.True(Equals(lunchResult, lunch));

            _lunchService.Verify(a => a.GetByIdAsync(It.Is <Guid>(g => g == id)), Times.Once);
        }