-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathFluentRfcReadTableTestCase.cs
195 lines (170 loc) · 6.51 KB
/
FluentRfcReadTableTestCase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using SharpSapRfc.Plain;
using SharpSapRfc.Soap;
using SharpSapRfc.Test.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
namespace SharpSapRfc.Test.TestCases
{
public class Soap_FluentRfcReadTableTestCase : FluentRfcReadTableTestCase
{
protected override SapRfcConnection GetConnection()
{
return new SoapSapRfcConnection("TST-SOAP");
}
}
public class Plain_FluentRfcReadTableTestCase : FluentRfcReadTableTestCase
{
protected override SapRfcConnection GetConnection()
{
return new PlainSapRfcConnection("TST");
}
}
public abstract class FluentRfcReadTableTestCase
{
protected abstract SapRfcConnection GetConnection();
[Fact]
public void ReadAllEntriesTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR").Read();
Assert.Equal(18, scarr.Count());
}
}
[Fact]
public void ReadTwoFieldsTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR").Select("CARRID", "CARRNAME").Read();
Assert.Equal(18, scarr.Count());
var aa = scarr.FirstOrDefault(x => x.Code == "AA");
Assert.Equal("AA", aa.Code);
Assert.Equal("American Airlines", aa.Name);
Assert.Equal(null, aa.Currency);
Assert.Equal(null, aa.Url);
}
}
[Fact]
public void ReadTwoFieldFromDeltaAirlineCompanyTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR")
.Select("CARRID", "CURRCODE")
.Where("CARRID = 'DL'")
.Read();
Assert.Equal(1, scarr.Count());
Assert.Equal("DL", scarr.ElementAt(0).Code);
Assert.Equal("USD", scarr.ElementAt(0).Currency);
Assert.Equal(null, scarr.ElementAt(0).Name);
Assert.Equal(null, scarr.ElementAt(0).Url);
Assert.Equal(0, scarr.ElementAt(0).Client);
}
}
[Fact]
public void StrongTypeEqualsConditionTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR")
.Select("CARRID", "CURRCODE")
.Where("CARRID", RfcReadTableOption.Equals, "DL")
.Read();
Assert.Equal(1, scarr.Count());
Assert.Equal("DL", scarr.ElementAt(0).Code);
Assert.Equal("USD", scarr.ElementAt(0).Currency);
Assert.Equal(null, scarr.ElementAt(0).Name);
Assert.Equal(null, scarr.ElementAt(0).Url);
Assert.Equal(0, scarr.ElementAt(0).Client);
}
}
[Fact]
public void StrongTypeNotEqualsConditionTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR")
.Select("CARRID", "CURRCODE")
.Where("CARRID", RfcReadTableOption.NotEquals, "DL")
.Read();
foreach (var company in scarr)
{
Assert.NotEqual("DL", company.Code);
}
}
}
[Fact]
public void StrongTypeGreaterAndLessThanConditionTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var flights = conn.Table<Flight>("SPFLI")
.Where("DISTANCE", RfcReadTableOption.GreaterThan, 8000)
.And("DISTANCE", RfcReadTableOption.LessThan, 10000)
.Read();
Assert.Equal(4, flights.Count());
}
}
[Fact]
public void StrongTypeGreaterEqualAndLessEqualThanConditionTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var flights = conn.Table<Flight>("SPFLI")
.Where("DISTANCE", RfcReadTableOption.GreaterOrEqualThan, 6030)
.And("DISTANCE", RfcReadTableOption.LessOrEqualThan, 9100)
.Read();
Assert.Equal(12, flights.Count());
}
}
[Fact]
public void ReadWithTwoAndConditionsTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR")
.Select("CARRID", "CURRCODE")
.Where("CARRID = 'DL'")
.And("CURRCODE = 'BRL'")
.Read();
Assert.Equal(0, scarr.Count());
}
}
[Fact]
public void ReadWithTwoOrConditionsTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR")
.Select("CARRID", "CURRCODE")
.Where("CARRID = 'DL'")
.Or("CARRID = 'AA'")
.Read();
Assert.Equal(2, scarr.Count());
}
}
[Fact]
public void TakeFirstCompanyTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var scarr = conn.Table<AirlineCompany>("SCARR").Take(1).Read();
Assert.Equal(1, scarr.Count());
}
}
[Fact]
public void FirstCompanyShouldBeDifferentThanSecondCompanyTest()
{
using (SapRfcConnection conn = this.GetConnection())
{
var firstCompany = conn.Table<AirlineCompany>("SCARR").Take(1).ReadOne();
var secondCompany = conn.Table<AirlineCompany>("SCARR").Skip(1).Take(1).ReadOne();
Assert.NotEqual(firstCompany.Code, secondCompany.Code);
}
}
}
}