Example #1
0
        public void ShouldFailIfMethodAttributeIsAbsent()
        {
            //Arrange
            var mi = typeof(IContract).GetMethod(nameof(IContract.WithoutMethodAttribute));

            //Act & Assert
            Assert.Throws <ApiContractException>(() => MethodDescription.Create(mi));
        }
Example #2
0
        public void ShouldDetermineMethodParameters()
        {
            //Arrange
            var mi = typeof(IContract).GetMethod(nameof(IContract.WithAttribute));

            //Act
            var d = MethodDescription.Create(mi);

            //Assert
            Assert.Equal(HttpMethod.Get, d.HttpMethod);
            Assert.Equal("/foo", d.Url);
        }
Example #3
0
        /// <summary>
        /// Runs the given CIL method.
        /// </summary>
        /// <param name="sourceMethod">The CIL method.</param>
        /// <returns>TestingAssembly.</returns>
        public static TestingAssembly RunCIL(Func <object> sourceMethod)
        {
            var assembly = SettingsProvider.CreateTestingAssembly();

            var description = MethodDescription.Create <object>(false);

            assembly.AddMethod(Method.EntryMethodPath, sourceMethod.Method, description);

            addStandardMethods(assembly);

            return(assembly);
        }
Example #4
0
        public void ShouldDetermineExpectedHttpCodes()
        {
            //Arrange
            var mi = typeof(IContract).GetMethod(nameof(IContract.WithAttribute));

            //Act
            var d = MethodDescription.Create(mi);

            //Assert
            Assert.Equal(2, d.ExpectedStatusCodes.Count);
            Assert.Contains(HttpStatusCode.OK, d.ExpectedStatusCodes);
            Assert.Contains(HttpStatusCode.BadRequest, d.ExpectedStatusCodes);
        }
Example #5
0
        public async Task ActorCodeBuilder_BuildDispatcher()
        {
            var host = ActorHost.CreateForTest <TestActor>();

            var dispatcher = ActorCodeBuilder.GetOrCreateMethodDispatcher(typeof(ITestActor));
            var methodId   = MethodDescription.Create("test", typeof(ITestActor).GetMethod("GetCountAsync"), true).Id;

            var impl     = new TestActor(host);
            var request  = new ActorRequestMessageBody(0);
            var response = new WrappedRequestMessageFactory();

            var body = (WrappedMessage)await dispatcher.DispatchAsync(impl, methodId, request, response, default);

            dynamic bodyValue = body.Value;

            Assert.Equal(5, (int)bodyValue.retVal);
        }
Example #6
0
 internal static JsWorkerMethodDocs GetTask <TResult>(Func <Task <TResult> > task, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(typeof(TResult), null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 return new JsWorkerMethodResult
                 {
                     Result = task().ConfigureAwait(true).GetAwaiter().GetResult(),
                 };
             }
         }
     });
 }
Example #7
0
 internal static JsWorkerMethodDocs GetAction(Action action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 action();
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Example #8
0
 internal static JsWorkerMethodDocs GetTask <T1, T2, TResult>(Func <T1, T2, Task <TResult> > task, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(typeof(TResult), new List <Type> {
             typeof(T1), typeof(T2)
         }, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 return new JsWorkerMethodResult
                 {
                     Result = task(p.GetParameter <T1>(), p.GetParameter <T2>()).ConfigureAwait(true).GetAwaiter().GetResult(),
                 };
             }
         }
     });
 }
Example #9
0
        internal static JsWorkerMethodDocs GetFunc <TResult>(Func <TResult> func, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), null, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var result = func();

                        return new JsWorkerMethodResult
                        {
                            Result = result
                        };
                    }
                }
            });
        }
Example #10
0
 internal static JsWorkerMethodDocs GetTask <TService>(Func <TService, Task> task, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 var service = srv.GetRequiredService <TService>();
                 task(service).ConfigureAwait(true).GetAwaiter().GetResult();
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Example #11
0
 internal static JsWorkerMethodDocs GetAction <TService>(Action <TService> action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, null, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 var service = srv.GetRequiredService <TService>();
                 action(service);
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Example #12
0
 internal static JsWorkerMethodDocs GetAction <T1, T2>(Action <T1, T2> action, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, new List <Type> {
             typeof(T1), typeof(T2)
         }, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 action(p.GetParameter <T1>(), p.GetParameter <T2>());
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Example #13
0
        internal static JsWorkerMethodDocs GetFunc <T1, T2, T3, TResult>(Func <T1, T2, T3, TResult> func, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), new List <Type> {
                    typeof(T1), typeof(T2), typeof(T3)
                }, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var result = func(p.GetParameter <T1>(), p.GetParameter <T2>(), p.GetParameter <T3>());

                        return new JsWorkerMethodResult
                        {
                            Result = result
                        };
                    }
                }
            });
        }
Example #14
0
 internal static JsWorkerMethodDocs GetTask <TService, T1, T2>(Func <TService, T1, T2, Task> task, MethodDocsOptions opts)
 {
     return(new JsWorkerMethodDocs
     {
         Description = MethodDescription.Create(null, new List <Type> {
             typeof(T1), typeof(T2)
         }, opts),
         Method = new JsWorkerMethodBase
         {
             FunctionLink = (p, srv) =>
             {
                 var service = srv.GetRequiredService <TService>();
                 task(service, p.GetParameter <T1>(), p.GetParameter <T2>()).ConfigureAwait(true).GetAwaiter().GetResult();
                 return new JsWorkerMethodResult
                 {
                     Result = null,
                 };
             }
         }
     });
 }
Example #15
0
        internal static JsWorkerMethodDocs GetAction <TService, T1>(Action <TService, T1> action, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(null, new List <Type> {
                    typeof(T1)
                }, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var service = srv.GetRequiredService <TService>();

                        action(service, p.GetParameter <T1>());
                        return new JsWorkerMethodResult
                        {
                            Result = null,
                        };
                    }
                }
            });
        }
Example #16
0
        internal static JsWorkerMethodDocs GetFunc <TService, T, TResult>(Func <TService, T, TResult> func, MethodDocsOptions opts)
        {
            return(new JsWorkerMethodDocs
            {
                Description = MethodDescription.Create(typeof(TResult), new List <Type> {
                    typeof(T)
                }, opts),
                Method = new JsWorkerMethodBase
                {
                    FunctionLink = (p, srv) =>
                    {
                        var service = srv.GetRequiredService <TService>();

                        var result = func(service, p.GetParameter <T>());

                        return new JsWorkerMethodResult
                        {
                            Result = result
                        };
                    }
                }
            });
        }