Exemplo n.º 1
0
        public void TestCreateTournament()
        {
            // Arrange
            int TEST_STYLE_ID        = 1;
            int TEST_NUM_OF_STATIONS = 4;

            var request          = new CreateTournamentRequest(TEST_TOURNAMENT_ID, TEST_STYLE_ID, TEST_NUM_OF_STATIONS);
            var expectedResponse = new Response <EmptyResponse>();

            var mockClient = new Mock <ITournamentClient>();

            mockClient.Setup(client => client.CreateTournament(request))
            .Returns(expectedResponse.WithSuccess());

            // Act
            var tournamentController = new TournamentController(
                requestFieldExtractor,
                mockClient.Object);

            var result   = tournamentController.CreateTournament(request) as OkObjectResult;
            var response = result.Value as Response <EmptyResponse>;

            // Assert
            Assert.NotNull(response);
            Assert.True(response.IsSuccessStatusCode);
        }
        public async Task <IActionResult> CreateTournament(TournamentCreateModel model)
        {
            var request    = new CreateTournamentRequest(model.TournamentName, model.TeamsCount);
            var tournament = await _mediator.Send(request);

            return(Ok(tournament.Name));
        }
        public async Task <IActionResult> CreateTournament([FromRoute] Guid golfClubId,
                                                           [FromBody] CreateTournamentRequest request,
                                                           CancellationToken cancellationToken)
        {
            Guid tournamentId = Guid.NewGuid();

            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim);

            if (validationResult == false)
            {
                return(this.Forbid());
            }

            // Create the command
            CreateTournamentCommand command = CreateTournamentCommand.Create(tournamentId, Guid.Parse(golfClubIdClaim.Value), request);

            // Route the command
            await this.CommandRouter.Route(command, cancellationToken);

            // return the result
            return(this.Created($"{TournamentController.ControllerRoute}/{tournamentId}", new CreateTournamentResponse
            {
                TournamentId = tournamentId
            }));
        }
Exemplo n.º 4
0
        public async Task GolfClubController_POST_CreateTournament_TournamentIsCreated()
        {
            // 1. Arrange
            HttpClient client = this.WebApplicationFactory.AddPlayer().CreateClient();

            CreateTournamentRequest createTournamentRequest = TestData.CreateTournamentRequest;
            String uri = $"api/golfclubs/{TestData.GolfClubId}/tournaments";

            client.DefaultRequestHeaders.Add("api-version", "2.0");
            StringContent content = Helpers.CreateStringContent(createTournamentRequest);

            // 2. Act
            HttpResponseMessage response = await client.PostAsync(uri, content, CancellationToken.None);

            // 3. Assert
            response.StatusCode.ShouldBe(HttpStatusCode.Created);

            String responseAsJson = await response.Content.ReadAsStringAsync();

            responseAsJson.ShouldNotBeNullOrEmpty();

            CreateTournamentResponse responseObject = JsonConvert.DeserializeObject <CreateTournamentResponse>(responseAsJson);

            responseObject.TournamentId.ShouldNotBe(Guid.Empty);
        }
        public async Task GivenWhenICreateATournamentWithTheFollowingDetails(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(tableRow["GolfClubNumber"]);

                List <MeasuredCourseListResponse> measuredCourseList = await this.TestingContext.DockerHelper.GolfClubClient.GetMeasuredCourses(this.TestingContext.GolfClubAdministratorToken,
                                                                                                                                                createGolfClubResponse.GolfClubId,
                                                                                                                                                CancellationToken.None).ConfigureAwait(false);

                MeasuredCourseListResponse measuredCourse = measuredCourseList.Single(m => m.Name == tableRow["MeasuredCourseName"]);

                TournamentFormat tournamentFormat = Enum.Parse <TournamentFormat>(tableRow["TournamentFormat"], true);
                PlayerCategory   playerCategory   = Enum.Parse <PlayerCategory>(tableRow["PlayerCategory"], true);

                // Work out the tournament date
                DateTime tournamentDate = this.CalculateTournamentDate(tableRow);

                CreateTournamentRequest createTournamentRequest = new CreateTournamentRequest
                {
                    Format           = (Int32)tournamentFormat,
                    Name             = tableRow["TournamentName"],
                    MeasuredCourseId = measuredCourse.MeasuredCourseId,
                    MemberCategory   = (Int32)playerCategory,
                    TournamentDate   = tournamentDate
                };

                this.TestingContext.CreateTournamentRequests.Add(new Tuple <String, String, String>(tableRow["GolfClubNumber"], tableRow["MeasuredCourseName"],
                                                                                                    tableRow["TournamentNumber"]), createTournamentRequest);
            }
        }
 /// <summary>
 /// Creates the tournament.
 /// </summary>
 /// <param name="accessToken">The password token.</param>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="createTournamentRequest">The create tournament request.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 public async Task <CreateTournamentResponse> CreateTournament(String accessToken,
                                                               Guid golfClubId,
                                                               CreateTournamentRequest createTournamentRequest,
                                                               CancellationToken cancellationToken)
 {
     return(await this.TournamentClient.CreateTournament(accessToken, golfClubId, createTournamentRequest, cancellationToken));
 }
