Exemplo n.º 1
0
        public void GetAllGenericShouldReturnCorrectCountUsingMoq()
        {
            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly);

            var repository = new Mock <IDeletableEntityRepository <Address> >();

            var country = new Country
            {
                Id   = 1,
                Name = "Bulgaria",
            };

            var city = new City
            {
                Id      = 1,
                Name    = "Ruse",
                ZIPCode = "7000",
                Country = country,
            };

            var addressesList = new List <Address>
            {
                new Address {
                    Id = "TestId1", CreatedOn = DateTime.UtcNow, City = city, Street = "Test Street 1", UserId = "Test User 1"
                },
                new Address {
                    Id = "TestId2", CreatedOn = DateTime.UtcNow, City = city, Street = "Test Street 2", UserId = "Test User 2"
                },
                new Address {
                    Id = "TestId3", CreatedOn = DateTime.UtcNow, City = city, Street = "Test Street 3", UserId = "Test User 1"
                },
            };

            repository.Setup(r => r.AllAsNoTracking()).Returns(addressesList.AsQueryable());

            var service = new AddressesService(repository.Object, null);

            Assert.Equal(2, service.GetAll <AddressViewModel>("Test User 1").Count());

            repository.Verify(x => x.AllAsNoTracking(), Times.Once);
        }