public void ExistsChecksCorrectly() { //Arrange string name = "test name"; var hospitals = new List <Hospital> { new Hospital { Name = name }, new Hospital { Name = $"aaa{name}" }, new Hospital { Name = $"{name}bbb" } }; var dbSet = hospitals.AsQueryable().BuildMockDbSet(); context.Setup(c => c.Set <Hospital>()).Returns(dbSet.Object); IHospitalRepository repository = new HospitalRepository(context.Object); //Act var result = repository.Exists(name).Result; //Assert Assert.IsTrue(result); }