예제 #1
0
        public void QueryingCollectionHandler_ReturnsAllCharactersFromFacade()
        {
            var facade     = new CharactersFacade();
            var characters = facade.Query();

            Assert.NotNull(characters);
            Assert.NotEmpty(characters);
            var handler = new CharactersQueryHandler(facade);
            var result  = handler.Handle(new CharactersQuery(), new CancellationToken()).GetAwaiter().GetResult();

            Assert.NotNull(result);
            Assert.NotNull(result.Data);
            Assert.True(result.IsSuccessful);
            Assert.Equal(characters.Count, result.Data.Count);
        }
예제 #2
0
        public void SubsequentQueryReturnsTheSameValues()
        {
            var facade       = new CharactersFacade();
            var characterIds = facade.Query().Select(x => x.Id).ToList();

            Assert.NotNull(characterIds);
            Assert.NotEmpty(characterIds);
            var handler = new CharacterQueryHandler(facade);

            foreach (var id in characterIds)
            {
                var result1 = handler.Handle(new CharacterQuery(id), new CancellationToken()).GetAwaiter().GetResult();
                var result2 = handler.Handle(new CharacterQuery(id), new CancellationToken()).GetAwaiter().GetResult();
                Assert.NotSame(result1, result2);
                Assert.True(result1.IsSuccessful);
                Assert.True(result2.IsSuccessful);

                Assert.Equal(result1.Data.Id, result2.Data.Id);
                Assert.Equal(result1.Data.Name, result2.Data.Name);
                Assert.Equal(result1.Data.Episodes.Count, result2.Data.Episodes.Count);
                Assert.Equal(result1.Data.Friends.Count, result2.Data.Friends.Count);

                var res1episodes = result1.Data.Episodes.OrderBy(x => x.Value).ToList();
                var res2episodes = result2.Data.Episodes.OrderBy(x => x.Value).ToList();
                for (int i = 0; i < res1episodes.Count; i++)
                {
                    Assert.Equal(res1episodes[i], res2episodes[i]);
                }

                var res1friends = result1.Data.Friends.OrderBy(x => x.Id).ToList();
                var res2friends = result2.Data.Friends.OrderBy(x => x.Id).ToList();
                for (int i = 0; i < res1friends.Count; i++)
                {
                    Assert.Equal(res1friends[i].Id, res2friends[i].Id);
                    Assert.Equal(res1friends[i].Name, res2friends[i].Name);
                }
            }
        }
예제 #3
0
        public void QueryingSingleHandler_ReturnsSpecificCharacterFromFacade()
        {
            var facade       = new CharactersFacade();
            var characterIds = facade.Query().Select(x => x.Id).ToList();

            Assert.NotNull(characterIds);
            Assert.NotEmpty(characterIds);
            var handler = new CharacterQueryHandler(facade);
            var results = new List <CharacterQueryResponse>();

            foreach (var id in characterIds)
            {
                results.Add(handler.Handle(new CharacterQuery(id), new CancellationToken()).GetAwaiter().GetResult());
            }

            Assert.NotNull(results);
            Assert.NotEmpty(results);
            foreach (var result in results)
            {
                Assert.True(result.IsSuccessful);
                Assert.Contains(result.Id, characterIds);
            }
        }