// by convention routing: GET/api.lawyers/{id}
 public Lawyer Get(int id)
 {
     using (LawyerService lawyerService = new LawyerService(new DataContext()))
     {
         return(lawyerService.Get(id));
     }
 }
示例#2
0
        public void GetOneLawyer()
        {
            // setting up the expectations
            var existing    = Lawyers.ElementAt(1);
            var notExisting = new Lawyer {
                Id = 404
            };

            // test
            using (LawyerService lawyerService = new LawyerService(MockContext.Object))
            {
                var actual = lawyerService.Get(existing.Id);
                MockLawyersSet.Verify(m => m.Find(It.IsAny <int>()), Times.Once);
                Assert.IsNotNull(actual);
                Assert.AreEqual(existing, actual);

                actual = lawyerService.Get(notExisting.Id);
                MockLawyersSet.Verify(m => m.Find(It.IsAny <int>()), Times.Exactly(2));
                Assert.IsNull(actual);
            }
        }