コード例 #1
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public async void GenerateFromHttpWithSettingTest(string url, string version, int n)
        {
             PocoSetting setting = new PocoSetting
            {
                AddNullableDataType = true,
                AddKeyAttribute = true,
                AddTableAttribute = true,
                AddRequiredAttribute = true,
                AddNavigation = true
            };

             //var url = "http://services.odata.org/V4/OData/OData.svc";
             O2P o2p = new O2P( setting);
             var code = await o2p.GenerateAsync(new Uri(url));
             Debug.WriteLine(code);

             Assert.AreEqual(o2p.MetaDataVersion, version);
             Assert.AreEqual(o2p.ClassList.Count, n);
             Assert.IsTrue(code.Contains(o2p.SchemaNamespace));

             StringAssert.Contains("[Key]", code);
             StringAssert.Contains("[Required]", code);
             StringAssert.Contains("[Table", code);

        }
コード例 #2
0
        public void GenerateCodeWithAttributeTest(string url)
        {
            string o2p = new O2P()
                         .AddKeyAttribute()
                         .AddRequiredAttribute()
                         .AddNavigation()
                         .AddTableAttribute()
                         .SetUrl(url)
                         .Generate("north.cs");

            //.SaveCodeTo();
            //Console.WriteLine(File.ReadAllText("north.cs"));
            Console.WriteLine(o2p);
            //Assert.IsTrue(MatchFileContent("north.cs", o2p));
            if (!o2p.Contains("[Key]"))
            {
                Console.WriteLine("eeeeeeeeeeeeeeerror");
            }
            else
            {
                Console.WriteLine("exxxxxxxxxxxxist");
            }
            // .SaveCodeTo();
            Console.WriteLine(o2p);
            //Assert.IsTrue(code.Contains("public class Product"));
            Assert.IsTrue(o2p.Contains("Key"));
            Assert.IsTrue(o2p.Contains("Required"));
            Assert.IsTrue(o2p.Contains("Table"));
        }
コード例 #3
0
        public async void GenerateFromHttpWithSettingTest(string url, string version, int n)
        {
            PocoSetting setting = new PocoSetting
            {
                AddNullableDataType  = true,
                AddKeyAttribute      = true,
                AddTableAttribute    = true,
                AddRequiredAttribute = true,
                AddNavigation        = true
            };

            //var url = "http://services.odata.org/V4/OData/OData.svc";
            O2P o2p  = new O2P(setting);
            var code = await o2p.GenerateAsync(new Uri(url));

            Debug.WriteLine(code);

            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2p.SchemaNamespace));

            StringAssert.Contains("[Key]", code);
            StringAssert.Contains("[Required]", code);
            StringAssert.Contains("[Table", code);
            StringAssert.Contains("virtual public Supplier Supplier  {get;set;}", code);
            StringAssert.DoesNotContain("public class Product :", code);
            StringAssert.Contains("System.ComponentModel.DataAnnotations.Schema", code);
            StringAssert.Contains("System.ComponentModel.DataAnnotations", code);
        }
コード例 #4
0
        public async Task web_api2_v3_mult_namespace_class_and_enum_Test()
        {
            var conn = new OdataConnectionString
            {
                ServiceUrl = TestSample.MultiSchemaV3,
            };
            var setting = new PocoSetting
            {
                Lang     = Language.CS,
                NameCase = CaseEnum.None,
            };
            var o2P  = new O2P(setting);
            var code = await o2P.GenerateAsync(conn);

            var expected = @"
namespace ODataDemo
{
	public partial class Customer
	{
	    public int ID {get;set;} //PrimaryKey not null
	    public string CustomerName {get;set;} 
	    public string Address {get;set;} 
	}
	public partial class Location
	{
	    public string Address {get;set;} 
	    public string City {get;set;}
	}
}
namespace ODataDemo2
{
	public partial class Customer
	{
    public int ID {get;set;} //PrimaryKey not null
	    public string CustomerName {get;set;} 
	    public string Address {get;set;} 
	}
	public partial class Customer2
	{
	    public int ID {get;set;} //PrimaryKey not null
	    public string CustomerName {get;set;} 
	    public string Address {get;set;} 
	}
	public enum Feature
	 {
        Feature1=0,
        Feature2=1,
        Feature3=2,
        Feature4=3 
	}
}
";

            //Assert
            Assert.That(code.TrimAllSpace(), Does.Contain(expected.TrimAllSpace()));
        }
