Example #1
0
        public CompositionRoot(IDomainEventChannelFactory domainEventChannelFactory,
                               IGameBuilder gameBuilder,
                               IUICommandChannelFactory commandChannelFactory,
                               IGameViewFactory gameViewFactory)
        {
            this.GameId = Guid.NewGuid();


            this.domainEventChannel = MaybeConvertions.ToMaybe(domainEventChannelFactory.Create());

            // Application
            gameService = new GameService(this.domainEventChannel,
                                          new GameInMemoryRepository(),
                                          gameBuilder);

            gameService.GenerateNewGame(this.GameId);


            // View
            this.uiCommandChannel = commandChannelFactory.Create();
            this.gameView         = gameViewFactory.Create(this.uiCommandChannel);

            // Handlers
            this.fromUICommandsToDomainHandler =
                new FromUICommandsToDomainHandler(this.uiCommandChannel, this.gameService, this.GameId);

            this.fromDomainEventsToViewHandler =
                new FromDomainEventsToViewHandler(this.domainEventChannel, this.gameView);
        }
Example #2
0
        public void Given_AGame_With_null_Value()
        {
            // Arrange
            var moqDomainEventChannel = MaybeConvertions.ToMaybe(Substitute.For <IDomainEventChannel>());
            var gameBuilder           = new GameBuilder();
            var sut = gameBuilder.WithPlayer1(null).WithPlayer2(null).Create(moqDomainEventChannel);

            // Act
            sut.Start();

            // Assert
            moqDomainEventChannel.Value.Received().Submit <CurrentPlayerChanged>(
                new CurrentPlayerChanged(
                    new GameDto("012345678", "Player1")));
        }
Example #3
0
        public void Given_NewGame_With_Player1_When_Game_Starts_Then_Initialization_CurrentPlayerChanged_Event_Is_Sent()
        {
            // Arrange
            var moqDomainEventChannel = MaybeConvertions.ToMaybe(Substitute.For <IDomainEventChannel>());
            var gameBuilder           = new GameBuilder();
            var sut = gameBuilder.WithPlayer1("Player1").WithPlayer2("dummy").Create(moqDomainEventChannel);

            // Act
            sut.Start();

            // Assert
            moqDomainEventChannel.Value.Received().Submit <GameStarted>(
                new GameStarted(
                    new GameDto("012345678", "Player1")));
        }