Ejemplo n.º 1
0
        public void Index()
        {
            var dogOwnerViewModelMapper = new Mock <IDogOwnerViewModelMapper>();
            var dogOwner = new DogOwner()
            {
                OwnerName = "Qwe", DogNameList = new List <string> {
                    "q", "w", "e"
                }
            };
            var dogOwners = new List <DogOwner> {
                dogOwner
            };
            var dogOwnerListViewModel = new DogOwnerListViewModel {
                DogOwnerViewModels = dogOwners.Select(e => new DogOwnerViewModel {
                    OwnerName = e.OwnerName,
                    DogNames  = e.DogNameList
                }).ToList()
            };

            dogOwnerViewModelMapper.Setup(x => x.GetAllDogOwners()).Returns(dogOwnerListViewModel);
            //Arrange
            RobsDogsController controller = new RobsDogsController(dogOwnerViewModelMapper.Object);

            //Act
            ViewResult result = controller.Index() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(dogOwnerListViewModel, result.Model);
            //Should be testing / verifying call to GetAllDogOwners and subsequent methods down the stack.
            //Moq is installed to help you.
        }
Ejemplo n.º 2
0
        public DogOwnerListViewModel GetAllDogOwners()
        {
            var dogOwners             = dogOwnerService.GetAllDogOwners();
            var dogOwnerListViewModel = new DogOwnerListViewModel {
                DogOwnerViewModels = dogOwners.Select(e => new DogOwnerViewModel {
                    OwnerName = e.OwnerName,
                    DogNames  = e.DogNameList
                }).ToList()
            };

            return(dogOwnerListViewModel);
        }
 public void Setup()
 {
     model = new List <DogOwner> {
         new DogOwner {
             OwnerName = "anyowner", Dogs = new List <Dog> {
                 new Dog {
                     DogName = "adog"
                 }
             }
         }
     };
     viewModel = GetViewModel();
 }
Ejemplo n.º 4
0
        public DogOwnerListViewModel GetAllDogOwners()
        {
            var dogOwners             = _DogOwnerService.GetAllDogOwners();
            var dogs                  = _DogService.GetAllDogs();
            var dogOwnerListViewModel = new DogOwnerListViewModel
            {
                DogOwnerViewModels = dogOwners.GroupJoin(dogs,
                                                         owner => owner.OwnerId,
                                                         dog => dog.OwnerId,
                                                         (owner, dogCollection) => new DogOwnerViewModel()
                {
                    OwnerName = owner.OwnerName, DogNames = dogCollection.Select(x => x.DogName).ToList()
                }
                                                         ).ToList()
            };

            return(dogOwnerListViewModel);
        }
Ejemplo n.º 5
0
        public DogOwnerListViewModel GetAllDogOwners()
        {
            var dogOwnerService       = new DogOwnerService(new DogOwnerRepository());
            var dogOwners             = dogOwnerService.GetAllDogOwners();
            var dogOwnerListViewModel = new DogOwnerListViewModel
            {
                DogOwnerViewModels = dogOwners.Select(e => new DogOwnerViewModel
                {
                    OwnerName = e.OwnerName,
                    DogNames  = new List <string>
                    {
                        e.DogName
                    }
                }).ToList()
            };

            return(dogOwnerListViewModel);
        }
Ejemplo n.º 6
0
        public DogOwnerListViewModel GetAllDogOwners()
        {
            DogOwnerService          dogOwnerService       = new DogOwnerService();
            List <Entities.DogOwner> dogOwners             = dogOwnerService.GetAllDogOwners();
            DogOwnerListViewModel    dogOwnerListViewModel = new DogOwnerListViewModel
            {
                DogOwnerViewModels = dogOwners.Select(e => new DogOwnerViewModel
                {
                    Id        = e.Id,
                    OwnerName = e.OwnerName,
                    DogNames  = new List <string>
                    {
                        e.DogName
                    }
                }).ToList()
            };

            return(dogOwnerListViewModel);
        }