public void TestGreetingGetByID() { //准备 var fakeRequest = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/api/greeting"); var service = new GreetingController(); var name = "AAA"; var _greeting = service.GetGreetingData(); service.Request = fakeRequest; //操作 var response = service.GetGreeting(name); //断言 Assert.IsNotNull(response); Assert.AreEqual(_greeting.FirstOrDefault(t => t.Name == name).Message, response.ToString()); }