Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 197 lines (189 sloc) 9.455 kb
0cc1d77 @visoft Added the local type to the service collections method and began clea…
authored
1 require 'spec_helper'
2
3 module OData
4 describe Service do
5 before(:all) do
6 stub_request(:get, /http:\/\/test\.com\/test\.svc\/\$metadata(?:\?.+)?/).
7 with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
8 to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sample_service/edmx_categories_products.xml", __FILE__)), :headers => {})
9
4744f94 @visoft Built URIs for function imports
authored
10 @cat_prod_service = OData::Service.new "http://test.com/test.svc"
0cc1d77 @visoft Added the local type to the service collections method and began clea…
authored
11 end
12 subject { @cat_prod_service }
13
14 context "methods" do
15 it { should respond_to :update_object }
16 it { should respond_to :delete_object }
17 it { should respond_to :save_changes }
18 it { should respond_to :load_property }
19 it { should respond_to :add_link }
20 it { should respond_to :execute }
21 it { should respond_to :partial? }
22 it { should respond_to :next }
23 it { should respond_to :classes }
24 it { should respond_to :class_metadata }
25 it { should respond_to :collections }
26 it { should respond_to :options }
9756dbc @visoft Added parsing of function imports
authored
27 it { should respond_to :function_imports }
0cc1d77 @visoft Added the local type to the service collections method and began clea…
authored
28
29 context "after parsing metadata" do
30 it { should respond_to :Products }
31 it { should respond_to :Categories }
32 it { should respond_to :AddToProducts }
33 it { should respond_to :AddToCategories }
34 end
35 end
36 context "collections method" do
18730ee @visoft add_link now fills the child's property
authored
37 subject { @cat_prod_service.collections }
0cc1d77 @visoft Added the local type to the service collections method and began clea…
authored
38 it { should include 'Products' }
39 it { should include 'Categories' }
40 it "should expose the edmx type of objects" do
300e64b @visoft Began work on implementing custom methods
authored
41 subject['Products'][:edmx_type].should eq 'RubyODataService.Product'
42 subject['Categories'][:edmx_type].should eq 'RubyODataService.Category'
0cc1d77 @visoft Added the local type to the service collections method and began clea…
authored
43 end
44 it "should expose the local model type" do
45 subject['Products'][:type].should eq Product
46 subject['Categories'][:type].should eq Category
47 end
48 end
18730ee @visoft add_link now fills the child's property
authored
49 context "class metadata" do
50 subject { @cat_prod_service.class_metadata }
51 it { should_not be_empty}
52 it { should have_key 'Product' }
53 it { should have_key 'Category' }
54 context "should have keys for each property" do
55 subject { @cat_prod_service.class_metadata['Category'] }
56 it { should have_key 'Id' }
57 it { should have_key 'Name' }
58 it { should have_key 'Products' }
59 it "should return a PropertyMetadata object for each property" do
60 subject['Id'].should be_a PropertyMetadata
61 subject['Name'].should be_a PropertyMetadata
62 subject['Products'].should be_a PropertyMetadata
63 end
64 it "should have correct PropertyMetadata for Category.Id" do
65 meta = subject['Id']
66 meta.name.should eq 'Id'
67 meta.type.should eq 'Edm.Int32'
68 meta.nullable.should eq false
69 meta.fc_target_path.should be_nil
70 meta.fc_keep_in_content.should be_nil
71 meta.nav_prop.should eq false
72 end
73 it "should have correct PropertyMetadata for Category.Name" do
74 meta = subject['Name']
75 meta.name.should eq 'Name'
76 meta.type.should eq 'Edm.String'
77 meta.nullable.should eq false
78 meta.fc_target_path.should be_nil
79 meta.fc_keep_in_content.should be_nil
80 meta.nav_prop.should eq false
81 end
82 it "should have correct PropertyMetadata for Category.Products" do
83 meta = subject['Products']
84 meta.name.should eq 'Products'
85 meta.type.should be_nil
86 meta.nullable.should eq true
87 meta.fc_target_path.should be_nil
88 meta.fc_keep_in_content.should be_nil
89 meta.nav_prop.should eq true
90 meta.association.should_not be_nil
91 end
92 end
93 end
9756dbc @visoft Added parsing of function imports
authored
94 context "function_imports method" do
95 subject { @cat_prod_service.function_imports }
96 it { should_not be_empty}
97 it { should have_key 'CleanDatabaseForTesting' }
98 it { should have_key 'EntityCategoryWebGet' }
99 it { should have_key 'EntitySingleCategoryWebGet' }
100 it "should expose the http method" do
101 subject['CleanDatabaseForTesting'][:http_method].should eq 'POST'
102 subject['EntityCategoryWebGet'][:http_method].should eq 'GET'
103 subject['EntitySingleCategoryWebGet'][:http_method].should eq 'GET'
104 end
105 it "should expose the return type" do
106 subject['CleanDatabaseForTesting'][:return_typo].should be_nil
107 subject['EntityCategoryWebGet'][:return_type].should eq Array
4744f94 @visoft Built URIs for function imports
authored
108 subject['EntityCategoryWebGet'][:inner_return_type].should eq Category
9756dbc @visoft Added parsing of function imports
authored
109 subject['EntitySingleCategoryWebGet'][:return_type].should eq Category
110 subject['EntitySingleCategoryWebGet'][:inner_return_type].should be_nil
4744f94 @visoft Built URIs for function imports
authored
111 subject['CategoryNames'][:return_type].should eq Array
112 subject['CategoryNames'][:inner_return_type].should eq String
9756dbc @visoft Added parsing of function imports
authored
113 end
114 it "should provide a hash of parameters" do
115 subject['EntityCategoryWebGet'][:parameters].should be_nil
116 subject['EntitySingleCategoryWebGet'][:parameters].should be_a Hash
117 subject['EntitySingleCategoryWebGet'][:parameters]['id'].should eq 'Edm.Int32'
118 end
4744f94 @visoft Built URIs for function imports
authored
119 context "after parsing function imports" do
120 subject { @cat_prod_service }
121 it { should respond_to :CleanDatabaseForTesting }
122 it { should respond_to :EntityCategoryWebGet }
123 it { should respond_to :EntitySingleCategoryWebGet }
124 it { should respond_to :CategoryNames }
125 end
126 context "error checking" do
127 subject { @cat_prod_service }
128 it "should throw an exception if a parameter is passed in to a method that doesn't require one" do
129 lambda { subject.EntityCategoryWebGet(1) }.should raise_error(ArgumentError, "wrong number of arguments (1 for 0)")
130 end
131 it "should throw and exception if more parameters are passed in than required by the function" do
132 lambda { subject.EntitySingleCategoryWebGet(1,2) }.should raise_error(ArgumentError, "wrong number of arguments (2 for 1)")
133 end
134 end
135 context "url and http method checks" do
136 subject { @cat_prod_service }
137 before { stub_request(:any, /http:\/\/test\.com\/test\.svc\/(.*)/) }
138 it "should call the correct url with the correct http method for a post with no parameters" do
139 subject.CleanDatabaseForTesting
140 a_request(:post, "http://test.com/test.svc/CleanDatabaseForTesting").should have_been_made
141 end
142 it "should call the correct url with the correct http method for a get with no parameters" do
143 subject.EntityCategoryWebGet
144 a_request(:get, "http://test.com/test.svc/EntityCategoryWebGet").should have_been_made
145 end
146 it "should call the correct url with the correct http method for a get with parameters" do
147 subject.EntitySingleCategoryWebGet(1)
148 a_request(:get, "http://test.com/test.svc/EntitySingleCategoryWebGet?id=1").should have_been_made
149 end
150 end
3b4ba45 @visoft Added initial support for custom WCF DS methods
authored
151 context "function import result parsing" do
152 subject { @cat_prod_service }
153 before(:each) do
154 stub_request(:post, "http://test.com/test.svc/CleanDatabaseForTesting").to_return(:status => 204)
155
156 stub_request(:get, "http://test.com/test.svc/EntityCategoryWebGet").
157 to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sample_service/result_entity_category_web_get.xml", __FILE__)), :headers => {})
158
159 stub_request(:get, "http://test.com/test.svc/EntitySingleCategoryWebGet?id=1").
160 to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sample_service/result_entity_single_category_web_get.xml", __FILE__)), :headers => {})
161
162 stub_request(:get, "http://test.com/test.svc/CategoryNames").
163 to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sample_service/result_category_names.xml", __FILE__)), :headers => {})
164
165 stub_request(:get, "http://test.com/test.svc/FirstCategoryId").
166 to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sample_service/result_first_category_id.xml", __FILE__)), :headers => {})
167 end
168 it "should return true if a function import post that returns successfully and doesn't have a return value (HTTP 204)" do
169 result = subject.CleanDatabaseForTesting
170 result.should be_true
171 end
172 it "should return a collection of entities for a collection" do
173 result = subject.EntityCategoryWebGet
174 result.should be_an Enumerable
175 result.first.should be_a Category
176 result.first.Name.should eq "Test Category"
177 end
178 it "should return a single entity if it isn't a collection" do
179 result = subject.EntitySingleCategoryWebGet(1)
180 result.should be_a Category
181 result.Name.should eq "Test Category"
182 end
183 it "should return a collection of primitive types" do
184 result = subject.CategoryNames
185 result.should be_an Enumerable
186 result.first.should be_a String
187 result.first.should eq "Test Category 1"
188 end
189 it "should return a single primitive type" do
190 result = subject.FirstCategoryId
191 result.should be_a Fixnum
192 result.should eq 1
193 end
194 end
9756dbc @visoft Added parsing of function imports
authored
195 end
0cc1d77 @visoft Added the local type to the service collections method and began clea…
authored
196 end
197 end
Something went wrong with that request. Please try again.