コード例 #5
0
        public async Task GenerateDefaultTest(string url, string version, int n)
        {
            var connString = new OdataConnectionString {
                ServiceUrl = url
            };
            var o2p  = new O2P();
            var code = await o2p.GenerateAsync(connString);

            Assert.IsTrue(code.Contains("public partial class Product"));
        }
コード例 #6
0
        public void InheritanceDisabledWithInheritSettingTest()
        {
            var setting = new PocoSetting
            {
                Inherit = "MyBaseClass",
            };
            var o2p = new O2P(setting);

            Assert.IsFalse(o2p.Setting.UseInheritance);
        }
コード例 #7
0
        public void GeneratePocoFromNullUrlTest()
        {
            var url = "";
            var o2P = new O2P();

            Assert.Throws <UriFormatException>(async() =>
            {
                var code = await o2P.GenerateAsync(new Uri(url));
            });
        }
コード例 #8
0
        public void GenerateFromXmlWithSettingTest(string fname, string version, int n)
        {
            var xml  = File.ReadAllText(fname);
            O2P o2p  = new O2P();
            var code = o2p.Generate(xml);

            Debug.WriteLine(code);
            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2p.SchemaNamespace));
        }
コード例 #9
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public void GenerateFromXmlWithSettingTest(string fname, string version, int n)
        {
            var xml = File.ReadAllText(fname);
            O2P o2p = new O2P();
            var code = o2p.Generate(xml);
            Debug.WriteLine(code);
            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2p.SchemaNamespace));

        }
コード例 #10
0
        public void GenerateWithNoUrlTest()
        {
            //System.Exception : Url is empty
            string code = new O2P()
                          // .SetUrl("http://services.odata.org/V4/Northwind/Northwind.svc")
                          .AddKeyAttribute()
                          .AddTableAttribute()
                          .Generate();

            Assert.IsNull(code);
        }
コード例 #11
0
ファイル: O2PTest.cs プロジェクト: thucnguyen77/odata2poco
        public async Task GenerateDefaultTestV3()
        {
            var url        = TestSample.NorthWindV3;
            var connString = new OdataConnectionString {
                ServiceUrl = url
            };
            var o2p  = new O2P();
            var code = await o2p.GenerateAsync(connString);

            Assert.IsTrue(code.Contains("public partial class Product"));
        }
コード例 #12
0
        public async void GenerateCodeUrlValidAuthenticateNoSettingTest()
        {
            string url     = "http://asd-pc/odata2/api/northwind";
            string version = "4.0";
            int    n       = 26;
            var    o2P     = new O2P();

            var code = await o2P.GenerateAsync(new Uri(url), "hassan", "123");

            Debug.WriteLine(code);
            StringAssert.Contains("public class Product", code);
        }
コード例 #13
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
 public async void GenerateFromHttpDefaultSettingTest(string url, string version, int n)
 {
     //var url = "http://services.odata.org/V4/OData/OData.svc";
     O2P o2p = new O2P();
     var code = await o2p.GenerateAsync(new Uri(url));
     Debug.WriteLine(code);
    
     Assert.AreEqual(o2p.MetaDataVersion, version);
     Assert.AreEqual(o2p.ClassList.Count, n);
     Assert.IsTrue(code.Contains(o2p.SchemaNamespace));
     
 }
コード例 #14
0
ファイル: O2PTest.cs プロジェクト: thucnguyen77/odata2poco
        public async Task GenerateDefaultTestV4()
        {
            var url = TestSample.TripPin4;

            Console.WriteLine(url);
            var connString = new OdataConnectionString {
                ServiceUrl = url
            };
            var o2p  = new O2P();
            var code = await o2p.GenerateAsync(connString);

            Assert.IsTrue(code.Contains("public partial class City"));
        }
