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); }
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")); }
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); }
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())); }
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")); }
public void InheritanceDisabledWithInheritSettingTest() { var setting = new PocoSetting { Inherit = "MyBaseClass", }; var o2p = new O2P(setting); Assert.IsFalse(o2p.Setting.UseInheritance); }
public void GeneratePocoFromNullUrlTest() { var url = ""; var o2P = new O2P(); Assert.Throws <UriFormatException>(async() => { var code = await o2P.GenerateAsync(new Uri(url)); }); }
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)); }
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); }
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")); }
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); }
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)); }
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")); }
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")); }
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); }
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")); }
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); }
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); }
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")); }
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}")); }
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(); } }
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)); }
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")); }
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); }
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); }
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; } }
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); }
[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); }
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); }
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); }
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 }
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); }
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); }
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); }
public void GeneratePocoFromNullUrlTest() { var url = ""; var o2P = new O2P(); Assert.Throws<UriFormatException>(async () => { var code = await o2P.GenerateAsync(new Uri(url)); }); }
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); }
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")); }
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; }