コード例 #1
0
        public void Get_All_Persons()
        {
            // Arrange
            var allPersons = new[]
            {
                new Library.Entity.Person {FirstName = "John", LastName = "McClung", MiddleName = "Paul", Notes = "Crazy as can be"},
                new Library.Entity.Person {FirstName = "Katie", LastName = "McClung", MiddleName = "Elane", Notes = "Just as crazy as John"}
            };
            var service = Mock.Of<IPersonService>(s => s.All(null, null, "LastName") == allPersons.AsEnumerable());
            var controller = new PersonController(service);

            // Act
            var result = controller.Get(null, null, "LastName") as OkNegotiatedContentResult<IEnumerable<Web.Models.Person>>;
            var personModels = allPersons.AsEnumerable().ToModel();

            // Assert
            Assert.NotNull(result);
            Assert.True(personModels.SequenceEqual(result.Content));
        }
コード例 #2
0
        public void Get_Person_By_Id_Test()
        {
            // Arrange
            var person = new Library.Entity.Person
            {
                FirstName = "John",
                LastName = "McClung",
                MiddleName = "Paul",
                Notes = "Crazy as can be",
                Id = ObjectId.GenerateNewId()
            };
            var service = Mock.Of<IPersonService>(s => s.Get(person.Id.ToString()) == person);
            var controller = new PersonController(service);
            var personModel = Mapper.Map<Library.Entity.Person, Web.Models.Person>(person);

            // Act
            var result = controller.Get(person.Id.ToString()) as OkNegotiatedContentResult<Web.Models.Person>;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(personModel, result.Content);
        }
コード例 #3
0
        public void Get_Person_Throws_when_service_returns_null()
        {
            // Arrange
            var id = new ObjectId().ToString();
            var service = new Mock<IPersonService>();
            service.Setup(s => s.Get(id)).Returns((Library.Entity.Person) null);// Had trouble making the static setup work like in the other tests
            var controller = new PersonController(service.Object);

            // Act
            var result = controller.Get(id);

            // Assert
            Assert.IsType<NotFoundResult>(result);
        }