Esempio n. 1
0
        public static Mock <IAdService> Build(this ServiceBuildInfo info, out string html)
        {
            html = AutoFaker.Generate <string>();
            var service = new Mock <IAdService>();

            service
            .Setup(it => it.GetOffer(It.IsAny <Criteria>()))
            .ReturnsAsync(new AdResponse {
                Amount = info.Amount, Html = html
            }, TimeSpan.FromMilliseconds(info.Delay));
            return(service);
        }
Esempio n. 2
0
        private static Dictionary <TypeInfo, ServiceBuildInfo> BuildPaths(IList <string> hiddenTags)
        {
            var wcfAssembly = typeof(ServiceContractAttribute).Assembly.GetName().Name;

            // if assembly is from GAC, then we don't need to process it
            // or if assembly doesn't reference System.ServiceModel so it can't have WCF services and we also can safely ignore it
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
                                    .Where(
                assembly =>
                !assembly.GlobalAssemblyCache ||
                assembly.GetReferencedAssemblies().Any(a => a.Name != wcfAssembly)).ToArray();

            Dictionary <TypeInfo, ServiceBuildInfo> result = new Dictionary <TypeInfo, ServiceBuildInfo>();

            foreach (Assembly assembly in assemblies)
            {
                IEnumerable <TypeInfo> types;
                try
                {
                    types = assembly.DefinedTypes;
                }
                catch (Exception)
                {
                    // ignore assembly and continue
                    continue;
                }

                foreach (TypeInfo ti in types)
                {
                    SwaggerWcfAttribute da = ti.GetCustomAttribute <SwaggerWcfAttribute>();
                    if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
                    {
                        continue;
                    }

                    Mapper mapper = new Mapper(hiddenTags);

                    var info = new ServiceBuildInfo();
                    info.DefinitionsTypesList = new List <Type>();
                    info.Name  = da.Name;
                    info.Paths = mapper.FindMethods(da.ServicePath, ti.AsType(), info.DefinitionsTypesList).ToList();

                    result.Add(ti, info);
                }
            }

            return(result);
        }
Esempio n. 3
0
 public static ServiceBuildInfo WithAmount(this ServiceBuildInfo info, decimal amount)
 {
     info.Amount = amount;
     return(info);
 }
Esempio n. 4
0
 public static ServiceBuildInfo WithDelay(this ServiceBuildInfo info, int delay)
 {
     info.Delay = delay;
     return(info);
 }