Пример #1
0
 /// <summary>
 /// Called after a service method is executed.
 /// </summary>
 /// <param name="serviceContext">The service context.</param>
 /// <param name="behaviorContext">The "method executed" behavior context.</param>
 public override void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext)
 {
     serviceContext.Response.Output.WriteLine(2).WriteFormat("Action '{0}' executed", behaviorContext.GetMethodName());
 }
Пример #2
0
        public void MethodExecutedContextShouldBePopulatedForSelfContainedService()
        {
            var service = new TestSelfContainedService();

            MethodInfo method = service.GetType().GetMethod("GetOK");
            Assert.That(method, Is.Not.Null);

            var returnedObject = String.Copy("OK");

            var behaviorContext = new MethodExecutedContext(service, method, returnedObject);
            Assert.That(behaviorContext.Service, Is.SameAs(service));
            Assert.That(behaviorContext.Method, Is.SameAs(method));
            Assert.That(behaviorContext.ReturnedObject, Is.SameAs(returnedObject));
            Assert.That(behaviorContext.GetServiceContractType(), Is.EqualTo(typeof(TestSelfContainedService)));
            Assert.That(behaviorContext.GetServiceType(), Is.EqualTo(typeof(TestSelfContainedService)));
            Assert.That(behaviorContext.GetMethodName(), Is.EqualTo(method.Name));

            var httpMethods = behaviorContext.GetSupportedHttpMethods().ToList();
            Assert.That(httpMethods.Contains(HttpMethod.Get), Is.True);
            Assert.That(httpMethods.Contains(HttpMethod.Head), Is.False);
            Assert.That(httpMethods.Contains(HttpMethod.Post), Is.False);
            Assert.That(httpMethods.Contains(HttpMethod.Put), Is.False);
            Assert.That(httpMethods.Contains(HttpMethod.Patch), Is.False);
            Assert.That(httpMethods.Contains(HttpMethod.Delete), Is.False);
        }