Exemple #1
0
        public async Task FindMatchAsync_ShouldBeEquivalentToMatch(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(83459632, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var matchQuery = new MatchQuery(context);

                foreach (var match in challenge.Participants.SelectMany(participant => participant.Matches).ToList())
                {
                    //Act
                    var matchAsync = await matchQuery.FindMatchAsync(MatchId.FromGuid(match.Id));

                    //Arrange
                    matchAsync.Should().BeEquivalentTo(match);
                }
            }
        }
Exemple #2
0
 public static MatchEvent ToDomain(this Entities.MatchEvent matchEvent) =>
 new MatchEvent(
     UserId.CreateUserId(matchEvent.UserId).IfNone(new UserId()),
     MatchId.CreateMatchId(matchEvent.MatchId).IfNone(new MatchId()),
     matchEvent.EventTime,
     (MatchEventType)matchEvent.MatchEventType
     );
Exemple #3
0
        public bool Equals(Match other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(GameMode == other.GameMode &&
                   IsMatchComplete == other.IsMatchComplete &&
                   string.Equals(MapId, other.MapId) &&
                   MatchDuration.Equals(other.MatchDuration) &&
                   MatchEndReason == other.MatchEndReason &&
                   MatchId.Equals(other.MatchId) &&
                   Equals(MatchStartDate, other.MatchStartDate) &&
                   MatchType == other.MatchType &&
                   Players.OrderBy(p => p.Key).SequenceEqual(other.Players.OrderBy(p => p.Key)) &&
                   PlaylistId.Equals(other.PlaylistId) &&
                   SeasonId.Equals(other.SeasonId) &&
                   Teams.OrderBy(t => t.Key).SequenceEqual(other.Teams.OrderBy(t => t.Key)) &&
                   VictoryCondition == other.VictoryCondition);
        }
        public async void TestGetAllEventsByUserId()
        {
            // Assemble
            var matchEvents = new List <MatchEvent>()
            {
                new MatchEvent(
                    UserId.CreateUserId(42).IfNone(new UserId()),
                    MatchId.CreateMatchId(22).IfNone(new MatchId()),
                    DateTime.Now.AddDays(-1),
                    MatchEventType.Conversion
                    ),
                new MatchEvent(
                    UserId.CreateUserId(42).IfNone(new UserId()),
                    MatchId.CreateMatchId(22).IfNone(new MatchId()),
                    DateTime.Now.AddDays(-1),
                    MatchEventType.Conversion
                    )
            };
            Either <IEnumerable <Error>, List <MatchEvent> > returnValue = Right(matchEvents);

            _matchEventRepository.Setup(m => m.GetAllMatchEventsByUserIdAsync(It.IsAny <UserId>(), It.IsAny <MatchId>())).Returns(Task.FromResult(returnValue));

            // Act
            var result = await _matchEventService.GetAllMatchEventsByUserIdAsync(42, 22);

            // Assert
            _matchEventRepository.Verify(w => w.GetAllMatchEventsByUserIdAsync(It.IsAny <UserId>(), It.IsAny <MatchId>()));
            result.Match(
                Left: (err) => Assert.False(true, "Expected no errors to be returned."),
                Right: (matchEvents) => Assert.Equal(2, matchEvents.Count)
                );
        }
Exemple #5
0
        public bool Equals(PlayerMatch other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Equals(ExperienceProgress, other.ExperienceProgress) &&
                   GameMode == other.GameMode &&
                   LeaderId == other.LeaderId &&
                   string.Equals(MapId, other.MapId) &&
                   MatchId.Equals(other.MatchId) &&
                   Equals(MatchStartDate, other.MatchStartDate) &&
                   MatchType == other.MatchType &&
                   PlayerCompletedMatch == other.PlayerCompletedMatch &&
                   PlayerIndex == other.PlayerIndex &&
                   PlayerMatchDuration.Equals(other.PlayerMatchDuration) &&
                   PlayerMatchOutcome == other.PlayerMatchOutcome &&
                   PlaylistId.Equals(other.PlaylistId) &&
                   Equals(RatingProgress, other.RatingProgress) &&
                   SeasonId.Equals(other.SeasonId) &&
                   TeamId == other.TeamId &&
                   TeamPlayerIndex == other.TeamPlayerIndex &&
                   Teams.OrderBy(t => t.Key).SequenceEqual(other.Teams.OrderBy(t => t.Key)));
        }
        public NetClientMatchController CreateClientMatchController(MatchId id, MatchOptions options)
        {
            var controller = new NetClientMatchController(id, options, this.Channels);

            this.MatchMap.Add(id.GUID, controller);

            return(controller);
        }
Exemple #7
0
        public static Phrase CreateNew(MatchId matchId, TeamId teamId, UserId createdByUserId, string description, bool positive)
        {
            var phrase = new Phrase(matchId, teamId, createdByUserId, description, positive);

            phrase.Upvote(createdByUserId);

            return(phrase);
        }
Exemple #8
0
        /// <summary>
        /// Returns true if Person instances are equal
        /// </summary>
        /// <param name="other">Instance of Person to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Person other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     FirstName == other.FirstName ||
                     FirstName != null &&
                     FirstName.Equals(other.FirstName)
                     ) &&
                 (
                     Surname == other.Surname ||
                     Surname != null &&
                     Surname.Equals(other.Surname)
                 ) &&
                 (
                     DateOfBirth == other.DateOfBirth ||
                     DateOfBirth != null &&
                     DateOfBirth.Equals(other.DateOfBirth)
                 ) &&
                 (
                     PersonGender == other.PersonGender ||

                     PersonGender.Equals(other.PersonGender)
                 ) &&
                 (
                     MatchId == other.MatchId ||
                     MatchId != null &&
                     MatchId.Equals(other.MatchId)
                 ) &&
                 (
                     AllocatePersonId == other.AllocatePersonId ||
                     AllocatePersonId != null &&
                     AllocatePersonId.Equals(other.AllocatePersonId)
                 ) &&
                 (
                     Email == other.Email ||
                     Email != null &&
                     Email.Equals(other.Email)
                 ) &&
                 (
                     TelephoneNumber == other.TelephoneNumber ||
                     TelephoneNumber != null &&
                     TelephoneNumber.Equals(other.TelephoneNumber)
                 ) &&
                 (
                     ExtSystemId == other.ExtSystemId ||
                     ExtSystemId != null &&
                     ExtSystemId.Equals(other.ExtSystemId)
                 ));
        }
 public MatchGeneralAttributesEditedDomainEvent(MatchId matchId, string newName, DateTime newUtcDate, Score newScore, string newSeason, string newStatus)
 {
     MatchId    = matchId;
     NewName    = newName;
     NewUtcDate = newUtcDate;
     NewScore   = newScore;
     NewSeason  = newSeason;
     NewStatus  = newStatus;
 }
Exemple #10
0
        public void Test_Compound_Type_Equality()
        {
            MatchId id = 3;

            MatchResult result = (id, 1, 2);

            Assert.Equal(new MatchResult(id, 1, 2), result);
            Assert.Equal(id, result.MatchId);
            Assert.Equal(1, result.HomeGoals);
            Assert.Equal(2, result.AwayGoals);
        }
Exemple #11
0
        public async Task <IActionResult> FindMatchAsync(MatchId matchId)
        {
            var match = await _matchQuery.FindMatchAsync(matchId);

            if (match == null)
            {
                return(this.NotFound("Match not found."));
            }

            return(this.Ok(_mapper.Map <ChallengeMatchDto>(match)));
        }
 public PhraseCreatedDomainEvent(PhraseId phraseId, MatchId matchId, TeamId teamId, UserId createdByUserId,
                                 string description, bool positive, DateTime utcDateCreated)
 {
     PhraseId        = phraseId;
     MatchId         = matchId;
     TeamId          = teamId;
     CreatedByUserId = createdByUserId;
     Description     = description;
     Positive        = positive;
     UtcDateCreated  = utcDateCreated;
 }
 public MatchCreatedDomainEvent(MatchId matchId, TeamId homeTeamId, TeamId awayTeamId, string externalId,
                                string name, Score score, string season, string status, DateTime utcDate)
 {
     MatchId    = matchId;
     HomeTeamId = homeTeamId;
     AwayTeamId = awayTeamId;
     ExternalId = externalId;
     Name       = name;
     Score      = score;
     Season     = season;
     Status     = status;
     UtcDate    = utcDate;
 }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Tick"/> class.
 /// </summary>
 /// <param name="symbol">The tick symbol.</param>
 /// <param name="price">The best quoted bid price.</param>
 /// <param name="size">The best quoted ask price.</param>
 /// <param name="maker">The tick bid size.</param>
 /// <param name="matchId">The tick ask size.</param>
 /// <param name="unixTimestamp">The unix timestamp in milliseconds.</param>
 public TradeTick(
     Symbol symbol,
     Price price,
     Quantity size,
     Maker maker,
     MatchId matchId,
     long unixTimestamp)
     : base(symbol, unixTimestamp)
 {
     this.Price   = price;
     this.Size    = size;
     this.Maker   = maker;
     this.MatchId = matchId;
 }
