Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added tests for sharing policy activator

  • Loading branch information...
commit f9fa54339017c8282e6cf015d82daf98387a7e3f 1 parent 3b1b456
Alex Henning Johannessen ahjohannessen authored
1  src/FubuMVC.Spark.Tests/FubuMVC.Spark.Tests.csproj
@@ -115,6 +115,7 @@
115 115 <Compile Include="SparkModel\Policies\ViewPathPolicyTester.cs" />
116 116 <Compile Include="SparkModel\Sharing\RecordingSharingRegistrationTester.cs" />
117 117 <Compile Include="SparkModel\Sharing\SharingGraphTester.cs" />
  118 + <Compile Include="SparkModel\Sharing\SharingPolicyActivatorTester.cs" />
118 119 <Compile Include="SparkModel\Sharing\SharingRegistrationDiagnosticsTester.cs" />
119 120 <Compile Include="SparkModel\Sharing\SharingsGraphActivatorTester.cs" />
120 121 <Compile Include="SparkModel\Sharing\SparkDslReaderTester.cs" />
101 src/FubuMVC.Spark.Tests/SparkModel/Sharing/SharingPolicyActivatorTester.cs
... ... @@ -0,0 +1,101 @@
  1 +using System.Collections.Generic;
  2 +using Bottles;
  3 +using Bottles.Diagnostics;
  4 +using FubuMVC.Spark.SparkModel;
  5 +using FubuMVC.Spark.SparkModel.Sharing;
  6 +using FubuTestingSupport;
  7 +using NUnit.Framework;
  8 +using Rhino.Mocks;
  9 +
  10 +namespace FubuMVC.Spark.Tests.SparkModel.Sharing
  11 +{
  12 + [TestFixture]
  13 + public class SharingPolicyActivatorTester
  14 + {
  15 + private SharingGraph _graph;
  16 + private List<ISharingPolicy> _policies;
  17 + private SharingPolicyActivator _activator;
  18 + private IPackageLog _packageLog;
  19 + private SharingLogsCache _sharingLogs;
  20 +
  21 + [SetUp]
  22 + public void beforeEach()
  23 + {
  24 + _policies = new List<ISharingPolicy> {MockRepository.GenerateMock<ISharingPolicy>()};
  25 + _graph = new SharingGraph();
  26 + _packageLog = MockRepository.GenerateMock<IPackageLog>();
  27 + _sharingLogs = new SharingLogsCache();
  28 + _activator = new SharingPolicyActivator(_graph, _sharingLogs, _policies);
  29 + }
  30 +
  31 + [Test]
  32 + public void apply_policies_logs_policy()
  33 + {
  34 + _activator.ApplyPolicies(_packageLog);
  35 + _packageLog.AssertWasCalled(x => x.Trace("Applying policy [{0}].", _policies[0].ToString()));
  36 + }
  37 +
  38 + [Test]
  39 + public void apply_policies_sets_provenance()
  40 + {
  41 + _activator.ApplyPolicies(_packageLog);
  42 + _activator.Diagnostics.CurrentProvenance.ShouldEqual(_policies[0].ToString());
  43 + }
  44 +
  45 + [Test]
  46 + public void apply_policies_uses_diagnostics()
  47 + {
  48 + _activator.ApplyPolicies(_packageLog);
  49 + _policies[0].AssertWasCalled(x => x.Apply(_packageLog, _activator.Diagnostics));
  50 + }
  51 +
  52 + [Test]
  53 + public void register_as_global_logs_operation()
  54 + {
  55 + _activator.RegisterAppGlobal(_packageLog);
  56 + _packageLog.AssertWasCalled(x => x.Trace("Registering application as global sharing."));
  57 + }
  58 +
  59 + [Test]
  60 + public void register_as_global_invokes_diagnostics()
  61 + {
  62 + var inner = MockRepository.GenerateMock<ISharingRegistration>();
  63 + var fake = new SharingRegistrationDiagnostics(inner, _sharingLogs);
  64 +
  65 + _activator.Diagnostics = fake;
  66 + _activator.RegisterAppGlobal(_packageLog);
  67 +
  68 + fake.CurrentProvenance.ShouldEqual(FubuSparkConstants.HostOrigin);
  69 + inner.AssertWasCalled(x => x.Global(FubuSparkConstants.HostOrigin));
  70 + }
  71 +
  72 + [Test]
  73 + public void compile_dependencies_logs_all_provenances()
  74 + {
  75 + var packages = new List<IPackageInfo>
  76 + {
  77 + new PackageInfo("a"),
  78 + new PackageInfo("b")
  79 + };
  80 +
  81 + _activator.CompileDependencies(packages, _packageLog);
  82 +
  83 + _packageLog.AssertWasCalled(x => x.Trace("Compiling dependencies for [{0}]", "a, b, Host"));
  84 + }
  85 +
  86 + [Test]
  87 + public void compile_dependencies_implicit_adds_host_as_provenance()
  88 + {
  89 + var packages = new List<IPackageInfo>
  90 + {
  91 + new PackageInfo("a"),
  92 + new PackageInfo("b")
  93 + };
  94 +
  95 + _graph.Global("x");
  96 + _activator.CompileDependencies(packages, _packageLog);
  97 +
  98 + _graph.SharingsFor(FubuSparkConstants.HostOrigin).ShouldContain("x");
  99 + }
  100 + }
  101 +}
42 src/FubuMVC.Spark/SparkModel/Sharing/SharingPolicyActivator.cs
@@ -5,48 +5,58 @@
5 5
6 6 namespace FubuMVC.Spark.SparkModel.Sharing
7 7 {
8   - // UT
9 8 public class SharingPolicyActivator : IActivator
10 9 {
11 10 private readonly SharingGraph _graph;
12 11 private readonly SharingLogsCache _logs;
13 12 private readonly IEnumerable<ISharingPolicy> _policies;
14   - private readonly SharingRegistrationDiagnostics _diagnostics;
15 13
16 14 public SharingPolicyActivator(SharingGraph graph, SharingLogsCache logs, IEnumerable<ISharingPolicy> policies)
17 15 {
18 16 _graph = graph;
19 17 _logs = logs;
20 18 _policies = policies;
21   - _diagnostics = new SharingRegistrationDiagnostics(_graph, _logs);
  19 +
  20 + Diagnostics = new SharingRegistrationDiagnostics(_graph, _logs);
22 21 }
23 22
24 23 public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log)
25 24 {
  25 + ApplyPolicies(log);
  26 + RegisterAppGlobal(log);
  27 + CompileDependencies(packages, log);
  28 + }
  29 +
  30 + public void ApplyPolicies(IPackageLog log)
  31 + {
26 32 _policies.Each(p =>
27 33 {
28 34 var policyName = p.ToString();
29   -
30   - log.Trace("Applying policy [{0}].", policyName);
31   - _diagnostics.SetCurrentProvenance(policyName);
32   -
33   - p.Apply(log, _diagnostics);
34   - });
35 35
36   - log.Trace("Registering application as global sharing.");
  36 + log.Trace("Applying policy [{0}].", policyName);
  37 + Diagnostics.SetCurrentProvenance(policyName);
37 38
38   - _diagnostics.SetCurrentProvenance(FubuSparkConstants.HostOrigin);
39   - _diagnostics.Global(FubuSparkConstants.HostOrigin);
40   -
  39 + p.Apply(log, Diagnostics);
  40 + });
  41 + }
  42 +
  43 + public void CompileDependencies(IEnumerable<IPackageInfo> packages, IPackageLog log)
  44 + {
41 45 var provenances = packages.Select(p => p.Name).Union(new[] { FubuSparkConstants.HostOrigin }).ToArray();
  46 +
42 47 log.Trace("Compiling dependencies for [{0}]", provenances.Join(", "));
43 48
44   - _graph.CompileDependencies(provenances);
  49 + _graph.CompileDependencies(provenances);
45 50 }
46 51
47   - public SharingRegistrationDiagnostics Diagnostics
  52 + public void RegisterAppGlobal(IPackageLog log)
48 53 {
49   - get { return _diagnostics; }
  54 + log.Trace("Registering application as global sharing.");
  55 +
  56 + Diagnostics.SetCurrentProvenance(FubuSparkConstants.HostOrigin);
  57 + Diagnostics.Global(FubuSparkConstants.HostOrigin);
50 58 }
  59 +
  60 + public SharingRegistrationDiagnostics Diagnostics { get; set; }
51 61 }
52 62 }

0 comments on commit f9fa543

Please sign in to comment.
Something went wrong with that request. Please try again.