Пример #1
0
        public async void GetAllOwners_Sorts_Results_By_Name()
        {
            // Arrange
            var mockOwnerRepository   = new Mock <IOwnerRepository>();
            var mockRepositoryWrapper = new Mock <IRepositoryWrapper>();

            var dylan = new Owner()
            {
                Id      = Guid.NewGuid(),
                Name    = "Dylan",
                Address = "my address"
            };

            var crystal = new Owner()
            {
                Id      = Guid.NewGuid(),
                Name    = "Crystal",
                Address = "my address"
            };

            var ownersToReturn = new List <Owner>()
            {
                dylan,
                crystal
            }.AsQueryable();

            mockOwnerRepository.Setup(m => m.FindAll()).Returns(ownersToReturn);

            var mockLogger = NullLogger <OwnerService> .Instance;

            var mockMapper = new Mock <IMapper>();

            var ownersAsDtos = ownersToReturn.Select(o => new OwnerDto()
            {
                Id      = o.Id,
                Name    = o.Name,
                Address = o.Address
            });

            mockMapper.Setup(m => m.Map <IEnumerable <OwnerDto> >(
                                 It.Is <IEnumerable <Owner> >(
                                     o => o.ToList()[0] == crystal && o.ToList()[1] == dylan))
                             ).Returns(ownersAsDtos);

            // Act
            var ownerService = new OwnerService(mockRepositoryWrapper.Object, mockLogger, mockMapper.Object);
            var result       = await ownerService.GetAllOwnersAsync();

            // Assert
            Assert.Equal(2, result.Count());
        }