示例#1
0
        public async Task CreateAsync_WhenSuccess_ShouldCallMethodCorrectly(
            Goal goal,
            GoalService sut)
        {
            // Arrange
            goal.Id = Guid.Empty;
            sut.GoalRepository.CreateAsync(Arg.Is(goal)).Returns(true);

            // Act
            var result = await sut.CreateAsync(goal);

            // Asserts
            result.Should().BeEquivalentTo(goal);
            await sut.GoalRepository.Received(1)
            .CreateAsync(Arg.Is <Goal>(x => x.Id != Guid.Empty));
        }
示例#2
0
        public async Task <IActionResult> Post(
            [FromBody] GoalModel goalModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var goal        = GoalMapper.Map(goalModel);
            var createdGoal = await GoalService.CreateAsync(goal);

            goalModel = GoalMapper.Map(createdGoal);

            return(goalModel != null
                ? Created(string.Empty, goalModel) as IActionResult
                : StatusCode((int)HttpStatusCode.NotModified));
        }