Ejemplo n.º 1
0
        public void ExistsChecksCorrectly()
        {
            //Arrange
            long addressId = 3;
            var  address   = new Address
            {
                Id        = addressId,
                CountryId = 1,
                CityId    = 1,
                StreetId  = 1,
                Building  = "test",
                Apartment = "test"
            };
            var addresses = new List <Address>
            {
                address
            };
            var dbSet   = addresses.AsQueryable().BuildMockDbSet();
            var context = new Mock <hNextDbContext>(new DbContextOptions <hNextDbContext>());

            context.Setup(c => c.Set <Address>()).Returns(dbSet.Object);
            AddressRepository repository = new AddressRepository(context.Object);

            //Act
            var found = repository.Exists(new Address
            {
                Id        = addressId + 1,
                CountryId = 1,
                CityId    = 1,
                StreetId  = 1,
                Building  = "test",
                Apartment = "test"
            }).Result;
            var notFound = repository.Exists(new Address()).Result;

            //Assert
            Assert.AreEqual(found.Id, addressId);
            Assert.IsNull(notFound);
        }