Hot answers tagged

6 votes
Accepted

NullReferenceException from Sitecore.Nexus on Sitecore 9.1

In Sitecore 9.1, this could indicate that your license.xml is missing from your data folder, which will typically be your App_Data folder. Place the license file in the correct location, and reset ...
nickwesselman's user avatar
5 votes

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

Sitecore FakeDb does not set the context item because depending on the scenario, you might or might not need it to be set. If you need the context item not to be null, you can set it in your test ...
Serhii Shushliapin's user avatar
4 votes
Accepted

Alternatives to using custom pipelines for improved unit testability

Had a bit of a think about how to do this: Test the processor steps So the first thing to do is make sure all your code logic is off loaded to a service or manager class. The processor class really ...
Richard Seal's user avatar
  • 19.6k
4 votes
Accepted

Adding DbItem under media library with FakeDb

The API is not quite obvious here. By default, all the items are added to the content. If you need to add an item to the Media Library, you should set the fakeItem.ParentID property: var ...
Serhii Shushliapin's user avatar
3 votes

Unit testing a Sitecore component controller throws exception in mocked service

By mocking a proper return type(GetPreviousProductsResponse) value for the injected service(_productService) instead of a model property(PreviousProducts) solved this issue. _productService....
Venu Vustipalli's user avatar
3 votes

Using TDS project items in FakeDb.Serialization

My problem was actually due to ReSharper Unit Test for NUnit runner. It was running tests from temporary location, not from the project output directory. Fix was to tell NUnit runner to set ...
jjczopek's user avatar
  • 353
3 votes
Accepted

Setting up FakeSiteContext for urls

The simplest solution is to change your code to make it more easily unit testable, and remove the dependence on the Sitecore.Context object, and instead pass in the required variables as a parameter ...
jammykam's user avatar
  • 13.8k
3 votes
Accepted

Problem retrieving FakeDb DbLinkField attributes

Ok I finally found my mistake. Since I am using DbTemplates, the DbLinkField needs to be added to the template first. db.Add(new DbTemplate("t1", t1_TemplateId)){ new DbLinkfield("theField") }); ...
jgondev's user avatar
  • 325
2 votes
Accepted

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

You need to add template to the FakeDB database first. Just add those 2 lines to your code: var childTemplate = new DbTemplate("child", templateID); db.Add(childTemplate); e.g: var myHomeID = new ...
Marek Musielak's user avatar
  • 21.7k
2 votes

Mocking the Authentication Provider

For testing authentication using FakeDb you can try next : [Theory] [AutoDbData] public void Login_UserIsNotLoggedIn_ShouldReturnFalse(FakeMembershipUser user, AuthenticationProvider ...
Vlad Iobagiu's user avatar
2 votes

URL encoding in HttpRequestArgs while unit testing

I'd suggest not to use FakeDb for (unit) testing such scenario. If I unrerstand your intention correctly, you do not test any logic of your application. You're trying to test a piece of Sitecore ...
Serhii Shushliapin's user avatar
2 votes

Error: Could not resolve type name: Sitecore.Data.DefaultDatabase, Sitecore.Kernel

Sitecore 8.2 introduced changes to the way Database is handled internally. To make FakeDB work on 8.2, you need to add a configuration snippet to App_Config\Include containing the following: <?xml ...
Mark Cassidy's user avatar
  • 24.7k
2 votes
Accepted

Fake a Media Item for Unit Testing

There is a package from Sitecore.FakeDb that integrates with AutoFixture to generate items on the fly. The Nuget package is Sitecore.FakeDb.AutoFixture https://github.com/sergeyshushlyapin/Sitecore....
Vincent Lui's user avatar
2 votes
Accepted

Unable to switch page DisplayMode in unit test

It's a bug and needs to be fixed in FakeDb. But the good news is that you may hotfix it following the article instructions carefully: add shell site registration to your config: <sites> &...
Serhii Shushliapin's user avatar
2 votes

Unable to get AutoFixture, FakeDb and NUnit3 combination to work

I will start my answer with a question, why do you need to use FakeDB? Even though the idea of FakeDB is great in theory, it inevitably causes more issues than it solves, in my opinion, when testing ...
Gravypower's user avatar
2 votes
Accepted

Sitecore.Exceptions.ConfigurationException:'Could not create instance of type:Sitecore.Data.Managers.ItemProvider.No matching constructor was found.'

There is a list of breaking changes between Sitecore 9.2 and 9.3 so you have to upgrade FakeDb to v3 (see release notes). JFI, for 9.3 FakeDb is no longer needed. You can easily mock Sitecore API.
Serhii Shushliapin's user avatar
2 votes
Accepted

FakeDB unit tests erroring

First, I'd strongly recommend you avoid using FakeDb for Sitecore 9. It still works, but Sitecore 9 (even 8.2+) contains abstractions that makes FakeDb unnecessary. See this post for more information. ...
Serhii Shushliapin's user avatar
1 vote

Implement unit test for a sitecore MVC solution with glassmapper

Please follow the below-mentioned steps and try to incorporate them with your existing code: Create a Test controller in your project, for example, I am creating HeroTestController and specifying the ...
Himmat Singh Dulawat's user avatar
1 vote

Error while using Sitecore Fake DB with Sitecore 8.2

I remember having some issues with error messages not corresponding to the actual issue. If you can make sure of all of these (assuming you are following Helix principles here): Declare databases ...
Jean-Nicolas G.'s user avatar
1 vote

Error while using Sitecore Fake DB with Sitecore 8.2

You should make sure that your Test project has at least the following references: <packages> <package id="Lucene.Net" version="3.0.3" targetFramework="net452" ...
Cristi Vulturar's user avatar
1 vote

FakeDB runs into error when unit tests executed in parallel

I'm afraid the parallel test execution is not supported. The scenario looks familiar to me, but I've never found a proper solution to this problem and ended up disabling this feature. If you use ...
Serhii Shushliapin's user avatar
1 vote

Sitecore FakeDB Deserialisation and Unicorn

It does not have to be TDS. You can use items that you have serialized in Sitecore. Go to the Developer Toolbar, and then click on Serialize Item / Serialize Tree.
Vincent Lui's user avatar
1 vote

Faking a MediaRequest and Media Items

What you are doing here is not Unit Testing, I would consider it more of an integration test, I am a broken record on this subject but it is my opinion that you should reserve unit testing for testing ...
Gravypower's user avatar
1 vote

Unit testing Sitecore ContentSearchManager

As it is hard to write your unit tests in an answer here, I'll try to give you some overal guidance.. For unit testing code that uses index queries I usually start with a custom Queryable stub as you ...
Gatogordo's user avatar
  • 19.7k
1 vote

Mock MediaProvider on 8.2

The decision to obsolete the switchers was predicted by SitecoreAuthenticationProvider which became obsolete in 8.2: /// <summary>SitecoreAuthenticationProvider class</summary> [Obsolete] ...
Serhii Shushliapin's user avatar
1 vote

Mock MediaProvider on 8.2

BaseMediaManager is an abstract class. Try using Sitecore.Resources.Media.DefaultMediaManager which is derived class of BaseMediaManager I'm using JustDecompile to see the class and inheritance ...
Harsh Baid's user avatar
  • 1,969

Only top scored, non community-wiki answers of a minimum length are eligible