Exemple #15
0
        public void Test_Id_Int_Type_With_Implicit_Conversion()
        {
            MatchId id1 = 1;
            MatchId id2 = 2;
            MatchId id3 = id1 + id2;

            Assert.NotEqual(id1, id2);
            Assert.Equal((MatchId)3, id3);

            Assert.True(id1 < id2);
            Assert.True(id1 <= id2);
            Assert.False(id1 > id2);
            Assert.False(id1 >= id2);
        }
Exemple #16
0
        private Phrase(MatchId matchId, TeamId teamId, UserId createdByUserId, string description, bool positive)
        {
            Id                 = new PhraseId(Guid.NewGuid());
            _matchId           = matchId;
            _teamId            = teamId;
            _createdByUserId   = createdByUserId;
            _description       = description;
            _positive          = positive;
            _dateCreated       = DateTime.UtcNow;
            _score             = 0;
            _phraseVoteHistory = new List <PhraseVoteHistory>();

            AddDomainEvent(new PhraseCreatedDomainEvent(Id, matchId, teamId, createdByUserId, description, positive, _dateCreated));
        }
Exemple #17
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)GameMode;
         hashCode = (hashCode * 397) ^ IsDefaultRuleSet.GetHashCode();
         hashCode = (hashCode * 397) ^ (MapId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ MatchId.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)MatchType;
         hashCode = (hashCode * 397) ^ PlaylistId.GetHashCode();
         hashCode = (hashCode * 397) ^ TeamSize;
         return(hashCode);
     }
 }
Exemple #18
0
        public static IMatch ToEntity(this MatchModel model)
        {
            var match = new Match(
                model.GameUuid,
                new DateTimeProvider(model.GameStartedAt),
                TimeSpan.FromTicks(model.GameDuration),
                model.Stats.Select(stat => stat.ToEntity()),
                new DateTimeProvider(model.SynchronizedAt));

            match.SetEntityId(MatchId.FromGuid(model.Id));

            match.ClearDomainEvents();

            return(match);
        }
        async Task ReadMessage()
        {
            WebSocketReceiveResult result;
            var message = new ArraySegment <byte>(new byte[4096]);

            do
            {
                result = await _ws.ReceiveAsync(message, _cancelationTokenSource.Token);

                if (result.MessageType != WebSocketMessageType.Text)
                {
                    break;
                }
                var messageBytes = message.Skip(message.Offset).Take(result.Count).ToArray();
                var messageStr   = Encoding.UTF8.GetString(messageBytes);
                if (messageStr == "ping")
                {
                    await _ws.SendAsync(StringToByte("pong"), WebSocketMessageType.Text, true, _cancelationTokenSource.Token).ConfigureAwait(false);

                    continue;
                }
                if (messageStr == "pong")
                {
                    await _ws.SendAsync(StringToByte("ping"), WebSocketMessageType.Text, true, _cancelationTokenSource.Token).ConfigureAwait(false);

                    continue;
                }
                if (!MatchId.TryParse(messageStr, out MatchId matchId))
                {
                    continue;
                }
                try
                {
                    var match = await _client.GetMatchAsync(matchId, _deviceToSubscribe).ConfigureAwait(false);

                    MatchReceived?.Invoke(this, new MatchReceivedEventArgs(_deviceToSubscribe, MatchChannel.Websocket, new List <Match> {
                        match
                    }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }while (!result.EndOfMessage);
        }
Exemple #20
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MatchId.Length != 0)
            {
                hash ^= MatchId.GetHashCode();
            }
            if (Result != 0)
            {
                hash ^= Result.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (MatchId != 0L)
                    {
                        hash ^= MatchId.GetHashCode();
                    }
                    if (Spectator != false)
                    {
                        hash ^= Spectator.GetHashCode();
                    }
                    if (_unknownFields != null)
                    {
                        hash ^= _unknownFields.GetHashCode();
                    }
                    return(hash);
                }
Exemple #22
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (FirstName != null)
                {
                    hashCode = hashCode * 59 + FirstName.GetHashCode();
                }
                if (Surname != null)
                {
                    hashCode = hashCode * 59 + Surname.GetHashCode();
                }
                if (DateOfBirth != null)
                {
                    hashCode = hashCode * 59 + DateOfBirth.GetHashCode();
                }

                hashCode = hashCode * 59 + PersonGender.GetHashCode();
                if (MatchId != null)
                {
                    hashCode = hashCode * 59 + MatchId.GetHashCode();
                }
                if (AllocatePersonId != null)
                {
                    hashCode = hashCode * 59 + AllocatePersonId.GetHashCode();
                }
                if (Email != null)
                {
                    hashCode = hashCode * 59 + Email.GetHashCode();
                }
                if (TelephoneNumber != null)
                {
                    hashCode = hashCode * 59 + TelephoneNumber.GetHashCode();
                }
                if (ExtSystemId != null)
                {
                    hashCode = hashCode * 59 + ExtSystemId.GetHashCode();
                }
                return(hashCode);
            }
        }
        public void ThirdPartyMatchProvider()
        {
            Assume.That(match != null, "Match is prepared");
            var matchProviderMonitor = _instance.SubscribeMatchesWithThirdParty();

            MatchReceivedEventArgs matchReceivedEvent = null;

            _instance.MatchReceived += (sender, e) => matchReceivedEvent = e;

            RunSync(() => matchProviderMonitor.ProvideMatchIdAsync(MatchId.Make(match.Id)));

            while (matchReceivedEvent == null)
            {
            }

            Assert.AreEqual(MatchChannel.ThirdParty, matchReceivedEvent.Channel);
            var receivedMatch = matchReceivedEvent.Matches.FirstOrDefault(m => m.Id == match.Id);

            Assert.NotNull(receivedMatch);
        }
