Skip to content

Commit e487f7b

Browse files
committed
added support for !=NULL and =NULL for string if conditions
1 parent 800d7cc commit e487f7b

File tree

3 files changed

+66
-11
lines changed

3 files changed

+66
-11
lines changed

ObjectSemantics.NET.Tests/ObjectSemanticsTests.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine(double amount)
562562
[InlineData(null)]
563563
[InlineData("John Doe")]
564564
[InlineData("")]
565-
public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_StringTest(string studentName)
565+
public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_String_EquallsNull(string studentName)
566566
{
567567
//Create Model
568568
Student student = new Student { StudentName = studentName };
@@ -571,13 +571,61 @@ public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_StringTest(string
571571
{
572572
FileContents = @"
573573
{{ if-start:StudentName(=NULL) }}
574-
--is null--
574+
--ok-passed--
575+
{{ else-if }}
576+
--error-failed--
577+
{{ if-end:Balance }}"
578+
};
579+
string generatedTemplate = TemplateMapper.Map(student, template);
580+
string expectedResult = string.IsNullOrEmpty(studentName) ? "\r\n\r\n--ok-passed--\r\n" : "\r\n\r\n--error-failed--\r\n";
581+
Assert.Equal(expectedResult, generatedTemplate, false, true, true);
582+
}
583+
584+
[Theory]
585+
[InlineData(null)]
586+
[InlineData("John Doe")]
587+
[InlineData("")]
588+
public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_String_NotEquallsNull(string studentName)
589+
{
590+
//Create Model
591+
Student student = new Student { StudentName = studentName };
592+
//Template
593+
var template = new ObjectSemanticsTemplate
594+
{
595+
FileContents = @"
596+
{{ if-start:StudentName(!=NULL) }}
597+
--ok-passed--
598+
{{ else-if }}
599+
--error-failed--
600+
{{ if-end:Balance }}"
601+
};
602+
string generatedTemplate = TemplateMapper.Map(student, template);
603+
string expectedResult = (!string.IsNullOrEmpty(studentName)) ? "\r\n\r\n--ok-passed--\r\n" : "\r\n\r\n--error-failed--\r\n";
604+
Assert.Equal(expectedResult, generatedTemplate, false, true, true);
605+
}
606+
607+
608+
609+
[Theory]
610+
[InlineData(null)]
611+
[InlineData("John Doe")]
612+
[InlineData("")]
613+
public void Should_Act_On_IfCondition_Having_ElseIf_MultiLine_String_Equalls(string studentName)
614+
{
615+
//Create Model
616+
Student student = new Student { StudentName = studentName };
617+
//Template
618+
var template = new ObjectSemanticsTemplate
619+
{
620+
FileContents = @"
621+
{{ if-start:StudentName(=John Doe) }}
622+
--ok-passed--
575623
{{ else-if }}
576-
--not-null--
624+
--error-failed--
577625
{{ if-end:Balance }}"
578626
};
579627
string generatedTemplate = TemplateMapper.Map(student, template);
580-
string expectedResult = (string.IsNullOrEmpty(studentName)) ? "\r\n\r\n--is null--\r\n" : "\r\n\r\n--not-null--\r\n";
628+
string expectedResult = (studentName == "John Doe") ? "\r\n\r\n--ok-passed--\r\n" : "\r\n\r\n--error-failed--\r\n";
581629
Assert.Equal(expectedResult, generatedTemplate, false, true, true);
582630
}
583631

ObjectSemantics.NET/Extensions/ExtractedObjPropertyExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public static bool IsPropertyValueConditionPassed(this ExtractedObjProperty prop
1818
{
1919
string v1 = property.OriginalValue?.ToString()?.Trim().ToLower() ?? string.Empty;
2020
string v2 = GetConvertibleValue<string>(valueComparer)?.Trim().ToLower() ?? string.Empty;
21-
return string.Compare(v1, v2, true) == 0;
21+
switch (criteria)
22+
{
23+
case "=": return v1 == v2;
24+
case "!=": return v1 != v2;
25+
default:
26+
return string.Compare(v1, v2, true) == 0;
27+
}
2228
}
2329
else if (property.Type == typeof(int) || property.Type == typeof(double) || property.Type == typeof(long) || property.Type == typeof(float) || property.Type == typeof(decimal))
2430
{

ObjectSemantics.NET/ObjectSemantics.NET.csproj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
&gt; Mapping your object e.g. StudentDetails to a html Template that you define
77
&gt; Mapping a collection to enumerable or List to a html/text/ (predefined format)
88
</Description>
9-
<Copyright>Crudsoft Technologies @ 2022</Copyright>
9+
<Copyright>Crudsoft Technologies @ 2023</Copyright>
1010
<PackageProjectUrl>https://github.com/swagfin/ObjectSemantics.NET</PackageProjectUrl>
1111
<PackageIcon>icon.jpg</PackageIcon>
1212
<PackageIconUrl />
1313
<RepositoryUrl>https://github.com/swagfin/ObjectSemantics.NET</RepositoryUrl>
1414
<RepositoryType>Github</RepositoryType>
15-
<PackageReleaseNotes>v.5.1.3
16-
Added support for if condition statements with ElseIf</PackageReleaseNotes>
17-
<AssemblyVersion>5.1.4.1</AssemblyVersion>
18-
<FileVersion>5.1.4.1</FileVersion>
19-
<Version>5.1.4</Version>
15+
<PackageReleaseNotes>v.5.1.5
16+
Added support for if condition statements with ElseIf
17+
Optimized performance</PackageReleaseNotes>
18+
<AssemblyVersion>5.1.5.1</AssemblyVersion>
19+
<FileVersion>5.1.5.1</FileVersion>
20+
<Version>5.1.5</Version>
2021
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
2122
<ApplicationIcon></ApplicationIcon>
2223
<PackageReadmeFile>README.md</PackageReadmeFile>

0 commit comments

Comments
 (0)