Skip to content

Instantly share code, notes, and snippets.

Nathanael Mann cardinal252

Block or report user

Report or block cardinal252

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View LanguageAgnosticGetModelFromView.cs
using Glass.Mapper.Sc;
using Glass.Mapper.Sc.Pipelines.Response;
using XXX.Common.IoC;
using XXX.Core.Sc.Abstractions.Context;
using Sitecore.Mvc.Pipelines.Response.GetModel;
namespace XXX.Web
{
public class LanguageAgnosticGetModelFromView : GetModelFromView
{
@cardinal252
cardinal252 / LazyString
Last active Aug 10, 2016
Basic LazyString to help with Glass codegen + usage
View LazyString
public class GlassLazy<T> : Lazy<T>
{
public GlassLazy(Func<object> lazy) : base(() => (T)lazy())
{
}
public override string ToString()
{
return Value.ToString();
}
@cardinal252
cardinal252 / gist:43e3eef5d472ce1c68e5
Last active Nov 10, 2015
Glass Context Provider vs Direct Context
View gist:43e3eef5d472ce1c68e5
using System;
using System.Diagnostics;
using xxx.App_Start;
using Glass.Mapper.Sc;
using Xunit;
namespace xxx.UnitTests
{
public class GlassContextTests
{
@cardinal252
cardinal252 / gist:b1b0119745d3d8efd65b
Last active Oct 13, 2015
Using Glass Mapper to get out Children Of Type
View gist:b1b0119745d3d8efd65b
using System;
using System.Collections.Generic;
using System.Linq;
using Glass.Mapper.Sc.Configuration;
using Glass.Mapper.Sc.Configuration.Attributes;
using NUnit.Framework;
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Globalization;
@cardinal252
cardinal252 / gist:d485fd9fb69585dc5525
Created Sep 16, 2015
Using Typed GlassControllers to provide DataSource
View gist:d485fd9fb69585dc5525
public class MyTypedController : GlassController<IContentItem>
{
public ActionResult DisplayControl()
{
return View(DataSource); // returns the view using the DataSource as the model of type IContentItem
}
}
public interface IContentItem
{
@cardinal252
cardinal252 / gist:7b5ef23dca7902088dcd
Last active Sep 26, 2017
Mocking the Context on GlassController<T>
View gist:7b5ef23dca7902088dcd
[TestFixture] // using NSubstitute, NUnit and Fluent Assertions
public class TypedGlassControllerTests
{
[Test]
public void GlassController_can_set_and_get_context()
{
// Arrange
StubClass classToReturn = new StubClass();
var testHarness = new SingleTypedGlassControllerTestHarness();
testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(classToReturn);
@cardinal252
cardinal252 / gist:96df9505353e43cfd1ef
Last active Sep 26, 2017
Mocking the DataSource on a GlassController<TContext, TDataSource>
View gist:96df9505353e43cfd1ef
[TestFixture] // using NSubstitute, NUnit and Fluent Assertions
public class GlassControllerContextItemTests
{
[Test]
public void GlassController_can_set_and_get_datasource()
{
// Arrange
ID expectedId = new ID(Guid.NewGuid());
DataSourceStubClass classToReturn = new DataSourceStubClass();
var testHarness = new DifferentTypedGlassControllerTestHarness();
@cardinal252
cardinal252 / gist:9c08f7c637f6591ee118
Last active Oct 1, 2015
Mocking the GlassController Layout Item
View gist:9c08f7c637f6591ee118
[TestFixture] // using NSubstitute, NUnit and Fluent Assertions
public class GlassControllerLayoutItemTests
{
[Test]
public void GlassController_can_set_and_get_layout_item_from_datasource()
{
// Arrange
ID expectedId = new ID(Guid.NewGuid());
StubClass classToReturn = new StubClass();
var testHarness = new GlassControllerTestHarness();
@cardinal252
cardinal252 / gist:00f2d89eee11ad156245
Last active Sep 16, 2015
Mocking the Request in GlassController
View gist:00f2d89eee11ad156245
[TestFixture]
public class GlassControllerHttpContextTests
{
[Test]
public void GlassController_can_get_query_string_from_http_context_mock()
{
// Arrange
var testHarness = new GlassControllerTestHarness();
NameValueCollection nvc = new NameValueCollection();
nvc.Add("fred", "flintstone");
@cardinal252
cardinal252 / gist:8c8496721a5c30f61453
Last active Oct 1, 2015
Mocking the GlassController context
View gist:8c8496721a5c30f61453
[TestFixture] // using NSubstitute, NUnit and Fluent Assertions
public class GlassControllerContextItemTests
{
[Test]
public void GlassController_can_set_and_get_context()
{
// Arrange
StubClass classToReturn = new StubClass();
var testHarness = new GlassControllerTestHarness();
testHarness.SitecoreContext.GetCurrentItem<StubClass>().Returns(classToReturn);
You can’t perform that action at this time.