private async Task SeedChallengesAsync() { var strategy = _challengePayoutFactory.CreateInstance(); var twoDollars = new EntryFee(2, CurrencyType.Money); var threeDollars = new EntryFee(3, CurrencyType.Money); var twoDollarsForOneEntries = strategy.GetChallengePayout(ChallengePayoutEntries.One, twoDollars); var twoDollarsForTwoEntries = strategy.GetChallengePayout(ChallengePayoutEntries.Two, twoDollars); var twoDollarsForThreeEntries = strategy.GetChallengePayout(ChallengePayoutEntries.Three, twoDollars); var threeDollarsForOneEntries = strategy.GetChallengePayout(ChallengePayoutEntries.One, threeDollars); var threeDollarsForTwoEntries = strategy.GetChallengePayout(ChallengePayoutEntries.Two, threeDollars); var threeDollarsForThreeEntries = strategy.GetChallengePayout(ChallengePayoutEntries.Three, threeDollars); var challenges = new List <IChallenge> { new Challenge(ChallengeId.Parse("d53b366f-e717-43d4-ac12-6e13d37f5cef"), twoDollarsForOneEntries), new Challenge(ChallengeId.Parse("369ae69d-b10d-4d72-84ba-698691646ba6"), twoDollarsForOneEntries), new Challenge(ChallengeId.Parse("eb76fa60-700f-4dce-b312-d69897563437"), twoDollarsForTwoEntries), new Challenge(ChallengeId.Parse("82592581-e6ac-41e0-9c61-773d924f233d"), twoDollarsForTwoEntries), new Challenge(ChallengeId.Parse("9457ae9a-4e5c-436f-b10f-33134af68439"), twoDollarsForThreeEntries), new Challenge(ChallengeId.Parse("91f6d007-b458-4f1c-9814-755b32059e00"), twoDollarsForThreeEntries), new Challenge(ChallengeId.Parse("4ecb13a4-0742-4140-93b0-27ee582e5cab"), threeDollarsForOneEntries), new Challenge(ChallengeId.Parse("fa38f697-2ef3-40e9-a165-d62c3cc750a8"), threeDollarsForOneEntries), new Challenge(ChallengeId.Parse("ac6851b4-2cb7-42ab-bf44-fb197d21221b"), threeDollarsForTwoEntries), new Challenge(ChallengeId.Parse("bb5f6e0c-ada7-47b4-9d24-a3c9ec7df034"), threeDollarsForTwoEntries), new Challenge(ChallengeId.Parse("6ec217f7-3d6a-41c2-b2eb-4cc8799d2af5"), threeDollarsForThreeEntries), new Challenge(ChallengeId.Parse("7d96b314-8d5b-4393-9257-9c0e2cf7c0f1"), threeDollarsForThreeEntries) }; Challenges.AddRange(challenges.Where(challenge => Challenges.All(x => x.Id != challenge.Id)).Select(challenge => challenge.ToModel())); await this.CommitAsync(); }
public async Task <DomainValidationResult <IChallenge> > CreateChallengeAsync( ChallengeId challengeId, ChallengePayoutEntries payoutEntries, EntryFee entryFee, CancellationToken cancellationToken = default ) { var result = new DomainValidationResult <IChallenge>(); var strategy = _challengePayoutFactory.CreateInstance(); if (payoutEntries == 0) { return(result.AddFailedPreconditionError("Challenge payout entries cannot be zero.")); } var payout = strategy.GetChallengePayout(payoutEntries, entryFee); if (payout == null) { return(result.AddFailedPreconditionError("Invalid payout structure. Payout entries doesn't match the chart.")); } if (result.IsValid) { var challenge = new Challenge(challengeId, payout !); _challengeRepository.Create(challenge); await _challengeRepository.CommitAsync(true, cancellationToken); return(challenge); } return(result); }