Questions tagged [unit-testing]

Only for questions that are specific to unit testing Sitecore-based features, controls, renderings and other Sitecore-specific application logic

Filter by
Sorted by
Tagged with
0
votes
1answer
86 views

Unit Test fails to run on solution based on Helix Visual Studio Templates

my project solution is based on Sitecore Helix Visual Studio Templates by Ander's Laub. Im trying to write Unit tests using XUnit, but none of the tests are running and not even failing. For test ...
0
votes
1answer
64 views

Create Unit Tests for Testing a Component in Sitecore 10

I'm completely new in Unit testing, trying to implement Unit testing for a navigation header component using xUnit, Moq and FluentAssertions library. Below are my code for Navigation Header ...
3
votes
1answer
28 views

Unit Testing with GlassMapper and GetItemByIdOptions

I have some code that retrieves a glass item like this: var root = this.RequestContext.SitecoreService.GetItem<ILookupFolderTemplate>( new GetItemByIdOptions(new Guid("{...
0
votes
1answer
36 views

Mock SiteSettingsProvider with Glass Mapper

Does anyone know how I can go about mocking the SiteSettingsProvider in Habitat? Item sitecoreItem= mvcContext.GetContextItem<Item>(); Item settingsItem= settingsProvider.GetSetting(...
0
votes
1answer
51 views

Item from Database.GetItem gets NullReference exception in field HasClones and in FieldRenderer.Render in test

I am trying to set up a simple test project to initially assert that my local C# models correspond to my Sitecore templates. The Item retrieval is successful using Database.GetItem(itemPath) and I can ...
3
votes
1answer
49 views

How to mock XConnectClient

I'm writing unit tests for a class that uses XConnectClient, which means I need to mock an XConnectClient. I've tried the following using Moq and RandomTestValues packages: Mock<XConnectClient> ...
1
vote
1answer
95 views

Can we use Moq for Sitecore Item Axes?

I have converted to my code from Nsubstitute to Moq. Nsubstitute: var item = Substitute.For<Item>(id, itemData, database); item.Axes.Returns(Substitute.For<ItemAxes>(item)); return ...
1
vote
1answer
490 views

FakeDB unit tests erroring

I'm trying to get some unit tests running in my Sitecore environment, where I'm using FakeDB as the testing framework. I've added the relevant NuGet packages in my Visual Studio project (which are ...
2
votes
1answer
155 views

FakeDB runs into error when unit tests executed in parallel

I am facing a weird problem with Sitecore 9.2.0 and FakeDb 2.0.1. Some of the unit tests fails randomly with the following error. System.NullReferenceException Object reference not set to an instance ...
1
vote
1answer
145 views

Sitecore 9.2 Unit Test Error: Could not find configuration node: contentSearch/configuration

I am trying to configure a Unit Test project within my Feature directory i.e. Feature Activity ExampleProject ExampleProject.UnitTest Implementation In Unit Test Project: UnitTest.cs [...
1
vote
1answer
187 views

Service Sitecore.Abstractions.ICorePipeline was not registered in container

I am writing unit test to read from ContentSearchManager.GetIndex method. At line ContentSearchManager.GetIndex(indexableItem) in below code : Sitecore.Context.SetActiveSite("<<Site ...
1
vote
1answer
200 views

Unable to switch page DisplayMode in unit test

I am trying to test one of the properties which checks for the PageMode.IsExperienceEditor. Reduced implementation of my property is given below: public ContentResult DataSourceNotConfiguredResult { ...
3
votes
1answer
61 views

Using TDS project items in FakeDb.Serialization

I have a test project for a module where I'd like to use FakeDb. Because I have a TDS project where store items for master database, I'd like to use them for tests with FakeDb.Serialization. When I ...
2
votes
1answer
127 views

Convert item to bucket in C# code

We have a code in our solution that checks if the item is a bucket using Sitecore.Buckets.Managers.BucketManager.IsBucket(bucketItem) I'm creating a unit test using fakeDb and my code is this var ...
-1
votes
1answer
329 views

Sitecore FakeDB Set Template Standard values

I am working on unit tests. So I am using fake DB. I am trying to set template standard values. So I used below code. Item newItem = db.GetItem(contextId); var standardValues = newItem.Template....
2
votes
1answer
416 views

Unable to get AutoFixture, FakeDb and NUnit3 combination to work

Has anyone been able to get the combination of AutoFixure, FakeDb and NUnit3 to work? I am unable to retrieve an item I have added to the database (using example from FakeDb AutoFixture wiki page); ...
0
votes
1answer
113 views

Sitecore FakeDB Deserialisation and Unicorn

Using Sitecore 9.0.1, Im looking at using Sitecore Fake DB for unit testing. Im interested in using the Deserialisation extension so that I can test using content that's been serialised to disk ...
2
votes
1answer
506 views

Fake a Media Item for Unit Testing

Is possible to autogenerate a Media "element" ? I am trying to do this mediaProvider.GetMedia(Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == mediaItemId)).Returns(Arg.Any<Media>()...
0
votes
1answer
344 views

Faking a MediaRequest and Media Items

I am currently trying to mock a media request and the media item I am requesting using FakeDb but for some reason my request is returning an empty MediaPath rather than the MediaPath I am expecting. ...
1
vote
1answer
400 views

Setting up FakeSiteContext for urls

I am currently trying to create a unittest for a override I made, but unittesting it seems a bit more difficult than I expected.. public class Extension : Original { public fallback(...
0
votes
1answer
641 views

Unit testing Sitecore ContentSearchManager

I have the following code that returns Items: public static IList<Item> GetAll(Language language) { var index = $"my_index_{Context.Database.Name.ToLowerInvariant()}"; using (var ...
0
votes
2answers
2k views

Create mock tests for the Sitecore logic

Have anyone used Mock Test framework for unit testing? I need to perform an unit testing for parent child functionality and am not able to get it resolved, because i am not getting a parent child ...
2
votes
2answers
361 views

Sitecore 9 eLearning TAC.Sitecore.Abstraction errors with code in Student resource file SitecoreItem.cs

In Module 5, I am getting an error on the Creating a Breadcrumb Component. I brought in the TAC.Sitecore.Abstractions project like the directions say and I added the reference for it in my event.tac....
1
vote
1answer
970 views

Fake DB on Sitecore.data.Items.Item.add method

I'm creating a unit test for a code that has an Item.Add method used and trying to use Sitecore Fake DB for this and I'm getting an error that it's not being populated. A sample code below: public ...
1
vote
1answer
904 views

Mocking the Authentication Provider

I'm trying to Unit test my login method, for that I used below provider var provider = Substitute.For<Sitecore.Security.Authentication.AuthenticationProvider>(); provider ...
0
votes
2answers
286 views

Mock an Item in Nunit having fast Query

I have a fast query : /sitecore/content/Countries/* I tried to mock them using nunit as using (Db db = new Db() { new DbItem("Countries"){ new ...
2
votes
2answers
492 views

URL encoding in HttpRequestArgs while unit testing

I'm putting together unit tests for item resolver running under httpRequest pipeline. One of the test is checking if the item is properly resolved using display name with asian characters (Japanese). ...
1
vote
1answer
418 views

Unit testing Sitecore custom rules

For a project I am using a bunch of custom Personalization rules, the only problem I am facing at the moment is that it takes quite a while to load the rules and I can't find any good examples of a ...
0
votes
1answer
1k views

Sitecore.Context.Item is Overwritten by RenderingContext.Current.Rendering

I'm new to Sitecore FakeDb NUnit Testing. While testing the code, I found that Sitecore.Context.Item = null; RenderingContext.Current.Rendering.DataSource = fakeItem.ID.ToString(); Since the item ...
5
votes
3answers
2k views

How to get item url without using Linkmanager?

Hello i need to get the url from a Sitecore ítem but without using the LinkManager class from Sitecore because i can't mock it. What is the best approach to do unit tests when i need information from ...
5
votes
1answer
438 views

Alternatives to using custom pipelines for improved unit testability

What are common or effective approaches for making Pipelines in Sitecore unit testable? I recently updated some code to use custom pipelines and then found I could no longer unit test it :-( In the ...
5
votes
2answers
999 views

Unit testing SXA component with FakeDB - No locator provider is configured

I'm using FakeDB to try and set up unit tests for a custom component. While trying to run it, I walked into a couple of missing .dll's which I hadn't expected since the FakeDB install page hadn't ...
1
vote
0answers
61 views

Using JustMock With Sitecore 8.2.4 Kernel DLL

I have the following JustMock call in my old 8.0.7 Sitecore project: var siteGuid = Guid.NewGuid(); var siteItem = Mock.Create<Item>(); var id = new ID(siteGuid); Mock.Arrange(() => siteItem....
1
vote
0answers
251 views

Analytics Tracking Unit Test

I need to create a unit test that will use the following pipeline Sitecore.Analytics.Pipelines.StartTracking It then needs to see if the tracking is enabled and then check if a cookie exists. I saw ...
3
votes
2answers
489 views

Mock MediaProvider on 8.2

I am using FakeDB trying to mock a media provider. I get this message when attempting the example shown in the wiki. Starting from Sitecore 8.2, the Sitecore.Resources.Media.MediaProvider class is ...
1
vote
0answers
565 views

Unit testing contentsearch with facets

I am trying to write a test for this code: var publicationYears = new List<string>(); using (var context = searchContextBuilder.GetSearchContext(Indexes.NewsIndex)) { var query = context....
2
votes
3answers
433 views

Problem retrieving FakeDb DbLinkField attributes

db.Add(new DbTemplate("t1", t1_TemplateId)); db.Add(new DbTemplate("T", T_TemplateId) { BaseIDs = new[] { t1_TemplateId} }); db.Add(new DbItem("root") { new DbItem("...
3
votes
3answers
1k views

Technique for changing Sitecore configuration for unit tests

When we unit test we often need to change some Sitecore configuration for the tests. For example, we may have the following: <sitecore> <configuration> <someNode name="myService"&...
8
votes
1answer
7k views

How to get started with Sitecore Unit Testing with SitecoreFakeDb

I'm trying to find the correct approach to begin unit testing the piece of code below: public class NameUtility { private readonly string _folder = Settings.GetSetting("FolderId"); public ...
25
votes
2answers
2k views

How do I create an NSubstitute Sitecore item?

Is it possible to create a mock Sitecore (using Sitecore 8.2) item using NSubstitute? I would like to write a unit test to cover the following pipeline processor code, which adds a child folder item ...