-
Notifications
You must be signed in to change notification settings - Fork 14
/
RfcContextTests.cs
115 lines (92 loc) · 3.74 KB
/
RfcContextTests.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dbosoft.YaNco;
using Dbosoft.YaNco.Live;
using Dbosoft.YaNco.Traits;
using Dbosoft.YaNco.TypeMapping;
using LanguageExt;
using Moq;
using Xunit;
using YaNco.Core.Tests.RfcMock;
namespace YaNco.Core.Tests
{
public class RfcContextTests
{
[Fact]
public async Task Connection_Is_Created()
{
var connectionIO = new Mock<SAPRfcConnectionIO>();
connectionIO.SetupOpenConnection(out _);
var connFunc = new ConnectionBuilder(new Dictionary<string, string>())
.ConfigureRuntime(c => c.UseSettingsFactory((l, m, o) =>
new SAPRfcRuntimeSettings(l, m, o)
{
RfcConnectionIO = connectionIO.Object,
RfcFunctionIO = new Mock<SAPRfcFunctionIO>().Object
})).Build();
using (var rfcContext = new RfcContext(connFunc))
{
await rfcContext.GetConnection().IfLeft(l => l.Throw());
}
connectionIO.VerifyAll();
}
[Fact]
public async Task Function_Is_Called()
{
var connectionIO = new Mock<SAPRfcConnectionIO>();
connectionIO.SetupOpenConnection(out var connHandle);
var functionIO = new Mock<SAPRfcFunctionIO>();
var dataIO = new Mock<SAPRfcDataIO>();
functionIO.SetupFunction("A_FUNC", connHandle,
h =>
{
dataIO.Setup(x => x.GetFieldValue<string>(h, It.IsAny<Func<Either<RfcError, RfcFieldInfo>>>()
))
.Returns("VALUE");
});
var connFunc = new ConnectionBuilder(new Dictionary<string, string>())
.ConfigureRuntime(c => c.UseSettingsFactory((l, m, o) =>
new SAPRfcRuntimeSettings(l, m, o)
{
RfcConnectionIO = connectionIO.Object,
RfcFunctionIO = functionIO.Object,
RfcDataIO = dataIO.Object
})).Build();
using (var rfcContext = new RfcContext(connFunc))
{
await rfcContext.CallFunction("A_FUNC",
f => f.GetField<string>("FIELD"),
f => f)
.IfLeft(l => { l.Throw(); });
}
connectionIO.VerifyAll();
functionIO.VerifyAll();
}
[Fact]
public async Task Can_access_buildIn_SAPRfcRuntime()
{
var connectionIO = new Mock<SAPRfcConnectionIO>();
connectionIO.SetupOpenConnection(out _);
var fieldMapper = new Mock<IFieldMapper>();
var connFunc = new ConnectionBuilder(new Dictionary<string, string>())
.ConfigureRuntime(c => c.UseSettingsFactory((l, _, o) =>
new SAPRfcRuntimeSettings(l, fieldMapper.Object, o)
{
RfcConnectionIO = connectionIO.Object,
RfcFunctionIO = new Mock<SAPRfcFunctionIO>().Object
})).Build();
using (var rfcContext = new RfcContext(connFunc))
{
await rfcContext.GetConnection().IfLeft(l => l.Throw());
var actFieldMapper = await rfcContext.RunIO( _ =>
from rt in Prelude.runtime<SAPRfcRuntime>()
select rt.Env.Settings.FieldMapper
)
.IfLeft(new DefaultFieldMapper(null));
Assert.Equal(fieldMapper.Object, actFieldMapper);
}
connectionIO.VerifyAll();
}
}
}