Ejemplo n.º 1
0
        public void CreateImplementationIsThreadSafe()
        {
            // Test passes if it does not throw "Duplicate type name within an assembly"

            var factory   = new ImplementationFactory(useSourceGenerator: false, useSystemReflectionEmit: true);
            var requester = new Mock <IRequester>();

            // We can't really test this well... Just try lots, and see if we have any exceptions
            for (int i = 0; i < 100; i++)
            {
                var tasks = new Task[10];
                for (int j = 0; j < tasks.Length; j++)
                {
                    tasks[j] = Task.Run(() => factory.CreateImplementation <ISomeApi>(requester.Object));
                }

                Task.WaitAll(tasks);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an implementation for the given API interface
        /// </summary>
        /// <typeparam name="T">Type of interface to implement</typeparam>
        /// <returns>An implementation which can be used to make REST requests</returns>
        public T For <T>()
        {
            var requester = this.CreateRequester();

            return(factory.CreateImplementation <T>(requester));
        }