Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created June 4, 2010 19:31
Show Gist options
  • Save jmarnold/425844 to your computer and use it in GitHub Desktop.
Save jmarnold/425844 to your computer and use it in GitHub Desktop.
[TestFixture]
public class When_Rendering_Entity_Details : InteractionContext<RenderEntityDetailsAction<Vendor, VendorRequestModel, VendorDetailsModel>>
{
private VendorRequestModel _requestModel;
protected override void BeforeEach()
{
_requestModel = new VendorRequestModel {VendorId = 1};
}
[Test]
public void An_Entity_Not_Found_Exception_Is_Thrown_If_The_Entity_Cannot_Be_Found()
{
MockFor<IEntityService>()
.Expect(s => s.Get<Vendor>(_requestModel))
.Return(null);
Exception<EntityNotFoundException<Vendor>>
.ShouldBeThrownBy(() => ClassUnderTest.Get(_requestModel));
}
[Test]
public void Entity_Is_Mapped_To_Details_Model_When_Found()
{
var vendor = Vendor
.CreateNew()
.WithVendorName("Test Vendor")
.WithAccountNumber("1234")
.WithVendorCode("TV")
.Build();
MockFor<IEntityService>()
.Expect(s => s.Get<Vendor>(_requestModel))
.Return(vendor);
var detailsModel = new VendorDetailsModel();
MockFor<IMappingRegistry>()
.Expect(r => r.Map<Vendor, VendorDetailsModel>(vendor))
.Return(detailsModel);
ClassUnderTest.Get(_requestModel).ShouldBeTheSameAs(detailsModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment