コード例 #1
0
        public void SetUp()
        {
            _persons = new List<Person>();
            _persons.Add(new Person() { Id = 1, Name = "FirstUser" });
            _persons.Add(new Person() { Id = 2, Name = "AnotherUser" });
            _persons.Add(new Person() { Id = 3, Name = "ThirdUser" });

            var repository = new Mock<IPersonRepository>();
            repository.Setup(x => x.GetAll()).Returns(_persons.AsEnumerable());
            var builder = new Mock<IPersonDtoBuilder>();
            builder.Setup(x => x.BuildDto(It.IsAny<Person>())).Returns((Person p) => new PersonDto() { Name = p.Name });
            _facade = new PersonFacade(repository.Object, builder.Object);
        }
コード例 #2
0
        public void GetPersonsReturnsAllFromRepository()
        {
            List<Person> persons = new List<Person>();
            persons.Add(new Person("a", 1, "a"));
            persons.Add(new Person("b", 2, "b"));

            var repositoryMock = new Mock<PersonRepository>();
            repositoryMock.Setup<IEnumerable<Person>>(x => x.GetAll()).Returns(persons.AsEnumerable());

            var facade = new PersonFacade(repositoryMock.Object, null);

            Assert.AreEqual(persons.AsEnumerable(), facade.GetPersons());
        }