예제 #1
0
        private static async void Run(IConfigurationRoot configuration)
        {
            var reelsPath      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration.GetSection("reelsPath").Value);
            var scoresPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration.GetSection("scoresPath").Value);
            var wordsPath      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration.GetSection("wordsPath").Value);
            var gameRepository = new FileGameDataSource(reelsPath, scoresPath, wordsPath);

            var eventDomainDispatcher = new EventDomainDispatcher();

            eventDomainDispatcher.Add <OnUserStartedGame, ConsoleOnUserStartedGame>(new ConsoleOnUserStartedGame());
            eventDomainDispatcher.Add <OnUserFinishedPlay, ConsoleOnUserFinishedPlay>(new ConsoleOnUserFinishedPlay());
            eventDomainDispatcher.Add <OnUserStartedNextPlay, ConsoleOnUserStartedNextPlay>(new ConsoleOnUserStartedNextPlay());

            var trieFactory = new TrieWorldImplementationFactory();

            var game = await new DefaultGameFactory(gameRepository, trieFactory, eventDomainDispatcher).Create();

            game.Init();

            while (game.IsPlaying)
            {
                var input = Console.ReadLine();
                game.Play(input);
            }
        }
예제 #2
0
        public void CallsRegisteredEvent()
        {
            var eventDispatcher = new EventDomainDispatcher();

            var implementationOneEventOne = Substitute.For <ImplementationOneEventOne>();

            eventDispatcher.Add <EventOne, ImplementationOneEventOne>(implementationOneEventOne);

            eventDispatcher.Send(new EventOne());

            implementationOneEventOne.Received(1).Execute(Arg.Any <EventOne>());
        }
예제 #3
0
        public void CallsSameInstanceRegistrations()
        {
            var eventDispatcher = new EventDomainDispatcher();

            var instanceOne = Substitute.For <ImplementationOneEventOne>();
            var instanceTwo = Substitute.For <ImplementationOneEventOne>();

            eventDispatcher.Add <EventOne, ImplementationOneEventOne>(instanceOne);
            eventDispatcher.Add <EventOne, ImplementationOneEventOne>(instanceTwo);

            eventDispatcher.Send(new EventOne());

            instanceOne.Received(1).Execute(Arg.Any <EventOne>());
            instanceTwo.Received(1).Execute(Arg.Any <EventOne>());
        }
예제 #4
0
        public void ThrowsWhenEventsHaveNoRegistrations()
        {
            var eventDispatcher = new EventDomainDispatcher();

            Assert.Throws <Exception>(() => eventDispatcher.Send(new EventOne()));
        }