예제 #1
0
        public async Task <PetNameViewModel> GetPetNameViewModel(PetType petType)
        {
            List <Person> personData = await _repository.GetPeopleData();

            PetNameViewModel viewModel = new PetNameViewModel()
            {
                MaleOwnerPetNames   = FilterAndSortData(personData, Gender.Male, petType),
                FemaleOwnerPetNames = FilterAndSortData(personData, Gender.Female, petType)
            };

            return(viewModel);
        }
예제 #2
0
        public async Task Service_Should_Return_ViewModel()
        {
            // Arrange
            Mock <IRepository> mockRepository = new Mock <IRepository>();

            mockRepository.Setup(x => x.GetPeopleData()).Returns(async() => { await Task.Yield(); return(_personData); });

            // Act
            IService         service   = new Service(mockRepository.Object);
            PetNameViewModel viewModel = await service.GetPetNameViewModel(PetType.Cat);

            // Assert
            // using of multiple asserts as they are testing the same thing (If the first assert fails, it means the second would fail too)
            Assert.IsNotNull(viewModel);
            Assert.IsNotNull(viewModel.FemaleOwnerPetNames);
            Assert.IsNotNull(viewModel.MaleOwnerPetNames);
        }
예제 #3
0
        public async Task Service_Returned_ViewModel_Not_Only_Has_Cat_Names()
        {
            // Arrange
            Mock <IRepository> mockRepository = new Mock <IRepository>();

            mockRepository.Setup(x => x.GetPeopleData()).Returns(async() => { await Task.Yield(); return(_personData); });
            PetNameViewModel expectedViewModel = new PetNameViewModel()
            {
                FemaleOwnerPetNames = _femaleOwnerPetNames,
                MaleOwnerPetNames   = _maleOwnerPetNames
            };

            // Act
            IService         service         = new Service(mockRepository.Object);
            PetNameViewModel actualViewModel = await service.GetPetNameViewModel(PetType.Cat);

            // Assert
            CollectionAssert.AreNotEquivalent(expectedViewModel.FemaleOwnerPetNames, actualViewModel.FemaleOwnerPetNames);
            CollectionAssert.AreNotEquivalent(expectedViewModel.MaleOwnerPetNames, actualViewModel.MaleOwnerPetNames);
        }
예제 #4
0
        public void Initialize()
        {
            _petNameViewModel = new PetNameViewModel()
            {
                FemaleOwnerPetNames = new List <string>()
                {
                    "Simba", "Nemo", "Jim"
                },
                MaleOwnerPetNames = new List <string>()
                {
                    "Garfield", "Fido", "Tom"
                }
            };

            _petCatNameViewModel = new PetNameViewModel()
            {
                FemaleOwnerPetNames = new List <string>()
                {
                    "Simba", "Jim"
                },
                MaleOwnerPetNames = new List <string>()
                {
                    "Garfield", "Tom"
                }
            };

            _petCatNameSortedViewModel = new PetNameViewModel()
            {
                FemaleOwnerPetNames = new List <string>()
                {
                    "Jim", "Simba"
                },
                MaleOwnerPetNames = new List <string>()
                {
                    "Garfield", "Tom"
                }
            };
        }
예제 #5
0
        public async Task Controller_Returned_ViewResult_With_Model_Having_Not_Only_Cat_Names()
        {
            // Arrange
            Mock <IService> mockService = new Mock <IService>();

            mockService.Setup(x => x.GetPetNameViewModel(PetType.Cat))
            .Returns(async() =>
            {
                await Task.Yield();
                return(_petCatNameViewModel);
            });
            PetNameViewModel expectedViewModel = _petNameViewModel;

            // Act
            HomeController controller = new HomeController(mockService.Object);
            ViewResult     result     = await controller.Index() as ViewResult;

            PetNameViewModel actualViewModel = result.ViewData.Model as PetNameViewModel;

            // Assert
            CollectionAssert.AreNotEquivalent(expectedViewModel.FemaleOwnerPetNames, actualViewModel.FemaleOwnerPetNames);
            CollectionAssert.AreNotEquivalent(expectedViewModel.MaleOwnerPetNames, actualViewModel.MaleOwnerPetNames);
        }
예제 #6
0
        public async Task <ActionResult> Index()
        {
            PetNameViewModel viewModel = await _service.GetPetNameViewModel(PetType.Cat);

            return(View("Index", viewModel));
        }