Exemplo n.º 7
0
        public async Task <CreateTournamentResponse> CreateTournament([FromBody] CreateTournamentRequest request)
        {
            string id = await tournamentService.CreateTournament(request);

            return(new CreateTournamentResponse
            {
                TournamentId = id,
            });
        }
Exemplo n.º 8
0
        public Response <EmptyResponse> CreateTournament(CreateTournamentRequest request)
        {
            var response = client.PostAsync("tournament", RequestSerializer.Content(request)).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <Response <EmptyResponse> >(response.Content.ReadAsStringAsync().Result));
            }
            return(new Response <EmptyResponse>(response.RequestMessage.ToString(), (int)response.StatusCode));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates the tournament.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="claimsIdentity">The claims identity.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task CreateTournament(String accessToken,
                                           ClaimsIdentity claimsIdentity,
                                           CreateTournamentViewModel viewModel,
                                           CancellationToken cancellationToken)
        {
            CreateTournamentRequest request = this.ModelFactory.ConvertFrom(viewModel);

            Guid golfClubId = ApiClient.GetClaimValue <Guid>(claimsIdentity, "GolfClubId");

            await this.TournamentClient.CreateTournament(accessToken, golfClubId, request, cancellationToken);
        }
Exemplo n.º 10
0
        public async Task <IActionResult> CreateTournament([FromBody] CreateTournamentRequest request)
        {
            try
            {
                await tournamentService.Create(request.Date);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Bad time: {e.Message}"));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <returns></returns>
        public CreateTournamentRequest ConvertFrom(CreateTournamentViewModel viewModel)
        {
            CreateTournamentRequest request = new CreateTournamentRequest
            {
                Format           = viewModel.Format,
                MemberCategory   = viewModel.MemberCategory,
                MeasuredCourseId = viewModel.MeasuredCourseId,
                TournamentDate   = viewModel.TournamentDate.Value,
                Name             = viewModel.Name
            };

            return(request);
        }
        public void ModelFactory_ConvertFrom_CreateTournamentViewModel_ConvertedSuccessfully()
        {
            ModelFactory factory = new ModelFactory();

            CreateTournamentViewModel viewModel = ModelFactoryTestData.GetCreateTournamentViewModel();

            CreateTournamentRequest apiRequest = factory.ConvertFrom(viewModel);

            apiRequest.Format.ShouldBe(viewModel.Format);
            apiRequest.MeasuredCourseId.ShouldBe(viewModel.MeasuredCourseId);
            apiRequest.MemberCategory.ShouldBe(viewModel.MemberCategory);
            apiRequest.Name.ShouldBe(viewModel.Name);
            apiRequest.TournamentDate.ShouldBe(viewModel.TournamentDate.Value);
        }
Exemplo n.º 13
0
        public async void Create_ShouldReturnError_IfTournamentCreateFails()
        {
            var testDate = new DateTime(2020, 1, 1);
            var request  = new CreateTournamentRequest()
            {
                Date = testDate
            };

            mockTournamentService.Setup(x => x.Create(It.IsAny <DateTime>())).ThrowsAsync(new Exception("Bad time"));

            var result = Assert.IsType <ObjectResult>(await tournamentController.CreateTournament(request));

            Assert.Equal(StatusCodes.Status500InternalServerError, result.StatusCode);
        }
Exemplo n.º 14
0
        public async void Create_ShouldReturnOk_IfTournamentCreated()
        {
            var testDate = new DateTime(2020, 1, 1);
            var request  = new CreateTournamentRequest()
            {
                Date = testDate
            };

            mockTournamentService.Setup(x => x.Create(testDate));

            var result = Assert.IsType <OkResult>(await tournamentController.CreateTournament(request));

            mockTournamentService.VerifyAll();
        }
        public async Task ThenTournamentNumberForGolfClubMeasuredCourseWillBeCreated(String tournamentNumber, String golfClubNumber, String measuredCourseName)
        {
            CreateTournamentRequest createTournamentRequest = this.TestingContext.GetCreateTournamentRequest(golfClubNumber, measuredCourseName, tournamentNumber);

            CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(golfClubNumber);

            CreateTournamentResponse createTournamentResponse = await this.TestingContext.DockerHelper.GolfClubClient
                                                                .CreateTournament(this.TestingContext.GolfClubAdministratorToken, createGolfClubResponse.GolfClubId, createTournamentRequest, CancellationToken.None)
                                                                .ConfigureAwait(false);

            createTournamentResponse.TournamentId.ShouldNotBe(Guid.Empty);

            this.TestingContext.CreateTournamentResponses.Add(new Tuple <String, String, String>(golfClubNumber, measuredCourseName,
                                                                                                 tournamentNumber), createTournamentResponse);
        }
        public async Task TestCreateTournament()
        {
            // Arrange
            int TEST_STYLE_ID = 1;
            int TEST_NUM_OF_STATIONS = 4;
            var request = new CreateTournamentRequest(TEST_TOURNAMENT_ID, TEST_STYLE_ID, TEST_NUM_OF_STATIONS);

            // Act
            var client = _testHostFixture.Client;
            var response = await client.PostAsync("/api/tournament/create", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);
        }
Exemplo n.º 17
0
        public async Task <string> CreateTournament(CreateTournamentRequest request)
        {
            using (var command = connectionProvider.CreateCommand(@"
                INSERT INTO Tournament (
                    id,
                    season,
                    title,
                    description,
                    location,
                    startDate,
                    endDate
                )
                VALUES (
                    @id,
                    @season,
                    @title,
                    @description,
                    @location,
                    @startDate,
                    @endDate
                )
            "))
            {
                string id = Guid.NewGuid().ToString();

                command.AddParameter("@id", id);
                command.AddParameter("@season", request.SeasonId);
                command.AddParameter("@title", request.Title);
                command.AddParameter("@description", request.Description);
                command.AddParameter("@location", request.Location);
                command.AddParameter("@startDate", request.StartDate);
                command.AddParameter("@endDate", request.EndDate);

                await command.ExecuteNonQueryAsync();

                return(id);
            }
        }
        /// <summary>
        /// Creates the tournament.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="golfClubId">The golf club identifier.</param>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CreateTournamentResponse> CreateTournament(String accessToken,
                                                                      Guid golfClubId,
                                                                      CreateTournamentRequest request,
                                                                      CancellationToken cancellationToken)
        {
            CreateTournamentResponse response = null;

            String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}/tournaments";

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(request);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <CreateTournamentResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error creating the new tournament {request.Name}.", ex);

                throw exception;
            }

            return(response);
        }
Exemplo n.º 19
0
        public Response <EmptyResponse> CreateTournament(CreateTournamentRequest request)
        {
            var response = tournamentClient.CreateTournament(request);

            return(response);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Creates the specified create tournament request.
 /// </summary>
 /// <param name="tournamentId">The tournament identifier.</param>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="createTournamentRequest">The create tournament request.</param>
 /// <returns></returns>
 public static CreateTournamentCommand Create(Guid tournamentId, Guid golfClubId, CreateTournamentRequest createTournamentRequest)
 {
     return(new CreateTournamentCommand(tournamentId, golfClubId, createTournamentRequest, Guid.NewGuid()));
 }
Exemplo n.º 21
0
        public IActionResult CreateTournament([FromBody, Required] CreateTournamentRequest request)
        {
            var response = tournamentService.CreateTournament(request);

            return(Ok(response));
        }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateTournamentCommand" /> class.
 /// </summary>
 /// <param name="tournamentId">The tournament identifier.</param>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="createTournamentRequest">The create tournament request.</param>
 /// <param name="commandId">The command identifier.</param>
 private CreateTournamentCommand(Guid tournamentId, Guid golfClubId, CreateTournamentRequest createTournamentRequest, Guid commandId) : base(commandId)
 {
     this.TournamentId            = tournamentId;
     this.GolfClubId              = golfClubId;
     this.CreateTournamentRequest = createTournamentRequest;
 }