Skip to content

Testing

Kirill edited this page Oct 4, 2019 · 2 revisions

Unit Tests

Dependency Injection

If you are using Dependency Injection in your project you don't need to do something special. Just create a mock for IPopupNavigation and inject it in your class.

Global Testing

If you don't use Dependency Injection in your project you can mock INavigationService as well. In this way, you have to mock INavigationService or create your own implementation of INavigationService and set it to NavigationService class. To do it you should use Rg.Plugins.Popup.Services.PopupNavigation.SetInstance(yourInstance). If you would like to reset an instance to default you can call Rg.Plugins.Popup.Services.PopupNavigation.RestoreDefaultInstance().

Also, PopupNavigation.SetInstance and PopupNavigation.RestoreDefaultInstance() methods have [EditorBrowsable(EditorBrowsableState.Never)] attribute and your VS can hide it. Don't worry this code will be compiled fine anyway.

using NUnit.Framework;
using Rg.Plugins.Popup.Contracts;
using Rg.Plugins.Popup.Services;

namespace Project.Tests
{
    [TestFixture]
    public class YourTest
    {
        [SetUp]
        public void Setup()
        {
            var instance = new Mock<INavigationService>();

            // Configuration mock
            ...

            PopupNavigation.SetInstance(instance);
        }

        [Test]
        public void Your_Test()
        {
            // It's your mock of INavigationService
            var popupInstance = PopupNavigation.Instance;

            // Do your tests
            ...
        }
    }
}