public void EngineApiGetPropertyTest() { var value = "testValue"; var alias = "testAlias"; var content = _unitTestEngine.WithPublishedContentPage(properties: new[] { UmbracoUnitTestHelper.GetPublishedProperty(value: value, alias: alias) }); var controller = new BasicUmbracoApiController(_unitTestEngine.UmbracoContext, _unitTestEngine.UmbracoHelper); var res = controller.BasicGetPropertyAction(content.Id, content.Properties.First().PropertyTypeAlias); Assert.AreEqual(content.Properties.First().Value, res); }
public void BasicApiGetPropertyTest() { 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); string propertyName = "testProp"; string propValue = "testValue"; var propertyMock = new Mock <IPublishedProperty>(); propertyMock.Setup(s => s.Value).Returns(propValue); var contentId = 2; //get a mocked IPublishedContent var contentMock = BasicHelpers.GetPublishedContentMock(); contentMock.Setup(s => s.GetProperty(propertyName)).Returns(propertyMock.Object); var mockedTypedQuery = new Mock <ITypedPublishedContentQuery>(); mockedTypedQuery.Setup(s => s.TypedContent(contentId)).Returns(contentMock.Object); //give our dynamic query mock to the longer version of the UmbracoHelper constructor var helper = new UmbracoHelper(ctx, Mock.Of <IPublishedContent>(), mockedTypedQuery.Object, 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>() }), Mock.Of <ICultureDictionary>(), Mock.Of <IUmbracoComponentRenderer>(), new MembershipHelper(ctx, Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>())); var controller = new BasicUmbracoApiController(ctx, helper); var res = controller.BasicGetPropertyAction(contentId, propertyName); Assert.AreEqual(propValue, res); }