示例#1
0
        public async Task GetById_WhenGoalNull_ShouldReturnNotFound(
            Guid goalId,
            GoalController sut)
        {
            // Arranges
            sut.GoalService.GetAsync(Arg.Is(goalId)).ReturnsNull();

            // Act
            var result = await sut.GetById(goalId);

            // Asserts
            result.Should().NotBeNull();
            result.Should().BeOfType <NotFoundResult>();
            await sut.GoalService.Received(1).GetAsync(Arg.Is(goalId));

            sut.GoalMapper.DidNotReceive().Map(Arg.Any <Goal>());
        }
示例#2
0
        public async Task GetById_ShouldCallMethodsCorrectly(
            Guid goalId,
            Goal goal,
            GoalModel goalModel,
            GoalController sut)
        {
            // Arranges
            sut.GoalService.GetAsync(Arg.Is(goalId)).Returns(goal);
            sut.GoalMapper.Map(Arg.Is(goal)).Returns(goalModel);

            // Act
            var result = await sut.GetById(goalId);

            // Asserts
            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            ((OkObjectResult)result).Value.Should().BeEquivalentTo(goalModel);
            await sut.GoalService.Received(1).GetAsync(Arg.Is(goalId));

            sut.GoalMapper.Received(1).Map(Arg.Is(goal));
        }