Skip to content

Commit eaab88f

Browse files
committed
add specs for ms_dynamic_nav
1 parent 5db03b4 commit eaab88f

5 files changed

Lines changed: 222 additions & 0 deletions

File tree

spec/dynamics_nav_spec.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
require 'spec_helper'
2+
3+
module OData
4+
describe Service do
5+
6+
describe "handling of Microsoft Dynamics Nav OData WebService" do
7+
let(:username) { "blabla" }
8+
let(:password) { "" }
9+
10+
before(:each) do
11+
auth_string = "#{username}:#{password}"
12+
authorization_header = { authorization: "Basic #{Base64::encode64(auth_string).strip}" }
13+
headers = DEFAULT_HEADERS.merge(authorization_header)
14+
15+
# Required for the build_classes method
16+
stub_request(:get, "http://test.com/nav.svc/$metadata").
17+
with(:headers => headers).
18+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_dynamics_nav/edmx_ms_dynamics_nav.xml", __FILE__)), :headers => {})
19+
20+
stub_request(:get, "http://test.com/nav.svc/Customer").
21+
with(:headers => headers).
22+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_dynamics_nav/result_customer.xml", __FILE__)), :headers => {})
23+
24+
stub_request(:get, "http://test.com/nav.svc/Customer('100013')").
25+
with(:headers => headers).
26+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_dynamics_nav/result_customer.xml", __FILE__)), :headers => {})
27+
28+
stub_request(:get, "http://test.com/nav.svc/Customer(100013)").
29+
with(:headers => headers).
30+
to_return(:status => 400, :body => File.new(File.expand_path("../fixtures/ms_dynamics_nav/result_customer_error.xml", __FILE__)), :headers => {})
31+
32+
stub_request(:get, "http://test.com/nav.svc/SalesOrder(Document_Type='Order',No='AB-1600013')").
33+
with(:headers => headers).
34+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_dynamics_nav/result_sales_order.xml", __FILE__)), :headers => {})
35+
end
36+
37+
after(:all) do
38+
Object.send(:remove_const, 'Customer')
39+
Object.send(:remove_const, 'SalesOrder')
40+
end
41+
42+
it "should successfully parse null valued string properties" do
43+
svc = OData::Service.new "http://test.com/nav.svc/", { :username => username, :password => password, :verify_ssl => false }
44+
svc.Customer
45+
results = svc.execute
46+
results.first.should be_a_kind_of(Customer)
47+
end
48+
49+
it "should return an error if a customer is accessed with integer id" do
50+
svc = OData::Service.new "http://test.com/nav.svc/", { :username => username, :password => password, :verify_ssl => false }
51+
byebug
52+
svc.Customer(100013)
53+
expect { svc.execute }.to raise_error(OData::ServiceError) { |error|
54+
error.http_code.should eq 400
55+
error.message.should eq "Server returned error but no message."
56+
}
57+
end
58+
59+
it "should successfully return a customer by its string id" do
60+
svc = OData::Service.new "http://test.com/nav.svc/", { :username => username, :password => password, :verify_ssl => false }
61+
svc.Customer('100013')
62+
results = svc.execute
63+
results.first.should be_a_kind_of(Customer)
64+
end
65+
66+
it "should successfully return a sales_order by its composite string ids" do
67+
svc = OData::Service.new "http://test.com/nav.svc/", { :username => username, :password => password, :verify_ssl => false }
68+
svc.SalesOrder(Document_Type: 'Order', No: 'AB-1600013')
69+
results = svc.execute
70+
results.first.should be_a_kind_of(Customer)
71+
end
72+
73+
end
74+
end
75+
end
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<edmx:Edmx
2+
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
3+
<edmx:DataServices
4+
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0">
5+
<Schema
6+
xmlns="http://schemas.microsoft.com/ado/2007/05/edm" Namespace="NAV">
7+
<EntityType Name="Customer">
8+
<Key>
9+
<PropertyRef Name="No"/>
10+
</Key>
11+
<Property Name="No" Type="Edm.String" Nullable="false"/>
12+
<Property Name="Name" Type="Edm.String"/>
13+
<Property Name="Address" Type="Edm.String"/>
14+
<Property Name="Address_2" Type="Edm.String"/>
15+
<Property Name="Post_Code" Type="Edm.String"/>
16+
<Property Name="City" Type="Edm.String"/>
17+
<Property Name="Country_Region_Code" Type="Edm.String"/>
18+
<Property Name="ETag" Type="Edm.String" ConcurrencyMode="Fixed"/>
19+
</EntityType>
20+
<EntityType Name="SalesOrder">
21+
<Key>
22+
<PropertyRef Name="Document_Type"/>
23+
<PropertyRef Name="No"/>
24+
</Key>
25+
<Property Name="Document_Type" Type="Edm.String" Nullable="false"/>
26+
<Property Name="No" Type="Edm.String" Nullable="false"/>
27+
<Property Name="Sell_to_Customer_No" Type="Edm.String"/>
28+
<Property Name="ETag" Type="Edm.String" ConcurrencyMode="Fixed"/>
29+
<NavigationProperty Name="SalesOrderSalesLines" Relationship="NAV.SalesOrder_SalesOrderSalesLines" ToRole="SalesOrderSalesLines" FromRole="SalesOrder"/>
30+
</EntityType>
31+
<EntityType Name="SalesOrderSalesLines">
32+
<Key>
33+
<PropertyRef Name="Document_No"/>
34+
<PropertyRef Name="Document_Type"/>
35+
<PropertyRef Name="Line_No"/>
36+
</Key>
37+
<Property Name="Document_Type" Type="Edm.String" Nullable="false"/>
38+
<Property Name="Document_No" Type="Edm.String" Nullable="false"/>
39+
<Property Name="Line_No" Type="Edm.Int32" Nullable="false"/>
40+
<Property Name="Position_No" Type="Edm.Int32"/>
41+
<Property Name="Type" Type="Edm.String"/>
42+
<Property Name="No" Type="Edm.String"/>
43+
</EntityType>
44+
<EntityType Name="Company">
45+
<Key>
46+
<PropertyRef Name="Name"/>
47+
</Key>
48+
<Property Name="Name" Type="Edm.String" Nullable="false"/>
49+
<NavigationProperty Name="Customer" Relationship="NAV.Company_Customer" ToRole="Customer" FromRole="Company"/>
50+
<NavigationProperty Name="SalesOrder" Relationship="NAV.Company_SalesOrder" ToRole="SalesOrder" FromRole="Company"/>
51+
<NavigationProperty Name="SalesOrderSalesLines" Relationship="NAV.Company_SalesOrderSalesLines" ToRole="SalesOrderSalesLines" FromRole="Company"/>
52+
</EntityType>
53+
<Association Name="SalesOrder_SalesOrderSalesLines">
54+
<End Type="NAV.SalesOrderSalesLines" Role="SalesOrderSalesLines" Multiplicity="*"/>
55+
<End Type="NAV.SalesOrder" Role="SalesOrder" Multiplicity="*"/>
56+
</Association>
57+
<Association Name="Company_Customer">
58+
<End Type="NAV.Customer" Role="Customer" Multiplicity="*"/>
59+
<End Type="NAV.Company" Role="Company" Multiplicity="*"/>
60+
</Association>
61+
<Association Name="Company_SalesOrder">
62+
<End Type="NAV.SalesOrder" Role="SalesOrder" Multiplicity="*"/>
63+
<End Type="NAV.Company" Role="Company" Multiplicity="*"/>
64+
</Association>
65+
<Association Name="Company_SalesOrderSalesLines">
66+
<End Type="NAV.SalesOrderSalesLines" Role="SalesOrderSalesLines" Multiplicity="*"/>
67+
<End Type="NAV.Company" Role="Company" Multiplicity="*"/>
68+
</Association>
69+
<EntityContainer Name="NAV" m:IsDefaultEntityContainer="true">
70+
<EntitySet Name="Customer" EntityType="NAV.Customer"/>
71+
<EntitySet Name="SalesOrder" EntityType="NAV.SalesOrder"/>
72+
<EntitySet Name="SalesOrderSalesLines" EntityType="NAV.SalesOrderSalesLines"/>
73+
<AssociationSet Name="SalesOrder_SalesOrderSalesLines_SalesOrderSalesLines" Association="NAV.SalesOrder_SalesOrderSalesLines">
74+
<End Role="SalesOrder" EntitySet="SalesOrder"/>
75+
<End Role="SalesOrderSalesLines" EntitySet="SalesOrderSalesLines"/>
76+
</AssociationSet>
77+
<AssociationSet Name="Company_Customer_Customer" Association="NAV.Company_Customer">
78+
<End Role="Company" EntitySet="Company"/>
79+
<End Role="Customer" EntitySet="Customer"/>
80+
</AssociationSet>
81+
<AssociationSet Name="Company_SalesOrder_SalesOrder" Association="NAV.Company_SalesOrder">
82+
<End Role="Company" EntitySet="Company"/>
83+
<End Role="SalesOrder" EntitySet="SalesOrder"/>
84+
</AssociationSet>
85+
<AssociationSet Name="Company_SalesOrderSalesLines_SalesOrderSalesLines" Association="NAV.Company_SalesOrderSalesLines">
86+
<End Role="Company" EntitySet="Company"/>
87+
<End Role="SalesOrderSalesLines" EntitySet="SalesOrderSalesLines"/>
88+
</AssociationSet>
89+
</EntityContainer>
90+
</Schema>
91+
</edmx:DataServices>
92+
</edmx:Edmx>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<entry xml:base="http://navapp1.office.zwick-edelstahl.de:7178/ZWICK-TEST-WEB/OData/"
3+
xmlns="http://www.w3.org/2005/Atom"
4+
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
5+
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/&quot;'28%3BEgAAAAJ7BTEAMAAwADAAMAAAAAAA8%3B791241770%3B'&quot;">
6+
<id>http://navapp1.office.zwick-edelstahl.de:7178/ZWICK-TEST-WEB/OData/Customer('10000')</id>
7+
<category term="NAV.Customer" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
8+
<link rel="edit" title="Customer" href="Customer('10000')" />
9+
<title />
10+
<updated>2017-08-02T20:02:42Z</updated>
11+
<author>
12+
<name />
13+
</author>
14+
<content type="application/xml">
15+
<m:properties>
16+
<d:No>10000</d:No>
17+
<d:Name>Contoso AG</d:Name>
18+
<d:Address></d:Address>
19+
<d:Address_2></d:Address_2>
20+
<d:Post_Code></d:Post_Code>
21+
<d:City>Berlin</d:City>
22+
<d:Country_Region_Code>DE</d:Country_Region_Code>
23+
<d:ETag>28;EgAAAAJ7BTEAMAAwADAAMAAAAAAA8;791241770;</d:ETag>
24+
</m:properties>
25+
</content>
26+
</entry>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<m:error
2+
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
3+
<m:code/>
4+
<m:message xml:lang="de-DE">Bad Request - Error in query syntax.</m:message>
5+
</m:error>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<entry xml:base="http://navapp1.office.zwick-edelstahl.de:7178/ZWICK-TEST-WEB/OData/"
3+
xmlns="http://www.w3.org/2005/Atom"
4+
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
5+
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/&quot;'52%3BJAAAAACLAQAAAAJ7%2F0EAQgAtADEANgAwADAAMAAxADMAAAAAAA%3D%3D8%3B824184700%3B'&quot;">
6+
<id>http://navapp1.office.zwick-edelstahl.de:7178/ZWICK-TEST-WEB/OData/SalesOrder(Document_Type='Order',No='AB-1600013')</id>
7+
<category term="NAV.SalesOrder" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
8+
<link rel="edit" title="SalesOrder" href="SalesOrder(Document_Type='Order',No='AB-1600013')" />
9+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SalesOrderSalesLines" type="application/atom+xml;type=feed" title="SalesOrderSalesLines" href="SalesOrder(Document_Type='Order',No='AB-1600013')/SalesOrderSalesLines" />
10+
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SalesOrderRouting_Status_View" type="application/atom+xml;type=feed" title="SalesOrderRouting_Status_View" href="SalesOrder(Document_Type='Order',No='AB-1600013')/SalesOrderRouting_Status_View" />
11+
<title />
12+
<updated>2017-08-02T19:53:22Z</updated>
13+
<author>
14+
<name />
15+
</author>
16+
<content type="application/xml">
17+
<m:properties>
18+
<d:Document_Type>Order</d:Document_Type>
19+
<d:No>AB-1600013</d:No>
20+
<d:Sell_to_Customer_No>11101</d:Sell_to_Customer_No>
21+
<d:ETag>52;JAAAAACLAQAAAAJ7/0EAQgAtADEANgAwADAAMAAxADMAAAAAAA==8;824184700;</d:ETag>
22+
</m:properties>
23+
</content>
24+
</entry>

0 commit comments

Comments
 (0)