コード例 #15
0
        public void GenerateCodeNoAttributeTest(string url)
        {
            string code = new O2P()
                .SetUrl(url)
                 .Generate("north.cs")
                //.SaveCodeTo("north.cs")
                .SaveMetaDataTo();

            var code2 = File.ReadAllText("north.cs");
            Console.WriteLine(code2);
            Assert.IsTrue(code.Contains("public class Product"));
            Assert.IsTrue(code2.Contains("public class Product"));
        }
コード例 #16
0
        public void GenerateCodeNoAttributeTest(string url)
        {
            string code = new O2P()
                          .SetUrl(url)
                          .Generate("north.cs")
                          //.SaveCodeTo("north.cs")
                          .SaveMetaDataTo();

            var code2 = File.ReadAllText("north.cs");

            Console.WriteLine(code2);
            Assert.IsTrue(code.Contains("public class Product"));
            Assert.IsTrue(code2.Contains("public class Product"));
        }
コード例 #17
0
        public async void GenerateFromHttpDefaultSettingTest(string url, string version, int n)
        {
            //var url = "http://services.odata.org/V4/OData/OData.svc";
            O2P o2p  = new O2P();
            var code = await o2p.GenerateAsync(new Uri(url));

            Debug.WriteLine(code);

            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2p.SchemaNamespace));
            StringAssert.DoesNotContain("System.ComponentModel.DataAnnotations.Schema", code);
            StringAssert.DoesNotContain("System.ComponentModel.DataAnnotations", code);
        }
コード例 #18
0
ファイル: O2PTest.cs プロジェクト: thucnguyen77/odata2poco
        public async Task Filter_by_namespace_Test()
        {
            var url        = TestSample.NorthWindV4;
            var connString = new OdataConnectionString {
                ServiceUrl = url
            };
            var setting = new PocoSetting {
                Include = new List <string> {
                    "NorthwindModel*"
                }
            };
            var o2p  = new O2P(setting);
            var code = await o2p.GenerateAsync(connString);

            Assert.IsTrue(code.Contains("public partial class Product"));
        }
コード例 #19
0
        public void GeneratePocoFromEmtyXmlTest()
        {
            // <System.Exception> (Metadata is not available)
            var o2P        = new O2P();
            var code       = "";
            var metaString = "";

            Assert.Throws <ArgumentNullException>(() =>
            {
                code = o2P.Generate("");
                //    metaString = await o2P.SaveMetaDataTo("north.xml");
            });

            Assert.IsEmpty(code);
            Assert.IsEmpty(metaString);
        }
コード例 #20
0
        public CsCommand(Options options, IPocoFileSystem fileSystem)
        {
            if (fileSystem == null)
            {
                _fileSystem = new NullFileSystem();
            }
            else
            {
                _fileSystem = fileSystem;
            }

            Errors                = new List <string>();
            ArgOptions            = optionManager = new OptionManager(options);
            odataConnectionString = optionManager.GetOdataConnectionString();
            PocoSettingOptions    = optionManager.GetPocoSetting();
            O2PGen                = new O2P(PocoSettingOptions);
        }
コード例 #21
0
        public async Task Web_api2_v4_base_class_test()
        {
            var conn = new OdataConnectionString
            {
                ServiceUrl = TestSample.SampleWebApiV4,
            };
            var setting = new PocoSetting
            {
                Lang     = Language.CS,
                NameCase = CaseEnum.None,
            };
            var o2P  = new O2P(setting);
            var code = await o2P.GenerateAsync(conn);

            Assert.That(code, Does.Contain("public partial class Circle : Shape"));
            Assert.That(code, Does.Contain("public partial class Rectangle : Shape"));
        }
コード例 #22
0
        public async void GenerateFromHttpWithSettingEmptyNamepaceTest(string url, string version, int n)
        {
            PocoSetting setting = new PocoSetting
            {
                NamespacePrefix = ""
            };

            //var url = "http://services.odata.org/V4/OData/OData.svc";
            O2P o2p  = new O2P(setting);
            var code = await o2p.GenerateAsync(new Uri(url));

            Debug.WriteLine(code);

            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains($"namespace {o2p.SchemaNamespace}"));
        }
コード例 #23
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello OData2Poco Demo!");
            // string client_id="<Enter client id /or application id here>";
            // string client_secret="<Enter client secret  here>";

            //define connection parameters
            var connString = new OdataConnectionString
            {
                ServiceUrl   = "http://services.odata.org/V4/OData/OData.svc",
                Authenticate = AuthenticationType.none,

                //for oauth2
                //Authenticate = AuthenticationType.oauth2,
                //UserName = client_id,
                //Password = client_secret,
                //TokenParams = "resource=...",
                //TokenUrl = "https://url/of/tokenserver",
            };
            var setting = new PocoSetting
            {
                Attributes = new List <string> {
                    "key"
                },
                AddNavigation       = true,
                AddNullableDataType = true,
            };

            try
            {
                var o2p  = new O2P(setting);
                var code = await o2p.GenerateAsync(connString);

                Console.WriteLine(code);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
            }
        }
コード例 #24
0
        public async Task Web_api2_v4_abstract_class_test()
        {
            var conn = new OdataConnectionString
            {
                ServiceUrl = TestSample.SampleWebApiV4,
            };
            var setting = new PocoSetting
            {
                Lang     = Language.CS,
                NameCase = CaseEnum.None,
            };
            var o2P  = new O2P(setting);
            var code = await o2P.GenerateAsync(conn);

            var expected = "public abstract partial class Shape";

            Assert.That(code, Does.Contain(expected));
        }
コード例 #25
0
        public async Task web_api2_v3_mult_namespace_Test()
        {
            var conn = new OdataConnectionString
            {
                ServiceUrl = TestSample.MultiSchemaV3,
            };
            var setting = new PocoSetting
            {
                Lang     = Language.CS,
                NameCase = CaseEnum.None,
            };
            var o2P  = new O2P(setting);
            var code = await o2P.GenerateAsync(conn);

            Assert.That(code, Does.Contain("namespace ODataDemo"));
            Assert.That(code, Does.Contain("namespace ODataDemo2"));
            Assert.That(code, Does.Contain("namespace ODataDemo3"));
        }
コード例 #26
0
        public async void GenerateFromHttpWithSettingEagerTest(string url, string version, int n)
        {
            PocoSetting setting = new PocoSetting
            {
                AddEager = true
            };

            //var url = "http://services.odata.org/V4/OData/OData.svc";
            O2P o2p  = new O2P(setting);
            var code = await o2p.GenerateAsync(new Uri(url));

            Debug.WriteLine(code);

            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2p.SchemaNamespace));

            StringAssert.Contains("public Supplier Supplier  {get;set;}", code);
        }
コード例 #27
0
        public async void GenerateFromHttpWithSettingInheritTest(string url, string version, int n)
        {
            PocoSetting setting = new PocoSetting
            {
                Inherit = "MyBaseClass, MyInterface"
            };

            //var url = "http://services.odata.org/V4/OData/OData.svc";
            O2P o2p  = new O2P(setting);
            var code = await o2p.GenerateAsync(new Uri(url));

            Debug.WriteLine(code);

            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2p.SchemaNamespace));

            StringAssert.Contains(": MyBaseClass, MyInterface", code);
        }
コード例 #28
0
        public async Task Web_api2_v4_attributes_test(string att)
        {
            var conn = new OdataConnectionString
            {
                ServiceUrl = TestSample.SampleWebApiV4,
            };
            var setting = new PocoSetting
            {
                Lang       = Language.CS,
                NameCase   = CaseEnum.None,
                Attributes = new List <string> {
                    att
                }
            };
            var o2P  = new O2P(setting);
            var code = await o2P.GenerateAsync(conn);

            switch (att)
            {
            case "key":
                Assert.That(code, Does.Contain("[Key]"));
                break;

            case "req":
                Assert.That(code, Does.Contain("[Required]"));
                break;

            case "tab":
                Assert.That(code, Does.Contain("[Table(\"Windows\")]"));
                break;

            case "dm":
                Assert.That(code, Does.Contain("	[DataContract]"));
                Assert.That(code, Does.Contain("  [DataMember]"));
                break;

            case "proto":
                Assert.That(code, Does.Contain("	[ProtoContract]"));
                Assert.That(code, Does.Contain("   [ProtoMember(1)"));
                break;
            }
        }
コード例 #29
0
        public async Task <string> BaseTest(string url, string version, int n, PocoSetting setting)
        {
            O2P o2P = new O2P(setting);

            var code = await o2P.GenerateAsync(new Uri(url));

            //    var metaString = await o2P.SaveMetaDataTo("north.xml");
            if (o2P.MediaType == Media.Http)
            {
                Assert.Greater(o2P.ServiceHeader.Count, 0);
            }
            Debug.WriteLine(code);
            //Debug.WriteLine(metaString);

            Assert.AreEqual(o2P.MetaDataVersion, version);
            Assert.AreEqual(o2P.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2P.SchemaNamespace));
            //Assert.IsTrue(MatchFileContent("north.cs", code));
            //Assert.IsTrue(MatchFileContent("north.xml", metaString));
            return(code);
        }
コード例 #30
0
        [TestCase("http://www.google.com")]    //not odata support

        //[ExpectedException(typeof(WebException))]
        //System.Net.WebException : The remote name could not be resolved: 'not_valid_url.com'
        //System.Net.WebException : The remote server returned an error: (404) Not Found.
        public async void GeneratePocoInvalidODataOrUrlTest(string url)
        {
            var o2P        = new O2P();
            var code       = "";
            var metaString = "";


            try
            {
                code = await o2P.GenerateAsync(new Uri(url));

                //metaString = o2P.SaveMetaDataTo("north.xml");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.FullExceptionMessage());
            }

            Assert.IsEmpty(code);
            Assert.IsEmpty(metaString);
        }
コード例 #31
0
ファイル: Command.cs プロジェクト: altaweelali/odata2poco
 public Command(Options options)
 {
     ArgOptions         = options;
     PocoSettingOptions = new PocoSetting
     {
         AddKeyAttribute      = ArgOptions.Key,
         AddTableAttribute    = ArgOptions.Table,
         AddRequiredAttribute = ArgOptions.Required,
         AddNavigation        = ArgOptions.Navigation,
         AddNullableDataType  = ArgOptions.AddNullableDataType,
         AddEager             = ArgOptions.Eager,                                                             //v2.1.0
         Inherit         = string.IsNullOrWhiteSpace(ArgOptions.Inherit) ? string.Empty : ArgOptions.Inherit, //v2.1.0
         NamespacePrefix = string.IsNullOrEmpty(ArgOptions.Namespace) ? string.Empty : ArgOptions.Namespace,
         //v2.1.0
         AddJsonAttribute = ArgOptions.AddJsonAttribute,     //v2.2
         NameCase         = ArgOptions.NameCase.ToCaseEnum() //v2.2
     };
     AddAttributes();
     O2PGen = new O2P(PocoSettingOptions);
     //Console.WriteLine("constrrrrrrrrr {0} {1}",ArgOptions.NameCase ,PocoSettingOptions.NameCase);
 }
コード例 #32
0
        public async void GenerateFromHttpWithSettingNamepaceTest(string url, string version, int n)
        {
            PocoSetting setting = new PocoSetting
            {
                NamespacePrefix = "MyNamespace1.MyNamespace2"
            };

            //var url = "http://services.odata.org/V4/OData/OData.svc";
            O2P o2p  = new O2P(setting);
            var code = await o2p.GenerateAsync(new Uri(url));

            Debug.WriteLine(code);

            Assert.AreEqual(o2p.MetaDataVersion, version);
            Assert.AreEqual(o2p.ClassList.Count, n);

            var namespc = (setting.NamespacePrefix + "." + o2p.SchemaNamespace).Replace("..", ".");

            namespc = namespc.TrimEnd('.');
            //Assert.IsFalse(code.Contains(o2p.SchemaNamespace));
            StringAssert.Contains(namespc, code);
        }
コード例 #33
0
        public void ImplicitConversionTest(string url, string version)
        {
            var o2p = new O2P()
                .SetUrl(url)
                .AddKeyAttribute()
                 .Generate("north.cs")
                //.SaveCodeTo("north.cs")
                .SaveMetaDataTo("metanorth.xml");

            //implicit conversion
            MetaDataInfo meta = o2p;


            //implicit conversion as string
            Console.WriteLine(o2p);
            Assert.IsTrue(MatchFileContent("north.cs", o2p));
            Assert.IsTrue(MatchFileContent("metanorth.xml", ((MetaDataInfo)o2p).MetaDataAsString));
            Assert.IsTrue(((string)o2p).Contains("public class Product"));

            if (meta.MediaType == Media.Http)
            {
                Assert.Greater(meta.ServiceHeader.Count, 1);
            }
            else
            {
                Assert.AreEqual(meta.ServiceHeader.Count, 0);
            }

            Assert.AreEqual(meta.MetaDataVersion, version);

            Assert.AreEqual(((MetaDataInfo)o2p).MetaDataVersion, version, "metadataversion");

            Console.WriteLine(meta.ServiceHeader.DicToString());

            //implicit conversion test

        }
コード例 #34
0
        public void GenerateCodeUrlInvalidAuthenticateNoSettingTest()
        {
            string url        = "http://asd-pc/odata2/api/northwind";
            string version    = "4.0";
            int    n          = 26;
            var    code       = "";
            var    metaString = "";
            //File.Delete("north.cs");
            //File.Delete("north.xml");

            var o2P = new O2P();
            var ex  = Assert.Throws <WebException>(async() =>
            {
                code = await o2P.GenerateAsync(new Uri(url), "hassan1", "123");
                //metaString = o2P.SaveMetaDataTo("north.xml");
            }); //.GeneratePoco());

            Debug.WriteLine(ex.Message);
            Console.WriteLine(code);
            //Assert.IsFalse(File.Exists("north.cs"));
            //Assert.IsFalse(File.Exists("north.xml"));
            Assert.IsEmpty(code);
            Assert.IsEmpty(metaString);
        }
コード例 #35
0
        public void ImplicitConversionTest(string url, string version)
        {
            var o2p = new O2P()
                      .SetUrl(url)
                      .AddKeyAttribute()
                      .Generate("north.cs")
                      //.SaveCodeTo("north.cs")
                      .SaveMetaDataTo("metanorth.xml");

            //implicit conversion
            MetaDataInfo meta = o2p;


            //implicit conversion as string
            Console.WriteLine(o2p);
            Assert.IsTrue(MatchFileContent("north.cs", o2p));
            Assert.IsTrue(MatchFileContent("metanorth.xml", ((MetaDataInfo)o2p).MetaDataAsString));
            Assert.IsTrue(((string)o2p).Contains("public class Product"));

            if (meta.MediaType == Media.Http)
            {
                Assert.Greater(meta.ServiceHeader.Count, 1);
            }
            else
            {
                Assert.AreEqual(meta.ServiceHeader.Count, 0);
            }

            Assert.AreEqual(meta.MetaDataVersion, version);

            Assert.AreEqual(((MetaDataInfo)o2p).MetaDataVersion, version, "metadataversion");

            Console.WriteLine(meta.ServiceHeader.DicToString());

            //implicit conversion test
        }
コード例 #36
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public void GenerateCodeUrlInvalidAuthenticateNoSettingTest()
        {
            string url = "http://asd-pc/odata2/api/northwind";
            string version = "4.0";
            int n = 26;
            var code = "";
            var metaString = "";
            //File.Delete("north.cs");
            //File.Delete("north.xml");

            var o2P = new O2P();
         var ex=   Assert.Throws<WebException>(async () =>
            {
                code = await o2P.GenerateAsync(new Uri(url), "hassan1", "123");
                //metaString = o2P.SaveMetaDataTo("north.xml");
            }); //.GeneratePoco());
            Debug.WriteLine(ex.Message);
            Console.WriteLine(code);
            //Assert.IsFalse(File.Exists("north.cs"));
            //Assert.IsFalse(File.Exists("north.xml"));
            Assert.IsEmpty(code);
            Assert.IsEmpty(metaString);
        }
