Ejemplo n.º 1
0
        public void Generate()
        {
            if (_providerService == null)
            {
                throw new Exception("Mock the provider service");
            }

            if (string.IsNullOrEmpty(consumer))
            {
                throw new Exception("Define the service");
            }

            if (string.IsNullOrEmpty(provider))
            {
                throw new Exception("Define the provider");
            }

            DefaultContractResolver contractResolver = new DefaultContractResolver
            {
                NamingStrategy = new CamelCaseNamingStrategy
                {
                    OverrideSpecifiedNames = false
                }
            };


            var contracts          = _providerService.GetContracts();
            var contractDefinition = new ContractDefinition()
            {
                Provider  = provider,
                Consumer  = consumer,
                Contracts = contracts
            };

            File.WriteAllText($"{contractDirectory}{consumer}-{provider}.json",
                              JsonConvert.SerializeObject(contractDefinition,
                                                          new JsonSerializerSettings()
            {
                ContractResolver = contractResolver,
                Formatting       = Formatting.Indented
            }));
        }