public void ServiceFactoryDiscoveryV1_0ConstructorSuccessTest()
        {
            var param = new FactoryParameterV1_0("http://server/");
            var json = (JsonDictionary) JsonReader.Parse(ServiceFactoryTest.DiscoveryV1_0Example);
            var fact = new ServiceFactoryDiscoveryV1_0(json, param);

            Assert.AreEqual("adsense", fact.Name);
            Assert.AreEqual(param, fact.Param);
            Assert.AreEqual(json, fact.Information);
            Assert.IsInstanceOf(typeof(ServiceV1_0), fact.GetService());
        }
        public void ServiceFactoryDiscoveryV1_0ConstructorFailTest()
        {
            Assert.Throws<ArgumentNullException>(() => new FactoryParameterV1_0((string)null));
            var json = (JsonDictionary) JsonReader.Parse(ServiceFactoryTest.DiscoveryV1_0Example);

            // Test if the constructor will fail if required arguments are missing
            var param = new FactoryParameterV1_0();
            Assert.Throws(typeof(ArgumentNullException), () => new ServiceFactoryDiscoveryV1_0(null, param));
            Assert.Throws(typeof(ArgumentNullException), () => new ServiceFactoryDiscoveryV1_0(json, null));

            json = (JsonDictionary) JsonReader.Parse(BadDiscoveryv1_0_No_Name);
            Assert.Throws(typeof(ArgumentException), () => new ServiceFactoryDiscoveryV1_0(json, param));
        }
Example #3
0
        public void TestCreateServiceFactoryV1_0()
        {
            // Test without factory parameter
            var stream = CreateStringStream(DiscoveryV1_0Example);
            IServiceFactory factory = ServiceFactory.CreateServiceFactory(stream, DiscoveryVersion.Version_1_0, null);
            Assert.IsNotNull(factory);
            Assert.IsInstanceOf(typeof(ServiceFactoryDiscoveryV1_0), factory);

            // Test with FactoryParameter
            stream = CreateStringStream(DiscoveryV1_0Example);
            var param = new FactoryParameterV1_0("https://googlecode.com/");
            factory = ServiceFactory.CreateServiceFactory(stream, DiscoveryVersion.Version_1_0, param);
            Assert.IsNotNull(factory);
            Assert.IsInstanceOf(typeof(ServiceFactoryDiscoveryV1_0), factory);
        }
Example #4
0
        /// <summary>
        ///     Checks all the parameters and calls the GoogleServiceGenerator.
        /// </summary>
        protected override void ExecuteTask()
        {
            DiscoveryUrl.ThrowIfNullOrEmpty("DiscoveryUrl");
            OutputFile.ThrowIfNull("OutputFile");
            ClientNamespace.ThrowIfNullOrEmpty("ClientNamespace");
            ApiVersion.ThrowIfNullOrEmpty("ApiVersion");
            BaseUrl.ThrowIfNullOrEmpty("BaseUrl");

            Project.Log(Level.Info, "Fetching Discovery " + DiscoveryUrl);
            var fetcher = new WebDiscoveryDevice(new Uri(DiscoveryUrl));
            var discovery = new DiscoveryService(fetcher);
            var param = new FactoryParameterV1_0(BaseUrl, null);
            var service = discovery.GetService(DiscoveryVersion.Version_1_0, param);
            var generator = new GoogleServiceGenerator(service, ClientNamespace);
            var provider = CodeDomProvider.CreateProvider("CSharp");
            Project.Log(Level.Info, "Generating To File " + OutputFile.FullName);
            using (StreamWriter sw = new StreamWriter(OutputFile.FullName, false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "  ");
                provider.GenerateCodeFromCompileUnit(generator.GenerateCode(), tw, new CodeGeneratorOptions());
                tw.Close();
            }
        }