public async Task <IActionResult> Create([FromBody] AddGolfRound golfRound) { try { Guid golfRoundId = await _golfRoundAccessLayer.AddGolfRound(new GolfRound { Date = golfRound.Date, CourseId = golfRound.CourseId }); foreach (Score score in golfRound.Scores) { score.GolfRoundId = golfRoundId; if (!await AddScore(golfRound.Date, score, golfRound.CourseId)) { return(BadRequest()); } } return(Ok(true)); } catch { return(BadRequest(false)); } }
public async Task TestCreateGolfRound() { var testAddGolfRound = new AddGolfRound() { Date = _createdAt, CourseId = new Guid("00000000-0000-0000-0001-000000000000"), Scores = new List <Score>() { new Score() { Id = new Guid("00000000-0000-0000-0000-000000000003"), PlayerId = new Guid("00000000-0000-0000-0001-000000000000"), Value = 40, GolfRoundId = new Guid("00000000-0000-0000-0000-000000000001"), }, new Score() { Id = new Guid("00000000-0000-0000-0000-000000000004"), PlayerId = new Guid("00000000-0000-0000-0002-000000000000"), Value = 57, GolfRoundId = new Guid("00000000-0000-0000-0000-000000000001"), } } }; _mockGolfRoundAccessLayer.Setup(x => x.AddGolfRound(new GolfRound() { CourseId = new Guid("00000000-0000-0000-0001-000000000000"), Date = _createdAt, })).ReturnsAsync(new Guid("00000000-0000-0000-0000-000000000001")); _mockScoreAccessLayer.Setup(x => x.AddScore(It.IsAny <Score>())).ReturnsAsync(true); _mockCourseAccessLayer.Setup(x => x.GetCourse(new Guid("00000000-0000-0000-0001-000000000000"))) .Returns(new Course() { Id = new Guid("00000000-0000-0000-0001-000000000000"), Name = "Point Walter", Holes = "1-9", Location = "Western Australia", Par = 35, ScratchRating = 34, Slope = 115, TeeName = "Blue Men" }); _mockHandicapAccessLayer.Setup(x => x.GetOrderedHandicaps(new Guid("00000000-0000-0000-0001-000000000000"))).Returns( new List <Handicap>() { new Handicap() { CurrentHandicap = 20, Value = 25, } } ); _mockHandicapAccessLayer.Setup(x => x.AddHandicap(It.IsAny <Handicap>())).ReturnsAsync(true); _mockPlayerAccessLayer.Setup(x => x.GetPlayer(It.IsAny <Guid>())).Returns( new Player() { } ); _mockPlayerAccessLayer.Setup(x => x.UpdatePlayer(It.IsAny <Player>())).ReturnsAsync(true); var actual = await _sut.Create(testAddGolfRound) as ObjectResult; actual.StatusCode.Should().Be(200); }