public async Task CreatingContentTypesShouldCallActivateMethodIfConfigIsSet() { //Arrange var contentTypeInfo = new ContentTypeInformation() { ContentType = new ContentType() { Name = "Test", SystemProperties = new SystemProperties { Id = "FFff", Version = 7 } } }; var config = new ContentfulCodeFirstConfiguration { PublishAutomatically = true }; var client = new Mock <IContentfulManagementClient>(); client.Setup(c => c.CreateOrUpdateContentType(contentTypeInfo.ContentType, null, null, default(CancellationToken))).ReturnsAsync(contentTypeInfo.ContentType); //Act var contentTypes = await ContentTypeBuilder.CreateContentTypes(new[] { contentTypeInfo }, config, client.Object); //Assert client.Verify(c => c.GetContentTypes(null, default(CancellationToken)), Times.Once, "Did not receive call to get all contentTypes."); client.Verify(c => c.CreateOrUpdateContentType(contentTypeInfo.ContentType, null, null, //We expect version to be null here since the content type did not previously exist. default(CancellationToken)), Times.Once, "Did not receive a call to update contenttype."); client.Verify(c => c.ActivateContentType(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), default(CancellationToken)), Times.Once, "Activate should have been called since configuration value PublishAutomatically is true."); }
public static void RegisterContentTypes() { var configuration = GetConfig(); IEnumerable <IContentType> registeredContentTypes = ServiceLocator.Current.GetAllInstances <IContentType>(); var types = registeredContentTypes.Select(ct => ct.GetType()).Where(c => c.GetTypeInfo().IsClass&& c.GetTypeInfo().GetCustomAttribute <ContentTypeAttribute>() != null).ToList(); var contentTypesToCreate = ContentTypeBuilder.InitializeContentTypes(types, configuration.CamelcaseFieldIdsAutomatically); var createdContentTypes = ContentTypeBuilder.CreateContentTypes(contentTypesToCreate, configuration, ServiceLocator.Current.GetInstance <IContentManagementClient>().Instance).Result; }