コード例 #1
0
ファイル: Playroom.cs プロジェクト: Marebor/DXGame
        public static Playroom Create(CreatePlayroom command) 
        {
            var playroom = new Playroom();
            playroom.ApplyEvent(
                new PlayroomCreationRequested(
                    command.PlayroomId, 
                    command.Name,
                    command.IsPrivate,
                    command.Owner,
                    command.Password,
                    playroom.Version,
                    command.CommandId
                )
            );

            return playroom;
        }
コード例 #2
0
ファイル: PlayroomTests.cs プロジェクト: Marebor/DXGame
        public void Can_Retrieve_Aggregate_Changes()
        {
            var command = new CreatePlayroom(
                Guid.NewGuid(),
                Guid.NewGuid(),
                "Test",
                Guid.NewGuid(),
                false,
                "secret"
                );
            var playroom = Domain.Models.Playroom.Create(command);

            playroom.MarkRecentlyAppliedEventsAsConfirmed();

            playroom.ChangePassword(new ChangePassword(Guid.NewGuid(), playroom.Id, "secret", "secret1", playroom.Owner));
            playroom.ChangePassword(new ChangePassword(Guid.NewGuid(), playroom.Id, "secret1", "secret2", playroom.Owner));
            playroom.NewGame(new StartGame(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), playroom.Players.First()));

            Assert.AreEqual(3, playroom.RecentlyAppliedEvents.Count());
            Assert.AreEqual(typeof(PlayerJoined), playroom.RecentlyAppliedEvents.First().GetType());
            Assert.AreEqual(typeof(GameStartRequested), playroom.RecentlyAppliedEvents.Last().GetType());
        }
コード例 #3
0
 public async Task <IActionResult> Post([FromBody] string name)
 => await _actionResultHelper
 .Return(async() =>
 {
     _logger.LogWarning($"Executing test Post action with argument: {name}");
     var command = new CreatePlayroom(
         Guid.NewGuid(), Guid.NewGuid(), name, Guid.NewGuid(), false, "secret"
         );
     _logger.LogWarning("Attempting to send command...");
     await _messageBus.PublishAsync(command);
     _logger.LogWarning("Message published.");
     await _projectionRepository.SaveAsync(new PlayroomProjection {
         Name = name
     });
     _logger.LogWarning("Playroom projection saved.");
     return(Accepted());
 })
 .OnError(ex =>
 {
     _logger.LogError(ex, ex.Message);
     return(ServiceUnavailable());
 })
 .DoNotPropagateException()
 .ExecuteAsync();
コード例 #4
0
 public async Task <IActionResult> Post([FromBody] CreatePlayroom command)
 => await ProcessCommand(command);