Permalink
Browse files

[#392] reintroduced Feature/Demo and fixed up its tests, refactoring …

…as needed

* introduced interfaces for a number of services to facilitate mocking
  • Loading branch information...
nickwesselman committed Jun 29, 2018
1 parent 92f6342 commit 3559aaa7c610677129912395fda41d596640b796
Showing with 212 additions and 67 deletions.
  1. +11 −0 Habitat.sln
  2. +5 −3 src/Feature/Demo/code/Controllers/DemoController.cs
  3. +0 −16 src/Feature/Demo/code/Models/ExperienceData.cs
  4. +2 −2 src/Feature/Demo/code/Pipelines/FakeTrackerData.cs
  5. +5 −9 src/Feature/Demo/code/Repositories/EngagementPlanStateRepository.cs
  6. +10 −0 src/Feature/Demo/code/Repositories/IEngagementPlanStateRepository.cs
  7. +9 −0 src/Feature/Demo/code/Repositories/IOnsiteBehaviorRepository.cs
  8. +10 −0 src/Feature/Demo/code/Repositories/IPageViewRepository.cs
  9. +9 −0 src/Feature/Demo/code/Repositories/IPersonalInfoRepository.cs
  10. +9 −0 src/Feature/Demo/code/Repositories/IReferralRepository.cs
  11. +9 −0 src/Feature/Demo/code/Repositories/IVisitsRepository.cs
  12. +2 −2 src/Feature/Demo/code/Repositories/OnsiteBehaviorRepository.cs
  13. +2 −2 src/Feature/Demo/code/Repositories/PageViewRepository.cs
  14. +2 −2 src/Feature/Demo/code/Repositories/PersonalInfoRepository.cs
  15. +2 −2 src/Feature/Demo/code/Repositories/ReferralRepository.cs
  16. +5 −5 src/Feature/Demo/code/Repositories/VisitsRepository.cs
  17. +2 −2 src/Feature/Demo/code/Services/DemoStateService.cs
  18. +38 −0 src/Feature/Demo/code/Services/ExperienceDataFactory.cs
  19. +7 −0 src/Feature/Demo/code/Services/IDemoStateService.cs
  20. +9 −0 src/Feature/Demo/code/Services/IExperienceDataFactory.cs
  21. +10 −0 src/Feature/Demo/code/Sitecore.Feature.Demo.csproj
  22. +29 −14 src/Feature/Demo/tests/Controllers/DemoControllerTests.cs
  23. +5 −2 src/Feature/Demo/tests/Repositories/CampaignRepositoryTests.cs
  24. +6 −4 src/Feature/Demo/tests/Repositories/VisitsRepositoryTests.cs
  25. +1 −1 src/Feature/Demo/tests/Services/BehaviorProfileDecoratorTests.cs
  26. +1 −1 src/Feature/Demo/tests/Services/ProfileProviderTests.cs
  27. +6 −0 src/Feature/Demo/tests/Sitecore.Feature.Demo.Tests.csproj
  28. +4 −0 src/Feature/Demo/tests/app.config
  29. +2 −0 src/Feature/Demo/tests/packages.config
@@ -197,6 +197,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.Foundation.Account
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.Feature.Accounts.Tests", "src\Feature\Accounts\Tests\Sitecore.Feature.Accounts.Tests.csproj", "{0049EB56-74D3-4F39-B0CE-2295E0747F09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sitecore.Feature.Demo.Tests", "src\Feature\Demo\tests\Sitecore.Feature.Demo.Tests.csproj", "{0CF1F7D9-121A-4E40-844C-612EC40345F5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -603,6 +605,14 @@ Global
{0049EB56-74D3-4F39-B0CE-2295E0747F09}.Release|Any CPU.Build.0 = Release|Any CPU
{0049EB56-74D3-4F39-B0CE-2295E0747F09}.Release|x64.ActiveCfg = Release|Any CPU
{0049EB56-74D3-4F39-B0CE-2295E0747F09}.Release|x64.Build.0 = Release|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Debug|x64.ActiveCfg = Debug|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Debug|x64.Build.0 = Debug|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Release|Any CPU.Build.0 = Release|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Release|x64.ActiveCfg = Release|Any CPU
{0CF1F7D9-121A-4E40-844C-612EC40345F5}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -692,6 +702,7 @@ Global
{85F735B7-9BEE-43C3-94DF-539CE267F0B9} = {BE813EFD-133F-4BDE-AD25-A67D16A218CA}
{461905E3-1D1F-4A75-A4AF-0EFBC0B35F07} = {E0B40F60-22F9-4BF1-9611-0FFAB7A0728F}
{0049EB56-74D3-4F39-B0CE-2295E0747F09} = {C7886F90-3A67-4889-8ACC-F07D42CFDBF0}
{0CF1F7D9-121A-4E40-844C-612EC40345F5} = {434D5F70-8EA5-4441-963F-293AE1D2D403}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6822019A-56D3-4695-9B9E-96F9D10ECD75}
@@ -21,11 +21,13 @@ namespace Sitecore.Feature.Demo.Controllers
[SkipAnalyticsTracking]
public class DemoController : SitecoreController
{
public DemoStateService DemoStateService { get; }
private IDemoStateService DemoStateService { get; }
private IExperienceDataFactory ExperienceDataFactory { get; }
public DemoController(DemoStateService demoStateService)
public DemoController(IDemoStateService demoStateService, IExperienceDataFactory experienceDataFactory)
{
this.DemoStateService = demoStateService;
this.ExperienceDataFactory = experienceDataFactory;
}
public ActionResult ExperienceData()
@@ -41,7 +43,7 @@ public ActionResult ExperienceData()
return new EmptyResult();
}
var experienceData = ServiceLocator.ServiceProvider.GetService<ExperienceData>();
var experienceData = this.ExperienceDataFactory.Get();
return this.View(experienceData);
}
@@ -1,23 +1,7 @@
namespace Sitecore.Feature.Demo.Models
{
using Sitecore.Feature.Demo.Repositories;
using Sitecore.Feature.Demo.Services;
using Sitecore.Foundation.Accounts.Providers;
using Sitecore.Foundation.DependencyInjection;
using Sitecore.Foundation.SitecoreExtensions.Services;
[Service(Lifetime = Lifetime.Transient)]
public class ExperienceData
{
public ExperienceData(VisitsRepository visitsRepository, PersonalInfoRepository personalInfoRepository, OnsiteBehaviorRepository onsiteBehaviorRepository, ReferralRepository referralRepository, ITrackerService trackerService)
{
this.Visits = visitsRepository.Get();
this.PersonalInfo = personalInfoRepository.Get();
this.OnsiteBehavior = onsiteBehaviorRepository.Get();
this.Referral = referralRepository.Get();
this.IsActive = trackerService.IsActive;
}
public Visits Visits { get; set; }
public PersonalInfo PersonalInfo { get; set; }
public OnsiteBehavior OnsiteBehavior { get; set; }
@@ -17,9 +17,9 @@ namespace Sitecore.Feature.Demo.Pipelines
public class FakeTrackerData
{
public DemoStateService DemoStateService { get; }
public IDemoStateService DemoStateService { get; }
public FakeTrackerData(DemoStateService demoStateService)
public FakeTrackerData(IDemoStateService demoStateService)
{
this.DemoStateService = demoStateService;
}
@@ -5,26 +5,22 @@ namespace Sitecore.Feature.Demo.Repositories
using System.Globalization;
using System.Linq;
using Sitecore.Analytics;
using Sitecore.DependencyInjection;
using Sitecore.Diagnostics;
using Sitecore.Feature.Demo.Models;
using Sitecore.Foundation.DependencyInjection;
using Sitecore.Marketing.Automation.Data;
using Sitecore.Marketing.Automation.Extensions;
using Sitecore.Marketing.Definitions;
using Sitecore.Marketing.Definitions.AutomationPlans.Model;
using Sitecore.XConnect.Collection.Model;
using Sitecore.Xdb.MarketingAutomation.Tracking.Extensions;
[Service]
public class EngagementPlanStateRepository
[Service(typeof(IEngagementPlanStateRepository))]
public class EngagementPlanStateRepository : IEngagementPlanStateRepository
{
public IActivityDescriptorRepository ActivityDescriptorRepository { get; }
public IDefinitionManager<IAutomationPlanDefinition> AutomationPlanDefinitionManager { get; }
private IDefinitionManager<IAutomationPlanDefinition> AutomationPlanDefinitionManager { get; }
public EngagementPlanStateRepository(IServiceProvider serviceProvider)
public EngagementPlanStateRepository(DefinitionManagerFactory definitionManagerFactory)
{
this.AutomationPlanDefinitionManager = serviceProvider.GetDefinitionManagerFactory().GetDefinitionManager<IAutomationPlanDefinition>();
this.AutomationPlanDefinitionManager = definitionManagerFactory.GetDefinitionManager<IAutomationPlanDefinition>();
}
public IEnumerable<EngagementPlanState> GetCurrent()
@@ -0,0 +1,10 @@
namespace Sitecore.Feature.Demo.Repositories
{
using System.Collections.Generic;
using Sitecore.Feature.Demo.Models;
public interface IEngagementPlanStateRepository
{
IEnumerable<EngagementPlanState> GetCurrent();
}
}
@@ -0,0 +1,9 @@
namespace Sitecore.Feature.Demo.Repositories
{
using Sitecore.Feature.Demo.Models;
public interface IOnsiteBehaviorRepository
{
OnsiteBehavior Get();
}
}
@@ -0,0 +1,10 @@
namespace Sitecore.Feature.Demo.Repositories
{
using Sitecore.Analytics.Tracking;
using Sitecore.Feature.Demo.Models;
public interface IPageViewRepository
{
PageView Get(ICurrentPageContext pageContext);
}
}
@@ -0,0 +1,9 @@
namespace Sitecore.Feature.Demo.Repositories
{
using Sitecore.Feature.Demo.Models;
public interface IPersonalInfoRepository
{
PersonalInfo Get();
}
}
@@ -0,0 +1,9 @@
namespace Sitecore.Feature.Demo.Repositories
{
using Sitecore.Feature.Demo.Models;
public interface IReferralRepository
{
Referral Get();
}
}
@@ -0,0 +1,9 @@
namespace Sitecore.Feature.Demo.Repositories
{
using Sitecore.Feature.Demo.Models;
public interface IVisitsRepository
{
Visits Get();
}
}
@@ -5,8 +5,8 @@
using Sitecore.Feature.Demo.Services;
using Sitecore.Foundation.DependencyInjection;
[Service]
public class OnsiteBehaviorRepository
[Service(typeof(IOnsiteBehaviorRepository))]
public class OnsiteBehaviorRepository : IOnsiteBehaviorRepository
{
private readonly PageEventRepository pageEventRepository;
private readonly OutcomeRepository outcomesRepository;
@@ -8,8 +8,8 @@
using Sitecore.Foundation.DependencyInjection;
using Sitecore.Foundation.Dictionary.Repositories;
[Service]
public class PageViewRepository
[Service(typeof(IPageViewRepository))]
public class PageViewRepository : IPageViewRepository
{
public PageView Get(ICurrentPageContext pageContext)
{
@@ -14,8 +14,8 @@
using Sitecore.Foundation.SitecoreExtensions.Extensions;
using Sitecore.XConnect.Collection.Model;
[Service]
public class PersonalInfoRepository
[Service(typeof(IPersonalInfoRepository))]
public class PersonalInfoRepository : IPersonalInfoRepository
{
private readonly LocationRepository locationRepository;
private readonly DeviceRepository deviceRepository;
@@ -8,8 +8,8 @@
using Sitecore.Feature.Demo.Models;
using Sitecore.Foundation.DependencyInjection;
[Service]
public class ReferralRepository
[Service(typeof(IReferralRepository))]
public class ReferralRepository : IReferralRepository
{
private readonly ICampaignRepository campaignRepository;
@@ -8,14 +8,14 @@
using Sitecore.Foundation.Accounts.Providers;
using Sitecore.Foundation.DependencyInjection;
[Service]
public class VisitsRepository
[Service(typeof(IVisitsRepository))]
public class VisitsRepository : IVisitsRepository
{
private readonly IContactFacetsProvider contactFacetsProvider;
private readonly EngagementPlanStateRepository engagementPlanStateRepository;
private readonly PageViewRepository pageViewRepository;
private readonly IEngagementPlanStateRepository engagementPlanStateRepository;
private readonly IPageViewRepository pageViewRepository;
public VisitsRepository(IContactFacetsProvider contactFacetsProvider, EngagementPlanStateRepository engagementPlanStateRepository, PageViewRepository pageViewRepository)
public VisitsRepository(IContactFacetsProvider contactFacetsProvider, IEngagementPlanStateRepository engagementPlanStateRepository, IPageViewRepository pageViewRepository)
{
this.contactFacetsProvider = contactFacetsProvider;
this.engagementPlanStateRepository = engagementPlanStateRepository;
@@ -5,8 +5,8 @@
using Sitecore.Configuration;
using Sitecore.Foundation.DependencyInjection;
[Service]
public class DemoStateService
[Service(typeof(IDemoStateService))]
public class DemoStateService : IDemoStateService
{
public DemoStateService(HttpContextBase httpContext)
{
@@ -0,0 +1,38 @@
namespace Sitecore.Feature.Demo.Services
{
using Sitecore.Feature.Demo.Models;
using Sitecore.Feature.Demo.Repositories;
using Sitecore.Foundation.DependencyInjection;
using Sitecore.Foundation.SitecoreExtensions.Services;
[Service(typeof(IExperienceDataFactory))]
public class ExperienceDataFactory : IExperienceDataFactory
{
private readonly IVisitsRepository visitsRepository;
private readonly IPersonalInfoRepository personalInfoRepository;
private readonly IOnsiteBehaviorRepository onsiteBehaviorRepository;
private readonly IReferralRepository referralRepository;
private readonly ITrackerService trackerService;
public ExperienceDataFactory(IVisitsRepository visitsRepository, IPersonalInfoRepository personalInfoRepository, IOnsiteBehaviorRepository onsiteBehaviorRepository, IReferralRepository referralRepository, ITrackerService trackerService)
{
this.visitsRepository = visitsRepository;
this.personalInfoRepository = personalInfoRepository;
this.onsiteBehaviorRepository = onsiteBehaviorRepository;
this.referralRepository = referralRepository;
this.trackerService = trackerService;
}
public ExperienceData Get()
{
return new ExperienceData
{
Visits = visitsRepository.Get(),
PersonalInfo = personalInfoRepository.Get(),
OnsiteBehavior = onsiteBehaviorRepository.Get(),
Referral = referralRepository.Get(),
IsActive = trackerService.IsActive
};
}
}
}
@@ -0,0 +1,7 @@
namespace Sitecore.Feature.Demo.Services
{
public interface IDemoStateService
{
bool IsDemoEnabled { get; }
}
}
@@ -0,0 +1,9 @@
namespace Sitecore.Feature.Demo.Services
{
using Sitecore.Feature.Demo.Models;
public interface IExperienceDataFactory
{
ExperienceData Get();
}
}
@@ -25,6 +25,7 @@
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
<Use64BitIISExpress />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -265,6 +266,12 @@
<Compile Include="Repositories\CampaignRepository.cs" />
<Compile Include="Repositories\DeviceRepository.cs" />
<Compile Include="Repositories\EngagementPlanStateRepository.cs" />
<Compile Include="Repositories\IEngagementPlanStateRepository.cs" />
<Compile Include="Repositories\IOnsiteBehaviorRepository.cs" />
<Compile Include="Repositories\IPageViewRepository.cs" />
<Compile Include="Repositories\IPersonalInfoRepository.cs" />
<Compile Include="Repositories\IReferralRepository.cs" />
<Compile Include="Repositories\IVisitsRepository.cs" />
<Compile Include="Repositories\PageEventRepository.cs" />
<Compile Include="Repositories\ICampaignRepository.cs" />
<Compile Include="Repositories\LocationRepository.cs" />
@@ -286,6 +293,9 @@
<Compile Include="Pipelines\RegisterWebApiRoutes.cs" />
<Compile Include="Services\BehaviorProfileDecorator.cs" />
<Compile Include="Services\DemoStateService.cs" />
<Compile Include="Services\ExperienceDataFactory.cs" />
<Compile Include="Services\IDemoStateService.cs" />
<Compile Include="Services\IExperienceDataFactory.cs" />
<Compile Include="Services\ProfileProvider.cs" />
<Compile Include="Services\IProfileProvider.cs" />
<Compile Include="Models\PatternMatch.cs" />
Oops, something went wrong.

0 comments on commit 3559aaa

Please sign in to comment.