Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit b641846

Browse files
committed
Initial Checkin
1 parent 4869ad1 commit b641846

File tree

141 files changed

+16799
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+16799
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/src/ServiceStack.Text.EnumMemberSerializer.UnitTests/bin
2+
/src/ServiceStack.Text.EnumMemberSerializer.UnitTests/obj
3+
/src/ServiceStack.Text.EnumMemberSerializer/bin
4+
/src/ServiceStack.Text.EnumMemberSerializer/obj
5+
/ReleasePackages
6+
/src/TestResults
7+
/src/*.suo

LICENSE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The BSD 2-Clause License
2+
3+
Copyright (c) 2013, AnthonyCarl, Chatham Financial Corporation
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7+
8+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

LICENSE_ServiceStack

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2007-2011, Demis Bellot, ServiceStack.
2+
http://www.servicestack.net
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of the ServiceStack nor the
13+
names of its contributors may be used to endorse or promote products
14+
derived from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

build.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tools\psake.4.2.0.1\tools\psake.cmd %*

default.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
if((Get-Module | Where-Object {$_.Name -eq "psake"}) -eq $null)
2+
{
3+
Write-Host "psake module not found, importing it"
4+
$scriptPath = Split-Path $MyInvocation.InvocationName
5+
Import-Module .\tools\psake.4.2.0.1\tools\psake.psm1
6+
}
7+
8+
properties {
9+
$configuration = "Release"
10+
$rootLocation = get-location
11+
$srcRoot = "$rootLocation\src"
12+
$projectBaseName = "ServiceStack.Text.EnumMemberSerializer"
13+
$csprojFile = "$srcRoot\$projectBaseName\$projectBaseName.csproj"
14+
$unitTestNamePart = "UnitTests"
15+
$testDll = "$srcRoot\$projectBaseName.$unitTestNamePart\bin\$configuration\$projectBaseName.$unitTestNamePart.dll"
16+
$slnFile = "$srcRoot\$projectBaseName.sln"
17+
$framework = "4.0"
18+
$xunitRunner = ".\tools\xunit.runners.1.9.1\tools\xunit.console.clr4.exe"
19+
$nugetOutputDir = ".\ReleasePackages"
20+
$nugetExe = "$rootLocation\tools\nuget\nuget.exe"
21+
}
22+
23+
task Default -depends Pack
24+
25+
task Clean {
26+
msbuild "$slnFile" /t:Clean /p:Configuration=$configuration
27+
}
28+
29+
task Compile -depends Clean {
30+
msbuild "$slnFile" /p:Configuration=$configuration
31+
}
32+
33+
task Test -depends Compile {
34+
.$xunitRunner "$testDll"
35+
}
36+
37+
task Pack -depends Test {
38+
mkdir -p "$nugetOutputDir" -force
39+
invoke-expression "& '$nugetExe' pack '$csprojFile' -Symbols -Properties Configuration=$configuration -OutputDirectory '$nugetOutputDir'"
40+
}
41+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Reflection.Emit;
7+
using SomeOtherNamespace;
8+
using Xunit;
9+
10+
namespace ServiceStack.Text.EnumMemberSerializer.UnitTests
11+
{
12+
public class AssemblyExtenstionsTests
13+
{
14+
[Fact]
15+
public void GetPublicEnums_UnitTestClassNoFilter_ReturnsBothEnums()
16+
{
17+
var assemblies = new List<Assembly> {Assembly.GetExecutingAssembly()};
18+
var publicEnums = assemblies.GetPublicEnums(EnumSerializerConfigurator.AlwaysTrueFilter);
19+
20+
Assert.Equal(2, publicEnums.Count);
21+
Assert.True(publicEnums.Contains(typeof (FakeTestingEnum)));
22+
Assert.True(publicEnums.Contains(typeof (DifferentNamespaceEnum)));
23+
}
24+
25+
[Fact]
26+
public void GetPublicEnums_UnitTestClassWithFilter_ReturnsDifferentNamespaceEnum()
27+
{
28+
var assemblies = new List<Assembly> {Assembly.GetExecutingAssembly()};
29+
var publicEnums = assemblies.GetPublicEnums(s => s.StartsWith("SomeOtherNamespace"));
30+
31+
Assert.Equal(1, publicEnums.Count);
32+
Assert.Equal(typeof (DifferentNamespaceEnum), publicEnums.First());
33+
}
34+
35+
[Fact]
36+
public void GetPublicEnums_DuplicateAssemblyInList_ReturnsBothDistinctEnums()
37+
{
38+
var assemblies = new List<Assembly> {Assembly.GetExecutingAssembly(), Assembly.GetExecutingAssembly()};
39+
var publicEnums = assemblies.GetPublicEnums(EnumSerializerConfigurator.AlwaysTrueFilter);
40+
41+
Assert.Equal(2, publicEnums.Count);
42+
Assert.True(publicEnums.Contains(typeof(FakeTestingEnum)));
43+
Assert.True(publicEnums.Contains(typeof(DifferentNamespaceEnum)));
44+
}
45+
46+
[Fact]
47+
public void GetPublicEnums_EmptyAssemblyList_EmptyTypes()
48+
{
49+
var emptyAssemblyList = new List<Assembly>();
50+
var publicEnums = emptyAssemblyList.GetPublicEnums(EnumSerializerConfigurator.AlwaysTrueFilter);
51+
Assert.Equal(0, publicEnums.Count);
52+
}
53+
54+
[Fact]
55+
public void GetPublicEnums_NullAssemblyList_EmptyTypes()
56+
{
57+
List<Assembly> emptyAssemblyList = null;
58+
var publicEnums = emptyAssemblyList.GetPublicEnums(EnumSerializerConfigurator.AlwaysTrueFilter);
59+
Assert.Equal(0, publicEnums.Count);
60+
}
61+
62+
[Fact]
63+
public void GetPublicEnums_UnitTestClassNullFilter_ReturnsBothEnums()
64+
{
65+
var assemblies = new List<Assembly> {Assembly.GetExecutingAssembly()};
66+
var publicEnums = assemblies.GetPublicEnums(null);
67+
68+
Assert.Equal(2, publicEnums.Count);
69+
Assert.True(publicEnums.Contains(typeof (FakeTestingEnum)));
70+
Assert.True(publicEnums.Contains(typeof (DifferentNamespaceEnum)));
71+
}
72+
73+
[Fact]
74+
public void GetPublicEnums_UnitTestClassWithAlwaysFalseFilter_ReturnsEmptyTypeList()
75+
{
76+
var assemblies = new List<Assembly> {Assembly.GetExecutingAssembly()};
77+
var publicEnums = assemblies.GetPublicEnums(s => false);
78+
79+
Assert.Equal(0, publicEnums.Count);
80+
}
81+
82+
[Fact]
83+
public void GetPublicEnums_ListOfNullAssemblies_ReturnsEmtpyTypeList()
84+
{
85+
var assemblies = new List<Assembly> {null};
86+
var publicEnums = assemblies.GetPublicEnums(EnumSerializerConfigurator.AlwaysTrueFilter);
87+
88+
Assert.Equal(0, publicEnums.Count);
89+
}
90+
91+
[Fact]
92+
public void GetPublicEnums_FilterThrowsException_ExceptionPassedUpInAggregate()
93+
{
94+
var assemblies = new List<Assembly> {Assembly.GetExecutingAssembly()};
95+
Assert.Throws<AggregateException>(
96+
() =>
97+
{
98+
try
99+
{
100+
assemblies.GetPublicEnums(s => { throw new NotImplementedException(); });
101+
}
102+
catch (AggregateException ex)
103+
{
104+
Assert.Equal(
105+
2,
106+
ex.InnerExceptions
107+
.ToList()
108+
.FindAll(x => x.GetType() == typeof (NotImplementedException))
109+
.Count);
110+
throw;
111+
}
112+
catch (Exception)
113+
{
114+
Assert.True(false, "Expected AggregateException");
115+
}
116+
});
117+
}
118+
}
119+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using Xunit;
3+
4+
namespace ServiceStack.Text.EnumMemberSerializer.UnitTests
5+
{
6+
public class CollectionExtensionsTests
7+
{
8+
[Fact]
9+
public void IsEmpty_NullList_True()
10+
{
11+
List<string> myList = null;
12+
Assert.True(myList.IsEmpty());
13+
}
14+
15+
[Fact]
16+
public void IsEmpty_EmptyList_True()
17+
{
18+
var myList = new List<string>();
19+
Assert.True(myList.IsEmpty());
20+
}
21+
22+
[Fact]
23+
public void IsEmpty_OneItemList_False()
24+
{
25+
var myList = new List<string> {"a value"};
26+
Assert.False(myList.IsEmpty());
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SomeOtherNamespace
2+
{
3+
public enum DifferentNamespaceEnum
4+
{
5+
DifferentValue,
6+
SomeValue
7+
}
8+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Runtime.Serialization;
2+
using Xunit;
3+
4+
namespace ServiceStack.Text.EnumMemberSerializer.UnitTests
5+
{
6+
public class EnumMemberAttributeExtensionsTests
7+
{
8+
private const string MyEnumMemberValue = "MyEnumMemberValue";
9+
10+
[Fact]
11+
public void MatchesDescription_ConstantNameUsed_True()
12+
{
13+
var attribute = new EnumMemberAttribute {Value = MyEnumMemberValue};
14+
Assert.True(attribute.MatchesDescription(MyEnumMemberValue));
15+
}
16+
17+
[Fact]
18+
public void MatchesDescription_NameCaseDiffers_True()
19+
{
20+
var attribute = new EnumMemberAttribute { Value = MyEnumMemberValue };
21+
Assert.True(attribute.MatchesDescription(MyEnumMemberValue.ToUpper()));
22+
}
23+
24+
[Fact]
25+
public void MatchesDescription_NullFieldNameNonNullDescript_False()
26+
{
27+
var attribute = new EnumMemberAttribute { Value = null };
28+
Assert.False(attribute.MatchesDescription(MyEnumMemberValue));
29+
}
30+
31+
[Fact]
32+
public void MatchesDescription_EmptyFieldNameNonNullDescript_False()
33+
{
34+
var attribute = new EnumMemberAttribute { Value = string.Empty };
35+
Assert.False(attribute.MatchesDescription(MyEnumMemberValue));
36+
}
37+
38+
[Fact]
39+
public void MatchesDescription_FieldNameAndDescriptDiffer_False()
40+
{
41+
var attribute = new EnumMemberAttribute { Value = "bad value" };
42+
Assert.False(attribute.MatchesDescription("won't match"));
43+
}
44+
45+
[Fact]
46+
public void MatchesDescription_NullAttribute_False()
47+
{
48+
EnumMemberAttribute attribute = null;
49+
Assert.False(attribute.MatchesDescription("won't match"));
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)