Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Serialized in 'reverse' of standard Sitecore serialization, i.e. a role declares which roles it is a member of, instead of declaring which roles are in its role. * Reversing the order makes a lot more sense for real usage (e.g. "mysite\foo" is a member of "sitecore\authors" as opposed to having to serialize sitecore\authors to get that link * Thanks to OlegJytnik for an initial implementation using a hacked Sitecore format.
- Loading branch information
Showing
34 changed files
with
710 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Unicorn.Roles.Tests/Formatting/YamlRoleSerializationFormatterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.IO; | ||
using FluentAssertions; | ||
using Unicorn.Roles.Formatting; | ||
using Unicorn.Roles.Model; | ||
using Xunit; | ||
|
||
namespace Unicorn.Roles.Tests.Formatting | ||
{ | ||
public class YamlRoleSerializationFormatterTests | ||
{ | ||
[Fact] | ||
public void ShouldFormatSingleRole_AsExpected() | ||
{ | ||
var sut = new YamlRoleSerializationFormatter(); | ||
|
||
using (var ms = new MemoryStream()) | ||
{ | ||
sut.WriteSerializedRole(new SerializedRoleData("Test", new string[0], "Foo"), ms); | ||
|
||
ms.Seek(0, SeekOrigin.Begin); | ||
|
||
using (var reader = new StreamReader(ms)) | ||
{ | ||
var yml = reader.ReadToEnd(); | ||
|
||
yml.Should().Be(@"--- | ||
Role: Test | ||
"); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ShouldFormatRoleWithParents_AsExpected() | ||
{ | ||
var sut = new YamlRoleSerializationFormatter(); | ||
|
||
using (var ms = new MemoryStream()) | ||
{ | ||
sut.WriteSerializedRole(new SerializedRoleData("Test", new [] { "Foo", "Foo-Bar" }, "Foo"), ms); | ||
|
||
ms.Seek(0, SeekOrigin.Begin); | ||
|
||
using (var reader = new StreamReader(ms)) | ||
{ | ||
var yml = reader.ReadToEnd(); | ||
|
||
yml.Should().Be(@"--- | ||
Role: Test | ||
MemberOf: | ||
Role: Foo | ||
Role: ""Foo-Bar"" | ||
"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Unicorn.Roles.Tests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Unicorn.Roles.Tests")] | ||
[assembly: AssemblyCopyright("Copyright © 2016")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("7731968e-8a3e-4f36-860d-ce614c3d9114")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
52 changes: 52 additions & 0 deletions
52
src/Unicorn.Roles.Tests/RolePredicates/ConfigurationRolePredicateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Xml; | ||
using FluentAssertions; | ||
using Unicorn.Roles.Model; | ||
using Unicorn.Roles.RolePredicates; | ||
using Xunit; | ||
|
||
namespace Unicorn.Roles.Tests.RolePredicates | ||
{ | ||
public class ConfigurationRolePredicateTests | ||
{ | ||
[Theory] | ||
// Domain tests | ||
[InlineData(@"allfather\Foo", true)] | ||
[InlineData(@"AllFather\ZeusDogg", true)] | ||
// Excluded tests | ||
[InlineData(@"NOTME\haha", false)] | ||
[InlineData(@"haha", false)] | ||
// Pattern tests | ||
[InlineData(@"some\gonk droid", true)] | ||
[InlineData(@"some\fake", false)] | ||
public void Includes_MatchesExpectedPathResult(string testPath, bool expectedResult) | ||
{ | ||
var predicate = CreateTestPredicate(CreateTestConfiguration()); | ||
|
||
predicate.Includes(new SerializedRoleData(testPath, new string[0], @"C:\fake.yml")).IsIncluded.Should().Be(expectedResult); | ||
} | ||
|
||
private ConfigurationRolePredicate CreateTestPredicate(XmlNode configNode) | ||
{ | ||
return new ConfigurationRolePredicate(configNode); | ||
} | ||
|
||
private XmlNode CreateTestConfiguration() | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
string text; | ||
// ReSharper disable AssignNullToNotNullAttribute | ||
using (var textStreamReader = new StreamReader(assembly.GetManifestResourceStream("Unicorn.Roles.Tests.RolePredicates.TestConfiguration.xml"))) | ||
// ReSharper restore AssignNullToNotNullAttribute | ||
{ | ||
text = textStreamReader.ReadToEnd(); | ||
} | ||
|
||
var doc = new XmlDocument(); | ||
doc.LoadXml(text); | ||
|
||
return doc.DocumentElement; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<predicate> | ||
<include domain="allfather" /> | ||
<include domain="some" pattern="^gonk" /> | ||
</predicate> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{7731968E-8A3E-4F36-860D-CE614C3D9114}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Unicorn.Roles.Tests</RootNamespace> | ||
<AssemblyName>Unicorn.Roles.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="FluentAssertions, Version=4.3.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\FluentAssertions.4.3.2\lib\net45\FluentAssertions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="FluentAssertions.Core, Version=4.3.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\FluentAssertions.4.3.2\lib\net45\FluentAssertions.Core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Sitecore.Kernel"> | ||
<HintPath>..\..\lib\Sitecore\v7\Sitecore.Kernel.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Formatting\YamlRoleSerializationFormatterTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="RolePredicates\ConfigurationRolePredicateTests.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Rainbow\src\Rainbow\Rainbow.csproj"> | ||
<Project>{8ff75c8b-2a9e-4d95-91ad-333071813199}</Project> | ||
<Name>Rainbow</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Unicorn.Roles\Unicorn.Roles.csproj"> | ||
<Project>{cef534b3-ab68-45ce-afea-810d0e4a6613}</Project> | ||
<Name>Unicorn.Roles</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Unicorn\Unicorn.csproj"> | ||
<Project>{82c4441b-e11e-4601-b6b7-c5ad71b2ab70}</Project> | ||
<Name>Unicorn</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="RolePredicates\TestConfiguration.xml" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="FluentAssertions" version="4.3.2" targetFramework="net45" /> | ||
<package id="xunit" version="2.1.0" targetFramework="net45" /> | ||
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" /> | ||
<package id="xunit.assert" version="2.1.0" targetFramework="net45" /> | ||
<package id="xunit.core" version="2.1.0" targetFramework="net45" /> | ||
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" /> | ||
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" /> | ||
</packages> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.