Ejemplo n.º 1
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);

        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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()));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 6
0
        public void InheritanceDisabledWithInheritSettingTest()
        {
            var setting = new PocoSetting
            {
                Inherit = "MyBaseClass",
            };
            var o2p = new O2P(setting);

            Assert.IsFalse(o2p.Setting.UseInheritance);
        }
Ejemplo n.º 7
0
        public void GeneratePocoFromNullUrlTest()
        {
            var url = "";
            var o2P = new O2P();

            Assert.Throws <UriFormatException>(async() =>
            {
                var code = await o2P.GenerateAsync(new Uri(url));
            });
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 9
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));

        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
        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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 13
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));
     
 }
Ejemplo n.º 14
0
        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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 18
0
        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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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}"));
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 31
0
 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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

        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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
        }
Ejemplo n.º 36
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);
        }
Ejemplo n.º 37
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);
        }
Ejemplo n.º 38
0
        public void GeneratePocoFromNullUrlTest()
        {
            var url = "";
            var o2P = new O2P();
           
            Assert.Throws<UriFormatException>(async () =>
            {
               var code = await o2P.GenerateAsync(new Uri(url));
            });

        }
Ejemplo n.º 39
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);

        }
Ejemplo n.º 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"));
 }
Ejemplo n.º 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);


        }
Ejemplo n.º 42
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;
        }
Ejemplo n.º 43
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);
        }