Exemple #1
0
        public void CreateAthleteTest()
        {
            var athletes = new List <Athlete> {
                new() { name = "test" }
            };
            var result = controller.CreateAthlete(athletes);

            Assert.AreEqual("test", result.Value.First().name);
        }
        public void CreateAthlete_CallsRepository()
        {
            var input = new AthleteRequest
            {
                Username = "******",
                Email    = "*****@*****.**",
                FullName = "User One"
            };
            var expectedStatus = 201;
            var expected       = new DetailResponse <AthleteResponse>
            {
                Status = 201,
                Detail = new AthleteResponse
                {
                    Username = "******",
                    Email    = "*****@*****.**",
                    FullName = "User One"
                }
            };
            var convertedDto = new AthleteDto
            {
                Username = "******",
                Email    = "*****@*****.**",
                FullName = "User One"
            };

            mockAthleteService.Setup(service => service.CreateAthlete(input))
            .Returns(convertedDto);

            // act
            var actual = athleteController.CreateAthlete(input).Result
                         as CreatedResult;

            // assert
            Assert.Equal(expected, actual.Value);
            Assert.Equal(expectedStatus, actual.StatusCode);
            mockAthleteService.Verify(service => service.CreateAthlete(input), Times.Once);
            mockAthleteService.VerifyNoOtherCalls();
        }