Exemple #1
0
        public void get_all_dog_owners()
        {
            // Arrange
            List <DogOwner> list = new List <DogOwner>()
            {
                new DogOwner {
                    OwnerName = "Owner1", Dogs = new List <Dog> {
                        new Dog {
                            DogName = "DogA"
                        }
                    }
                },
                new DogOwner {
                    OwnerName = "Owner2", Dogs = new List <Dog> {
                        new Dog {
                            DogName = "DogB"
                        }
                    }
                }
            };

            repo.Setup(c => c.GetAllDogOwners()).Returns(list);

            // Act
            var result = _testObject.GetAllDogOwners();

            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreSame(list, result);
            repo.Verify(x => x.GetAllDogOwners(), Times.Once);
        }
Exemple #2
0
        public void GetAllDogOwners_Should_returnDogOwnersList_When_repositoryIsNotEmpty()
        {
            //Arrange
            var dogOwnerRepository = new Mock <IDogOwnerRepository>();
            var dogOwner           = new DogOwner()
            {
                OwnerName = "Qwe", DogNameList = new List <string>()
                {
                    "q", "w", "e"
                }
            };
            var dogOwnerList = new List <DogOwner> {
                dogOwner
            };

            dogOwnerRepository.Setup(x => x.GetAllDogOwners()).Returns(dogOwnerList);
            var dogOwnerService = new DogOwnerService(dogOwnerRepository.Object);

            //Act
            var result = dogOwnerService.GetAllDogOwners();

            //Assert
            Assert.IsNotNull(result);
            CollectionAssert.AreEqual(dogOwnerList, result);
        }
Exemple #3
0
        public void GetAllDogOwners_Should_throwException_When_repositoryReturnsNull()
        {
            //Arrange
            var dogOwnerRepository = new Mock <IDogOwnerRepository>();

            dogOwnerRepository.Setup(x => x.GetAllDogOwners()).Throws(new NullReferenceException());
            var dogOwnerService = new DogOwnerService(dogOwnerRepository.Object);

            //Act
            var result = dogOwnerService.GetAllDogOwners();
        }
Exemple #4
0
        public void GivenTheRepositoryReturnsAnException_WhenGettingAllDogs_ThenTheExceptionIsHandles()
        {
            // Assemble
            var dogOwnerRepository = new Mock <IDogOwnerRepository>();

            dogOwnerRepository.Setup(s => s.GetAllDogOwners()).Throws(new Exception());
            var dogOwnerService = new DogOwnerService(dogOwnerRepository.Object);

            // Act
            var allDogOwners = dogOwnerService.GetAllDogOwners();

            // Assert
            Assert.AreEqual(0, allDogOwners.Count());
        }
Exemple #5
0
        public void GetAllDogOwners_Should_returnEmptyDogOwnersList_When_repositoryIsEmpty()
        {
            //Arrange
            var dogOwnerRepository = new Mock <IDogOwnerRepository>();
            var dogOwnerList       = new List <DogOwner>();

            dogOwnerRepository.Setup(x => x.GetAllDogOwners()).Returns(dogOwnerList);
            var dogOwnerService = new DogOwnerService(dogOwnerRepository.Object);

            //Act
            var result = dogOwnerService.GetAllDogOwners();

            //Assert
            Assert.IsNotNull(result);
            CollectionAssert.AreEqual(dogOwnerList, result);
        }
Exemple #6
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);
        }
Exemple #7
0
        public DogOwnerListViewModel GetAllDogOwners()
        {
            var dogOwnerService       = new DogOwnerService();
            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);
        }
        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);
        }
Exemple #9
0
        public void GivenTheRepositoryHasData_WhenGettingAllDogs_ThenAListOfDogsOwnersIsReturned()
        {
            // Assemble
            var dogOwner = new List <DogOwner> {
                new DogOwner("Homer", new[] { "Santa's Little Helper" })
            };

            var dogOwnerRepository = new Mock <IDogOwnerRepository>();

            dogOwnerRepository.Setup(s => s.GetAllDogOwners()).Returns(dogOwner);
            var dogOwnerService = new DogOwnerService(dogOwnerRepository.Object);

            // Act
            var allDogOwners = dogOwnerService.GetAllDogOwners();

            // Assert
            Assert.AreEqual(1, allDogOwners.Count());
            Assert.AreEqual("Homer", allDogOwners.Single().OwnerName);
            Assert.AreEqual(1, allDogOwners.Single().DogNames.Count());
            Assert.AreEqual("Santa's Little Helper", allDogOwners.Single().DogNames.Single());
        }
        public void TestDogOwnerService()
        {
            var mockDogOwnerRepository = new Mock <DogOwnerRepository>();

            mockDogOwnerRepository.Setup(x => x.GetAllDogOwners()).Returns(
                new List <DogOwner>()
            {
                new DogOwner()
                {
                    OwnerId   = 1,
                    OwnerName = "TestOwner"
                }
            }
                );

            var dogOwnerService = new DogOwnerService(mockDogOwnerRepository.Object);
            var dogOwners       = dogOwnerService.GetAllDogOwners();

            Assert.IsNotNull(dogOwners);
            Assert.AreEqual(1, dogOwners.Count);
            Assert.AreEqual(1, dogOwners.Single().OwnerId);
            Assert.AreEqual("TestOwner", dogOwners.Single().OwnerName);
        }