コード例 #37
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public async void GenerateCodeUrlValidAuthenticateNoSettingTest()
        {
            string url = "http://asd-pc/odata2/api/northwind";
            string version = "4.0";
            int n=26;
            var o2P = new O2P();

            var code = await o2P.GenerateAsync(new Uri(url), "hassan", "123");
            Debug.WriteLine(code);
            StringAssert.Contains("public class Product", code);
        }
コード例 #38
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public void GeneratePocoFromNullUrlTest()
        {
            var url = "";
            var o2P = new O2P();
           
            Assert.Throws<UriFormatException>(async () =>
            {
               var code = await o2P.GenerateAsync(new Uri(url));
            });

        }
コード例 #39
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public void GeneratePocoFromEmtyXmlTest()
        {

            // <System.Exception> (Metadata is not available)
            var o2P = new O2P();
            var code = "";
            var metaString = "";
            Assert.Throws<ArgumentNullException>(() =>
            {
                code =  o2P.Generate("");
            //    metaString = await o2P.SaveMetaDataTo("north.xml");
            });

            Assert.IsEmpty(code);
            Assert.IsEmpty(metaString);

        }
コード例 #40
0
 public void GenerateCodeWithAttributeTest(string url)
 {
     string o2p = new O2P()
       .AddKeyAttribute()
         .AddRequiredAttribute()
         .AddNavigation()
         .AddTableAttribute()
           .SetUrl(url)
          .Generate("north.cs");
     //.SaveCodeTo();
     //Console.WriteLine(File.ReadAllText("north.cs"));
     Console.WriteLine(o2p);
     //Assert.IsTrue(MatchFileContent("north.cs", o2p));
     if (!o2p.Contains("[Key]")) Console.WriteLine("eeeeeeeeeeeeeeerror");
     else Console.WriteLine("exxxxxxxxxxxxist");
     // .SaveCodeTo();
     Console.WriteLine(o2p);
     //Assert.IsTrue(code.Contains("public class Product"));
     Assert.IsTrue(o2p.Contains("Key"));
     Assert.IsTrue(o2p.Contains("Required"));
     Assert.IsTrue(o2p.Contains("Table"));
 }
コード例 #41
0
        public void GenerateWithNoUrlTest()
        {
            //System.Exception : Url is empty
            string code = new O2P()
                // .SetUrl("http://services.odata.org/V4/Northwind/Northwind.svc")
               .AddKeyAttribute()
               .AddTableAttribute()
               .Generate();

            Assert.IsNull(code);


        }
コード例 #42
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        public async Task<string> BaseTest(string url, string version, int n, PocoSetting setting )
        {
            O2P o2P = new O2P(setting);

            var code = await o2P.GenerateAsync(new Uri(url) );
        //    var metaString = await o2P.SaveMetaDataTo("north.xml");
            if (o2P.MediaType == Media.Http)
            {
                Assert.Greater(o2P.ServiceHeader.Count, 0);
            }
            Debug.WriteLine(code);
            //Debug.WriteLine(metaString);

            Assert.AreEqual(o2P.MetaDataVersion, version);
            Assert.AreEqual(o2P.ClassList.Count, n);
            Assert.IsTrue(code.Contains(o2P.SchemaNamespace));
            //Assert.IsTrue(MatchFileContent("north.cs", code));
            //Assert.IsTrue(MatchFileContent("north.xml", metaString));
            return code;
        }
コード例 #43
0
ファイル: O2PTest.cs プロジェクト: moh-hassan/odata2poco
        [TestCase("http://www.google.com")] //not odata support

        //[ExpectedException(typeof(WebException))]
        //System.Net.WebException : The remote name could not be resolved: 'not_valid_url.com'
        //System.Net.WebException : The remote server returned an error: (404) Not Found.
        public async void GeneratePocoInvalidODataOrUrlTest(string url)
        {
            var o2P = new O2P();
            var code = "";
            var metaString = "";


            try
            {
                code = await o2P.GenerateAsync(new Uri(url));
                //metaString = o2P.SaveMetaDataTo("north.xml");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.FullExceptionMessage());
            }

            Assert.IsEmpty(code);
            Assert.IsEmpty(metaString);
        }