public async Task Initialize(Dictionary <int, int> truth, CancellationToken cancellationToken)
        {
            _store.Clear();

            foreach (var(round, correctDoor) in truth)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var dto = new RoundInfoDto
                {
                    CorrectDoor = correctDoor
                };

                _store.AddOrUpdate(round, _ => dto, (_, __) => dto);
            }
        }
        public async void FailToOpenDoorInRoundThatHasAlreadyBeenPlayed()
        {
            var playedRounds = new List <int>();

            var repositoryMock = new Mock <IGameRepository>();

            repositoryMock.Setup(mock => mock.GetRoundInfo(It.Is <int>(m => m == 1), It.IsAny <CancellationToken>()))
            .Returns((int r, CancellationToken _) =>
            {
                var result = new RoundInfoDto
                {
                    CorrectDoor = 1,
                    GuessedDoor = 2,
                    OpenedDoor  = playedRounds.Contains(r) ? 1 : null
                };

                playedRounds.Add(r);
                return(Task.FromResult(result));
            });
            repositoryMock.Setup(mock => mock.SaveRoundInfo(It.IsAny <int>(), It.IsAny <RoundInfoDto>(), It.IsAny <CancellationToken>()))
            .Returns((int r, RoundInfoDto _, CancellationToken __) =>
            {
                playedRounds.Add(r);
                return(Task.CompletedTask);
            });
            repositoryMock.Setup(mock => mock.GetSummary(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SummaryDto
            {
                CompletedRounds = 0,
                FailedRounds    = 0,
                TotalRounds     = int.MaxValue
            }));

            var randomizerMock = new Mock <IRandomizer>();

            var target = new GameEngine(repositoryMock.Object, randomizerMock.Object);

            var round = 1;
            var door  = 1;

            await target.OpenDoor(round, door, CancellationToken.None);

            await Assert.ThrowsAsync <ValidationException>(() => target.OpenDoor(round, door, CancellationToken.None));
        }
 public Task SaveRoundInfo(int round, RoundInfoDto dto, CancellationToken cancellationToken)
 {
     _store.AddOrUpdate(round, _ => dto, (_, __) => dto);
     return(Task.CompletedTask);
 }