public async Task Returns_MoreGendersThanMaleAndFemaleIfOwnerIdentifiedAsAnotherGender()
        {
            //Arrange
            _maleOwner1.Pets = new List <PetDto> {
                _cat1
            };
            _femaleOwner1.Pets = new List <PetDto> {
                _cat2
            };
            _transgenderOwner1.Pets = new List <PetDto> {
                _cat3
            };
            _owners = new List <PersonDto> {
                _maleOwner1, _femaleOwner1, _transgenderOwner1
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Returns(Task.FromResult <IEnumerable <PersonDto> >(_owners));

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act
            var catOwnersViewModel = await catsReadService.GetCatOwnersViewModel();

            //Assert
            Assert.AreEqual(catOwnersViewModel.CatsByGender.Count(), 3);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList().Select(g => g.OwnerGender).Contains(_maleOwner1.Gender), true);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList().Select(g => g.OwnerGender).Contains(_femaleOwner1.Gender), true);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList().Select(g => g.OwnerGender).Contains(_transgenderOwner1.Gender), true);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.Count(), 1);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.Count(), 1);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.Count(), 1);
            //TODO I've just used AreEqual everywhere... which does what I need... just wondering if I should be using
            //different terms for perhaps clarity or perhaps something like Shouldy or Fluent Assertions? (I believe some
            //people think they make it more readable/understandable).
        }
        public async Task Returns_GendersRelatedToPetCatOwnersOnly()
        {
            //Arrange
            _maleOwner1.Pets = new List <PetDto> {
                _cat1
            };
            _femaleOwner1.Pets = new List <PetDto> {
                _dog2
            };
            _owners = new List <PersonDto> {
                _maleOwner1, _femaleOwner1
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Returns(Task.FromResult <IEnumerable <PersonDto> >(_owners));

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act
            var catOwnersViewModel = await catsReadService.GetCatOwnersViewModel();

            //Assert
            Assert.AreEqual(catOwnersViewModel.CatsByGender.Count(), 1);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].OwnerGender, _maleOwner1.Gender);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.Count(), 1);
        }
        public async Task Returns_EmptyModelIfThereAreNoOwners()
        {
            //Arrange
            _owners = new List <PersonDto> {
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Returns(Task.FromResult <IEnumerable <PersonDto> >(_owners));

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act
            var catOwnersViewModel = await catsReadService.GetCatOwnersViewModel();

            //Assert
            Assert.AreEqual(catOwnersViewModel.CatsByGender.Count(), 0);
        }
        public void ThrowsException_WhenCannotCallPeopleApi()
        {
            //Arrange
            _owners = new List <PersonDto> {
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Throws(new System.Exception());

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act and Assert
            //TODO Ok, so this works, I may not fully understand it though... it basically just
            //checks for any exception regardless of type - not sure if there is a better way to do
            //it or if this should be separated into a delegate somehow for the Act part, and the
            //delegate used in the Assert?
            Assert.CatchAsync(async() => await catsReadService.GetCatOwnersViewModel());
        }
        public async Task Returns_GendersAndPetNamesInAlphabeticOrder()
        {
            //Arrange
            _maleOwner1.Pets = new List <PetDto> {
                _cat6
            };
            _maleOwner2.Pets = new List <PetDto> {
                _cat3
            };
            _femaleOwner1.Pets = new List <PetDto> {
                _cat1, _cat4
            };
            _femaleOwner2.Pets = new List <PetDto> {
                _cat5
            };
            _transgenderOwner1.Pets = new List <PetDto> {
                _cat2
            };
            _owners = new List <PersonDto> {
                _maleOwner1, _maleOwner2, _transgenderOwner1, _femaleOwner1, _femaleOwner2
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Returns(Task.FromResult <IEnumerable <PersonDto> >(_owners));

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act
            var catOwnersViewModel = await catsReadService.GetCatOwnersViewModel();

            //Assert
            //...Genders are sorted alphabetically
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].OwnerGender, "Female");
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[1].OwnerGender, "Male");
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[2].OwnerGender, "Transgender");

            //...Cat names for Female owners sorted alphabetically
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.ToList()[0], "Cat1");
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.ToList()[1], "Cat4");
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.ToList()[2], "Cat5");

            //...Cat names for Male owners sorted alphabetically
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[1].CatNames.ToList()[0], "Cat3");
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[1].CatNames.ToList()[1], "Cat6");
        }
        public async Task Returns_MoreThanOneCatNameIfAOwnerHasMoreThanOneCat()
        {
            //Arrange
            _maleOwner1.Pets = new List <PetDto> {
                _cat1, _cat2, _cat3
            };
            _owners = new List <PersonDto> {
                _maleOwner1
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Returns(Task.FromResult <IEnumerable <PersonDto> >(_owners));

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act
            var catOwnersViewModel = await catsReadService.GetCatOwnersViewModel();

            //Assert
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList()[0].CatNames.Count(), 3);
        }
        public async Task Returns_WithoutThrowingExceptionWhenOnePersonHasNoPets()
        {
            //Arrange
            _maleOwner1.Pets = new List <PetDto> {
                _cat1
            };
            _owners = new List <PersonDto> {
                _maleOwner1, _femaleOwner1
            };

            _mockPeopleService.Setup(s => s.GetPeople()).Returns(Task.FromResult <IEnumerable <PersonDto> >(_owners));

            var catsReadService = new CatsReadService(_mockPeopleService.Object);

            //Act
            var catOwnersViewModel = await catsReadService.GetCatOwnersViewModel();

            //Assert
            Assert.AreEqual(catOwnersViewModel.CatsByGender.Count(), 1);
            Assert.AreEqual(catOwnersViewModel.CatsByGender.ToList().Select(g => g.OwnerGender).Contains(_maleOwner1.Gender), true);
        }