Пример #1
0
        public void OnlyMoveOneSquareAway()
        {
            _eventStore = new MockInMemoryEventStore();
            _ut         = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var herbivores = new List <Herbivore>()
            {
                new Herbivore(10, 10, "h1")
            };

            _ut.CreateNewGame(20, herbivores, new List <Carnivore> ());

            _ut.Bump();

            var @event = _eventStore.Events.Values.First().Last();

            Assert.Equal(typeof(HerbivoreMoved).Name, @event.GetType().Name);

            var movedEvent = (HerbivoreMoved)@event;

            Assert.Equal(10, movedEvent.OldPosition.X);
            Assert.Equal(10, movedEvent.OldPosition.Y);

            Assert.True(movedEvent.NewPosition.X >= 9);
            Assert.True(movedEvent.NewPosition.X <= 11);

            Assert.True(movedEvent.NewPosition.Y >= 9);
            Assert.True(movedEvent.NewPosition.Y <= 11);

            Assert.False(movedEvent.OldPosition.X == movedEvent.NewPosition.X && movedEvent.OldPosition.Y == movedEvent.NewPosition.Y);
        }
Пример #2
0
        public void CarnivoresMoveApartFromEachOther()
        {
            _eventStore = new MockInMemoryEventStore();

            const string c1 = "c1";
            const string c2 = "C2";

            _ut = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var createCarnivore = new List <Carnivore>
            {
                new Carnivore(10, 10, c1, 10),
                new Carnivore(10, 9, c2, 10)
            };

            _ut.CreateNewGame(20, new List <Herbivore>(), createCarnivore);

            _ut.Bump();

            var events         = _eventStore.Events.Values.First();
            var last2Events    = events.Skip(events.Count - 2).ToList();
            var last           = last2Events.Last();
            var secondFromLast = last2Events.First();

            Assert.Equal(typeof(CarnivoreMoved).Name, last.GetType().Name);
            Assert.Equal(typeof(CarnivoreMoved).Name, secondFromLast.GetType().Name);

            var e = (CarnivoreMoved)secondFromLast;

            Assert.Equal(10, e.NewPosition.X);
            Assert.Equal(11, e.NewPosition.Y);
        }
Пример #3
0
        public void EatHerbivoreIfNextToIt()
        {
            _eventStore = new MockInMemoryEventStore();
            var carnivoreId = "c1";
            var herbivoreId = "h1";

            _ut = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var createCarnivore = new List <Carnivore> {
                new Carnivore(10, 10, carnivoreId, 10)
            };
            var createHerbivore = new List <Herbivore> {
                new Herbivore(10, 9, herbivoreId)
            };

            _ut.CreateNewGame(20, createHerbivore, createCarnivore);

            _ut.Bump();

            var @event = _eventStore.Events.Values.First().Last();

            Assert.Equal(typeof(CarnivoreAteHerbivore).Name, @event.GetType().Name);
            var carnivoreAteHerbivore = (CarnivoreAteHerbivore)@event;

            Assert.Equal(carnivoreId, carnivoreAteHerbivore.CarnivoreId);

            Assert.Equal(Surface.CellType.Default,
                         _ut.Cells[carnivoreAteHerbivore.OldPosition.X, carnivoreAteHerbivore.OldPosition.Y]);
            Assert.Equal(Surface.CellType.Carnivore,
                         _ut.Cells[carnivoreAteHerbivore.NewPosition.X, carnivoreAteHerbivore.NewPosition.Y]);
        }
Пример #4
0
        public void WillDieAfter10Moves()
        {
            _eventStore = new MockInMemoryEventStore();
            _ut         = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var createCarnivores = new List <Carnivore> {
                new Carnivore(10, 10, "c1", 10)
            };

            _ut.CreateNewGame(20, new List <Herbivore>(), createCarnivores);

            for (int i = 0; i < 11; i++)
            {
                _ut.Bump();
            }

            var @event = _eventStore.Events.Values.First().Last();

            Assert.Equal(typeof(CarnivoreDied).Name, @event.GetType().Name);
        }
Пример #5
0
        public CreateSurvivalGameWill()
        {
            _eventStore = new MockInMemoryEventStore();
            _ut         = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var createHerbivores = new List <Herbivore>();

            for (int i = 1; i <= 10; i++)
            {
                createHerbivores.Add(new Herbivore(0, i, "h" + i));
            }

            var createCarnivores = new List <Carnivore>();

            for (int i = 1; i <= 10; i++)
            {
                createCarnivores.Add(new Carnivore(19, i, "c" + i, 10));
            }

            _ut.CreateNewGame(20, createHerbivores, createCarnivores);
        }
Пример #6
0
        public void WillNotDieAfter10MovesIfManagesToEat()
        {
            _eventStore = new MockInMemoryEventStore();
            _ut         = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var createCarnivores = new List <Carnivore> {
                new Carnivore(0, 0, "c1", 10)
            };
            var herbivores = new List <Herbivore>()
            {
                new Herbivore(2, 2, "h1")
            };

            _ut.CreateNewGame(3, herbivores, createCarnivores);

            for (int i = 0; i < 11; i++)
            {
                _ut.Bump();
            }

            var events = _eventStore.Events.Values.First();

            Assert.False(events.Any(e => e.GetType() == typeof(CarnivoreDied)));
        }
Пример #7
0
        public void AdjacentHerbivoresLayEggs()
        {
            _eventStore = new MockInMemoryEventStore();
            _ut         = new SurvivalGame(nameof(CreateSurvivalGameWill), new Random(), _eventStore);
            var herbivores = new List <Herbivore>()
            {
                new Herbivore(10, 10, "h1"),
                new Herbivore(10, 11, "h2")
            };

            _ut.CreateNewGame(20, herbivores, new List <Carnivore>());

            _ut.Bump();

            var eventStream             = _eventStore.Events.Values.First();
            var herbivoreLaidEggsEvents = eventStream.Where(e => e.GetType().Name == typeof(HerbivoreLaidEgg).Name).ToList();

            Assert.True(herbivoreLaidEggsEvents.Any());

            var laidEggEvent = (HerbivoreLaidEgg)herbivoreLaidEggsEvents.First();

            Assert.Equal(10, laidEggEvent.X);
            Assert.Equal(10, laidEggEvent.Y);


            //var movedEvent = (HerbivoreMoved)@event;
            //Assert.Equal(10, movedEvent.OldPosition.X);
            //Assert.Equal(10, movedEvent.OldPosition.Y);

            //Assert.True(movedEvent.NewPosition.X >= 9);
            //Assert.True(movedEvent.NewPosition.X <= 11);

            //Assert.True(movedEvent.NewPosition.Y >= 9);
            //Assert.True(movedEvent.NewPosition.Y <= 11);

            //Assert.False(movedEvent.OldPosition.X == movedEvent.NewPosition.X && movedEvent.OldPosition.Y == movedEvent.NewPosition.Y);
        }