Exemple #24
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (int)GameMode;
         hashCode = (hashCode * 397) ^ IsMatchComplete.GetHashCode();
         hashCode = (hashCode * 397) ^ (MapId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ MatchDuration.GetHashCode();
         hashCode = (hashCode * 397) ^ MatchEndReason.GetHashCode();
         hashCode = (hashCode * 397) ^ MatchId.GetHashCode();
         hashCode = (hashCode * 397) ^ (MatchStartDate != null ? MatchStartDate.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)MatchType;
         hashCode = (hashCode * 397) ^ (Players?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ PlaylistId.GetHashCode();
         hashCode = (hashCode * 397) ^ SeasonId.GetHashCode();
         hashCode = (hashCode * 397) ^ (Teams?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ VictoryCondition.GetHashCode();
         return(hashCode);
     }
 }
Exemple #25
0
        public ReplayLogger()
        {
            if (!Directory.Exists(Settings.Default.ReplaysFolder))
            {
                Directory.CreateDirectory(Settings.Default.ReplaysFolder);
            }

            var replays = Directory.GetDirectories(Settings.Default.ReplaysFolder);

            MatchId = 1;
            if (replays.Length > 0)
            {
                Array.Sort(replays);
                var lastReplayName = replays[replays.Length - 1].Split(Path.DirectorySeparatorChar)[1];
                MatchId = Int16.Parse(lastReplayName) + 1;
            }

            ReplayDirectory = Settings.Default.ReplaysFolder + Path.DirectorySeparatorChar +
                              MatchId.ToString("D4");
            Directory.CreateDirectory(ReplayDirectory);
        }
Exemple #26
0
        public bool Equals(MatchStart other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(base.Equals(other) &&
                   GameMode == other.GameMode &&
                   IsDefaultRuleSet == other.IsDefaultRuleSet &&
                   string.Equals(MapId, other.MapId) &&
                   MatchId.Equals(other.MatchId) &&
                   MatchType == other.MatchType &&
                   PlaylistId.Equals(other.PlaylistId) &&
                   TeamSize == other.TeamSize);
        }
Exemple #27
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ExperienceProgress != null ? ExperienceProgress.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)GameMode;
         hashCode = (hashCode * 397) ^ LeaderId;
         hashCode = (hashCode * 397) ^ (MapId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ MatchId.GetHashCode();
         hashCode = (hashCode * 397) ^ (MatchStartDate != null ? MatchStartDate.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)MatchType;
         hashCode = (hashCode * 397) ^ PlayerCompletedMatch.GetHashCode();
         hashCode = (hashCode * 397) ^ PlayerIndex;
         hashCode = (hashCode * 397) ^ PlayerMatchDuration.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)PlayerMatchOutcome;
         hashCode = (hashCode * 397) ^ PlaylistId.GetHashCode();
         hashCode = (hashCode * 397) ^ (RatingProgress != null ? RatingProgress.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ SeasonId.GetHashCode();
         hashCode = (hashCode * 397) ^ TeamId;
         hashCode = (hashCode * 397) ^ TeamPlayerIndex;
         hashCode = (hashCode * 397) ^ (Teams?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
 public async Task <Match> GetAsync(MatchId id)
 {
     return(await _context.Matches.SingleOrDefaultAsync(x => x.Id == id));
 }
Exemple #29
0
 => Apply(new MatchCreated(MatchId, name));
Exemple #30
0
 protected override int GetHashCodeCore()
 {
     return(MatchId.GetHashCode());
 }