-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSometimesRequired.cs
More file actions
98 lines (83 loc) · 3.06 KB
/
Copy pathTestSometimesRequired.cs
File metadata and controls
98 lines (83 loc) · 3.06 KB
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
#region license
// Transformalize
// Configurable Extract, Transform, and Load
// Copyright © 2013-2023 Dale Newman
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using Autofac;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using Transformalize.Configuration;
using Transformalize.Containers.Autofac;
using Transformalize.Contracts;
using Transformalize.Providers.Console;
using Transformalize.Validate.Jint.Autofac;
namespace Tests {
[TestClass]
public class TestSometimesRequired {
[TestMethod]
public void Run() {
var logger = new ConsoleLogger();
const string xml = @"
<add name='TestProcess'>
<entities>
<add name='TestData'>
<rows>
<add id='1' store='Walmart' other='' />
<add id='2' store='Target' other='' />
<add id='3' store='Other' other='' />
<add id='4' store='Other' other='Costco' />
</rows>
<fields>
<add name='id' type='int' primary-key='true' />
<add name='store' />
<add name='other' v=""jint(
if(store === 'Other' && other === '') {
otherMessage = 'other is required';
false;
} else {
true;
}
)""/>
</fields>
<calculated-fields>
</calculated-fields>
</add>
</entities>
</add>";
using (var outer = new ConfigurationContainer(new JintValidateModule()).CreateScope(xml, logger)) {
var process = outer.Resolve<Process>();
if (process.Errors().Any()) {
foreach(var error in process.Errors()) {
System.Console.WriteLine(error);
}
return;
}
using (var inner = new Container(new JintValidateModule()).CreateScope(process, logger)) {
var controller = inner.Resolve<IProcessController>();
controller.Execute();
var rows = process.Entities.First().Rows;
Assert.AreEqual(true, rows[0]["otherValid"]);
Assert.AreEqual("", rows[0]["otherMessage"]);
Assert.AreEqual(true, rows[1]["otherValid"]);
Assert.AreEqual("", rows[1]["otherMessage"]);
Assert.AreEqual(false, rows[2]["otherValid"]);
Assert.AreEqual("other is required|", rows[2]["otherMessage"]);
Assert.AreEqual(true, rows[3]["otherValid"]);
Assert.AreEqual("", rows[3]["otherMessage"]);
}
}
}
}
}