public void EngineApiHasPropertyTest() { string propertyName = "testProp"; var content = _unitTestEngine.WithPublishedContentPage(contentType: _unitTestEngine.WithPublishedContentType(propertyTypes: new[] { UmbracoUnitTestHelper.GetPropertyType(alias: propertyName) })); var controller = new BasicUmbracoApiController(_unitTestEngine.UmbracoContext, _unitTestEngine.UmbracoHelper); _unitTestEngine.RegisterController(controller); var res = controller.BasicHasPropertyAction(content.Id, propertyName); Assert.IsTrue(res); }
public void BasicApiHasPropertyTest() { //create a mock of the content type service var mockContentService = new Mock <IContentTypeService>(); //this time we will make our own service context, which can take in all of the umbraco services //Pass the context the mocked content service object //core boot manager requires Services.TextService to not be null (pass in mock of ILocalizedTextService) var serviceContext = new ServiceContext(contentTypeService: mockContentService.Object, localizedTextService: Mock.Of <ILocalizedTextService>()); var appCtx = ApplicationContext.EnsureContext( new DatabaseContext(Mock.Of <IDatabaseFactory>(), Mock.Of <ILogger>(), new SqlSyntaxProviders(new[] { Mock.Of <ISqlSyntaxProvider>() })), 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); //Have to use an inherited instance of boot manager to remove methods we can't use var bm = new CustomBoot(new UmbracoApplication(), serviceContext); bm.Initialize().Startup(null).Complete(null); string ctAlias = "testAlias"; string propertyName = "testProp"; //THIS TIME we do need a property type defined.... this is more complicated... var mockContentType = new Mock <IContentType>(); mockContentType.Setup(s => s.Alias).Returns(ctAlias); mockContentType.Setup(s => s.CompositionPropertyTypes).Returns(new PropertyType[] { new PropertyType(propertyName, DataTypeDatabaseType.Nvarchar, propertyName) }); mockContentService.Setup(s => s.GetContentType(ctAlias)).Returns(mockContentType.Object); var ContentType = PublishedContentType.Get(PublishedItemType.Content, ctAlias); var contentId = 2; //get a mocked IPublishedContent var contentMock = new Mock <IPublishedContent>(); contentMock.Setup(s => s.ContentType).Returns(ContentType); 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.BasicHasPropertyAction(contentId, propertyName); Assert.IsTrue(res); //clean up resolved so we can use this again... appCtx.DisposeIfDisposable(); }