Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save takahirohonda/6ddf2d433b546f70ddcb9e934774541e to your computer and use it in GitHub Desktop.
Save takahirohonda/6ddf2d433b546f70ddcb9e934774541e to your computer and use it in GitHub Desktop.
how-to-mock-rendering-parameters-in-unit-test-sitecore-2.cs
using FluentAssertions;
using Sitecore.Mvc.Presentation;
using SitecoreDev.Feature.Design.Models;
using SitecoreDev.Feature.Design.Repository;
using System.Collections.Generic;
using Xunit;
namespace SitecoreDev.Feature.Design.Tests.RepositoryTests
{
public class CustomDataDivRepositoryTests
{
[Fact]
public void GetParamsForCustomDiv_Should_Return_Correct_Model()
{
// Arrange
// Create mock parameters
var parameters = new RenderingParameters("hey=hello&more=moreValues");
// Create expected model
var expectedModel = new CustomDataDiv()
{
CustomData = new Dictionary<string, string>
{
{ "hey", "hello" },
{ "more", "moreValues" }
}
};
// Instantiate the class
var repository = new CustomDataDivRepository();
// Act
var model = repository.GetParamsForCustomDiv(parameters);
// Assert
model.Should().BeEquivalentTo(expectedModel);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment