Skip to content

Instantly share code, notes, and snippets.

@emiaj
Created June 10, 2011 18:54
Show Gist options
  • Select an option

  • Save emiaj/1019499 to your computer and use it in GitHub Desktop.

Select an option

Save emiaj/1019499 to your computer and use it in GitHub Desktop.
EngineEntryBuilderTester
using System;
using System.Collections.Generic;
using System.IO;
using FubuCore;
using FubuTestingSupport;
using NUnit.Framework;
using Rhino.Mocks;
using ZG.Core.Entities;
using ZG.Mvc.Engines;
using ZG.Mvc.Theming.Elements.Model;
using ZG.Mvc.Theming.Elements.Output;
using ZG.Mvc.Theming.Elements.Runtime;
namespace ZG.Mvc.Tests.Theming.Elements.Runtime
{
[TestFixture]
public class EngineEntryBuilderTester : InteractionContext<EngineEntryBuilder>
{
private TextWriter _writer;
private IEngineInvocations _invocations;
private IEngineInvocation[] _engineInvocations;
private IEnumerable<EngineEntry> _engineEntries;
protected override void beforeEach()
{
var zoneEntry = new ZoneEntry { Name = "top" };
var outputScope = MockFor<IOutputScope>();
_invocations = MockFor<IEngineInvocations>();
_engineInvocations = Services.CreateMockArrayFor<IEngineInvocation>(3);
_writer = new StringWriter();
_engineInvocations
.Each((invocation, i) => invocation
.Stub(x => x.Metadata<Widget>())
.Return(new Widget
{
Id = i,
DefaultActionName = "Default" + i,
EngineName = "Engine" + i,
Display = new Widget.DisplaySettings { Box = "Box" + i },
}));
_invocations.Expect(x => x.ByZone(zoneEntry.Name)).Return(_engineInvocations);
outputScope.Stub(x => x.Create(Arg<string>.Is.Anything)).Return(_writer);
ClassUnderTest.Parent = zoneEntry;
_engineEntries = ClassUnderTest.Build();
}
private void eachEngineEntry(Action<EngineEntry> assertion)
{
_engineEntries.Each(assertion);
}
private void eachEngineDescriptor(Action<EngineDescriptor, Widget> assertion)
{
_engineEntries.Each((x, i) =>
{
var widget = _engineInvocations[i].Metadata<Widget>();
assertion(x.Descriptor.As<EngineDescriptor>(), widget);
});
}
[Test]
public void the_engine_invocations_subset_come_from_the_engine_invocations_by_zone()
{
_invocations.VerifyAllExpectations();
}
[Test]
public void engine_entries_match_number_of_engine_invocations()
{
_engineEntries.ShouldHaveCount(_engineInvocations.Length);
}
[Test]
public void engine_entries_descriptor_is_of_enginedescriptor_type()
{
eachEngineEntry(x => x.Descriptor.ShouldBeOfType<EngineDescriptor>());
}
[Test]
public void engine_entries_box_matches_widget_box()
{
eachEngineDescriptor((x, w) => x.Box.ShouldEqual(w.Display.Box));
}
[Test]
public void engine_entries_engineid_matches_widget_id()
{
eachEngineDescriptor((x, w) => x.EngineId.ShouldEqual(w.Id));
}
[Test]
public void engine_entries_defaultentry_matches_widget_defaultactionname()
{
eachEngineDescriptor((x, w) => x.DefaultEntry.ShouldEqual(w.DefaultActionName));
}
[Test]
public void engine_entries_enginename_matches_widget_enginename()
{
eachEngineDescriptor((x, w) => x.EngineName.ShouldEqual(w.EngineName));
}
[Test]
public void engine_entries_view_should_be_of_engineview_type()
{
eachEngineEntry(x => x.View.ShouldBeOfType<EngineView>());
}
[Test]
public void engine_entries_writer_should_be_the_one_from_the_theme_engine_output()
{
eachEngineEntry(x => x.Writer().ShouldEqual(_writer));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment