public override async Task <CreateChallengeResponse> CreateChallenge(CreateChallengeRequest request, ServerCallContext context) { // TODO: Validation... var result = await _challengeService.CreateChallengeAsync( new ChallengeName(request.Name), request.Game.ToEnumeration <Game>(), new BestOf(request.BestOf), new Entries(request.Entries), new ChallengeDuration(TimeSpan.FromDays(request.Duration)), new UtcNowDateTimeProvider(), new Scoring(request.Scoring.Items.OrderBy(item => item.Order).ToDictionary(item => item.StatName, item => item.StatWeighting))); if (result.IsValid) { var response = new CreateChallengeResponse { Challenge = ChallengeProfile.Map(result.Response) }; return(context.Ok(response)); } throw context.FailedPreconditionRpcException(result); }
public async Task <IActionResult> CreateChallengeAsync([FromBody] Requests.CreateChallengeRequest request) { var fetchDoxatagsRequest = new FetchDoxatagsRequest(); var fetchDoxatagsResponse = await _identityServiceClient.FetchDoxatagsAsync(fetchDoxatagsRequest); var findChallengeScoringRequest = new FindChallengeScoringRequest { Game = request.Game }; var findChallengeScoringResponse = await _gameServiceClient.FindChallengeScoringAsync(findChallengeScoringRequest); var createChallengeRequest = new CreateChallengeRequest { Name = request.Name, Game = request.Game, BestOf = request.BestOf, Entries = request.Entries, Duration = request.Duration, Scoring = findChallengeScoringResponse.Scoring }; var createChallengeResponse = await _challengesServiceClient.CreateChallengeAsync(createChallengeRequest); try { var createChallengePayoutRequest = new CreateChallengePayoutRequest { ChallengeId = createChallengeResponse.Challenge.Id, PayoutEntries = createChallengeResponse.Challenge.Entries / 2, // TODO EntryFee = new CurrencyDto { Amount = request.EntryFee.Amount, Type = request.EntryFee.Type } }; var createChallengePayoutResponse = await _cashierServiceClient.CreateChallengePayoutAsync(createChallengePayoutRequest); return(this.Ok(ChallengeMapper.Map(createChallengeResponse.Challenge, createChallengePayoutResponse.Payout, fetchDoxatagsResponse.Doxatags))); } catch (RpcException exception) { var deleteChallengeRequest = new DeleteChallengeRequest { ChallengeId = createChallengeResponse.Challenge.Id }; await _challengesServiceClient.DeleteChallengeAsync(deleteChallengeRequest); throw exception.Capture(); } }
public void CreateChallenge_ShouldThrowFailedPreconditionRpcException() { // Arrange var userId = new UserId(); const string email = "*****@*****.**"; var claims = new[] { new Claim(JwtClaimTypes.Subject, userId.ToString()), new Claim(JwtClaimTypes.Email, email) }; var host = TestHost.WithClaimsFromBearerAuthentication(claims); host.Server.CleanupDbContext(); var request = new CreateChallengeRequest(); var client = new ChallengeService.ChallengeServiceClient(host.CreateChannel()); // Act Assert var func = new Func <Task>(async() => await client.CreateChallengeAsync(request)); func.Should().Throw <RpcException>(); }
public async Task CreateChallenge_ShouldBeOfTypeCreateChallengeResponse() { // Arrange var userId = new UserId(); const string email = "*****@*****.**"; var claims = new[] { new Claim(JwtClaimTypes.Subject, userId.ToString()), new Claim(JwtClaimTypes.Email, email) }; var host = TestHost.WithClaimsFromBearerAuthentication(claims); host.Server.CleanupDbContext(); var request = new CreateChallengeRequest { BestOf = BestOf.Five, Duration = 5, Entries = Entries.Four, Game = EnumGame.LeagueOfLegends, Name = "Test", Scoring = new ChallengeScoringDto { Items = { new ChallengeScoringDto.Types.Item { StatName = "StatName", StatWeighting = 5F, Order = 0 } } } }; var client = new ChallengeService.ChallengeServiceClient(host.CreateChannel()); // Act var response = await client.CreateChallengeAsync(request); //Assert response.Should().BeOfType <CreateChallengeResponse>(); }
public async Task <IActionResult> Add(CreateChallengeRequest request, [FromServices] IHandler <CreateChallengeRequest, ObjectResult> handler) { return(await handler.Handle(request)); }
/// <summary> /// Begin a new CreateChallengeRequest /// </summary> /// <param name="requestData"></param> /// <returns></returns> public CreateChallengeResponse CreateChallengeRequest(CreateChallengeRequest requestData) { return(JsonConvert.DeserializeObject <CreateChallengeResponse>(Requestor.PostString(Urls.CreateChallengeRequest, JsonHelper.SerializeData(requestData)).ResponseJson)); }
/// <summary> /// Begin a new asynchronous CreateChallengeRequest /// </summary> /// <param name="requestData"></param> /// <returns></returns> public async Task <CreateChallengeResponse> CreateChallengeRequestAsync(CreateChallengeRequest requestData) { var res = await Requestor.PostStringAsync(Urls.CreateChallengeRequest, JsonHelper.SerializeData(requestData)); return(JsonConvert.DeserializeObject <CreateChallengeResponse>(res.ResponseJson)); }