Esempio n. 1
0
        public void BasicDictionaryTest()
        {
            var appCtx = ApplicationContext.EnsureContext(
                new DatabaseContext(Mock.Of <IDatabaseFactory>(), Mock.Of <ILogger>(), new SqlSyntaxProviders(new[] { Mock.Of <ISqlSyntaxProvider>() })),
                new ServiceContext(),
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(
                    Mock.Of <ILogger>(),
                    Mock.Of <IProfiler>()), true);

            var ctx = UmbracoContext.EnsureContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new Mock <WebSecurity>(null, null).Object,
                Mock.Of <IUmbracoSettingsSection>(),
                Enumerable.Empty <IUrlProvider>(), true);

            //Set ApplicationContext and UmbracoContext

            var test_value = "test";

            var valueDict = new Dictionary <string, string>()
            {
                { "Test Key", test_value }
            };

            //we can create a mock of the culture dictionary interface and set any value we want
            var mockDict = new Mock <ICultureDictionary>();

            //setup our mock dictionary to passthrough to our local dictionary
            mockDict.Setup(s => s[It.IsAny <string>()]).Returns <string>(key => valueDict[key]);

            //This time we use the larger constructor for the Helper. In ther we will set the dictionary that we mocked
            var helper = new UmbracoHelper(ctx,
                                           Mock.Of <IPublishedContent>(), Mock.Of <ITypedPublishedContentQuery>(),
                                           Mock.Of <IDynamicPublishedContentQuery>(),
                                           Mock.Of <ITagQuery>(),
                                           Mock.Of <IDataTypeService>(),
                                           new UrlProvider(ctx, Mock.Of <IWebRoutingSection>(section =>
                                                                                             section.UrlProviderMode == UrlProviderMode.Auto.ToString()),
                                                           new[] { Mock.Of <IUrlProvider>() }),
                                           mockDict.Object, //<--- set the dictionary
                                           Mock.Of <IUmbracoComponentRenderer>(),
                                           new MembershipHelper(ctx, Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>()));

            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicDictionaryAction();
            var model      = res.Model as string;

            Assert.AreEqual(test_value, model);
        }
        public void NuGetEngineDictionaryTest()
        {
            var key   = "Test Key";
            var value = "test";

            _unitTestEngine.WithDictionaryValue(key, value);

            var controller = new BasicTestSurfaceController(_unitTestEngine.UmbracoContext, _unitTestEngine.UmbracoHelper);

            _unitTestEngine.RegisterController(controller);
            var res   = controller.BasicDictionaryAction();
            var model = res.Model as string;

            Assert.AreEqual(value, model);
        }
        public void HelperDictionaryTest()
        {
            var ctx = UmbracoUnitTestHelper.GetUmbracoContext();

            var valueDict = new Dictionary <string, string>()
            {
                { "Test Key", "test" }
            };

            //we can create a mock of the culture dictionary interface and set any value we want
            var mockDict = new Mock <ICultureDictionary>();

            //setup our mock dictionary to passthrough to our local dictionary
            mockDict.Setup(s => s[It.IsAny <string>()]).Returns <string>(key => valueDict[key]);

            var helper = UmbracoUnitTestHelper.GetUmbracoHelper(ctx, cultureDictionary: mockDict.Object);

            var controller = new BasicTestSurfaceController(ctx, helper);
            var res        = controller.BasicDictionaryAction();
            var model      = res.Model as string;

            Assert.AreEqual(valueDict["Test Key"], model);
        }