Beispiel #1
0
        public void HandleCreate_WithExistingItems_HasCorrectId(int numberOfExistingHeroes)
        {
            // Arrange.
            var payload = "Tornado";
            var action  = new HeroesState.CreateAction(payload);
            var heroes  = new List <Hero>();

            for (int i = 0; i <= numberOfExistingHeroes; i++)
            {
                heroes.Add(new Hero
                {
                    Id = i
                });
            }

            var keyValuePairs = new Dictionary <string, object>
            {
                { "Heroes", heroes }
            };

            _heroesState.Hydrate(keyValuePairs);

            // Should be one higher than the number of Heroes already in the state.
            var expected = numberOfExistingHeroes + 1;

            // Act.
            _handleCreate.Handle(action, new CancellationToken());
            var tornado = _heroesState.Heroes.Single(hero => hero.Name == payload);

            // Assert.
            Assert.Equal(expected, tornado.Id);
        }
        public void CreateAction_ValidPayload_SetsPayload(string expectedPayload)
        {
            // Given a well formed action.
            var actualPayload = new HeroesState.CreateAction(expectedPayload).Name;

            // It should be instanciated with the given payload.
            Assert.Equal(expectedPayload, actualPayload);
        }
Beispiel #3
0
        public void HandleCreate_ValidAction_UpdatesState(string payload)
        {
            // Arrange.
            var action = new HeroesState.CreateAction(payload);

            // Act.
            _handleCreate.Handle(action, new CancellationToken());

            // Assert.
            Assert.Equal(payload, _heroesState.Heroes.Single().Name);
        }