public void HelperContentTypeTest() { var mocks = new MockServiceContext(); var appCtx = UmbracoUnitTestHelper.GetApplicationContext(serviceContext: mocks.ServiceContext); var ctx = UmbracoUnitTestHelper.GetUmbracoContext(appCtx); //pass in emtpy proprty types to avoid uninitialized resolver issue. To bypass, must use CoreBootManager UmbracoUnitTestHelper.SetupServicesForPublishedContentTypeResolution(mocks, new PropertyType[] { }); var alias = "test_alias"; var contentType = UmbracoUnitTestHelper.GetPublishedContentType(alias: alias); var contentId = 2; //get a mocked IPublishedContent var contentMock = UmbracoUnitTestHelper.GetPublishedContentMock(contentType: contentType); var mockedTypedQuery = new Mock <ITypedPublishedContentQuery>(); mockedTypedQuery.Setup(s => s.TypedContent(It.IsAny <int>())).Returns(contentMock.Object); //give our dynamic query mock to the longer version of the UmbracoHelper constructor var helper = UmbracoUnitTestHelper.GetUmbracoHelper(ctx, typedQuery: mockedTypedQuery.Object); var controller = new BasicTestSurfaceController(ctx, helper); var res = controller.BasicContentTypeAction(contentId); var model = (string)res.Model; Assert.AreEqual(alias, model); }
public PublishedContentType WithPublishedContentType(int?id = null, string name = null, string alias = null, IEnumerable <PropertyType> propertyTypes = null) { alias = alias ?? _Fixture.Create <string>(); id = id.HasValue ? id : _Fixture.Create <int>(); //use unique ID system? name = name ?? _Fixture.Create <string>(); PublishedContentType contentType = null; if ((contentType = this.ContentTypes.FirstOrDefault(c => c.Alias == alias)) != null) //already existings, return { return(contentType); } if (propertyTypes != null && propertyTypes.Count() > 0) //need boot manager for property types... { NeedsCoreBootManager(); } mockServiceContext.ContentTypeService.Setup(s => s.GetContentType(alias)).Returns(UmbracoUnitTestHelper.GetContentTypeComposition <IContentType>(alias: alias, name: name, id: id, propertyTypes: propertyTypes)); contentType = UmbracoUnitTestHelper.GetPublishedContentType(PublishedItemType.Content, alias); return(contentType); }
public void HelperHasPropertyTest() { //Uses our special service context object (it mocks all services!!) var mockServiceContext = new MockServiceContext(); var appCtx = UmbracoUnitTestHelper.GetApplicationContext(serviceContext: mockServiceContext.ServiceContext); var ctx = UmbracoUnitTestHelper.GetUmbracoContext(appCtx); UmbracoUnitTestHelper.StartCoreBootManager(UmbracoUnitTestHelper.GetCustomBootManager(serviceContext: mockServiceContext.ServiceContext)); string propertyName = "testProp"; //THIS TIME we do need a property type defined.... this is more complicated... UmbracoUnitTestHelper.SetupServicesForPublishedContentTypeResolution(mockServiceContext, new[] { UmbracoUnitTestHelper.GetPropertyType(alias: propertyName) }); var contentId = 2; //get a mocked IPublishedContent var contentType = UmbracoUnitTestHelper.GetPublishedContentType(); var contentMock = UmbracoUnitTestHelper.GetPublishedContentMock(contentType: 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 = UmbracoUnitTestHelper.GetUmbracoHelper(ctx, typedQuery: mockedTypedQuery.Object); var controller = new BasicTestSurfaceController(ctx, helper); var res = controller.BasicHasPropertyAction(contentId, propertyName); var model = (bool)res.Model; Assert.IsTrue(model); //clean up resolved so we can use this again... UmbracoUnitTestHelper.CleanupCoreBootManager(appCtx); }