public void GetDictionaryModels_LocalizationServiceThrowsException_ErrorLoggedThrowException() { // Arrange Mock <ILogger> logger = new Mock <ILogger>(); Mock <ILocalizationService> localizationService = new Mock <ILocalizationService>(); localizationService .Setup(x => x.GetDictionaryItemDescendants(It.IsAny <Guid?>())) .Throws <Exception>(); Log.Logger = logger.Object; UmbracoService subject = new UmbracoService(localizationService.Object); // Assert Assert.Throws <Exception>(() => { // Act subject.GetDictionaryModels(); }); logger.Verify(x => x.Write( It.Is <LogEventLevel>(level => level == LogEventLevel.Error), It.IsAny <Exception>(), It.IsAny <string>() )); }
public void Setup() { if (_hasRun) { return; } _hasRun = true; _glassWatch = new Stopwatch(); _rawWatch = new Stopwatch(); _expected = "hello world"; _context = Context.Create(DependencyResolver.CreateStandardResolver()); _context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); _service = new UmbracoService(_contentService, _context); var content = _contentService.GetById(new Guid("{2867D837-B258-4DF1-90F1-D5E849FCAF84}")); content.Properties["Property"].Value = _expected; _contentService.Save(content); }
public void Save_ItemDisplayNameChanged_SavesName() { //Assign string expected = "new name"; var context = Context.Create(DependencyResolver.CreateStandardResolver()); context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); var currentItem = _contentService.GetById(new Guid("{24814F74-CE52-4975-B9F3-15ABCBB132D6}")); var service = new UmbracoService(_contentService, context); var cls = new StubSaving(); cls.Id = currentItem.Key; //setup item currentItem.Name = "old name"; _contentService.Save(currentItem); //Act cls.Name = expected; service.Save(cls); //Assert var newItem = _contentService.GetById(new Guid("{24814F74-CE52-4975-B9F3-15ABCBB132D6}")); Assert.AreEqual(expected, newItem.Name); }
public UmbracoServiceTests() { var umbracoContextFactoryMock = new Mock <IUmbracoContextFactory>(); umbracoContextFactoryMock.Setup(x => x.EnsureUmbracoContext(It.IsAny <HttpContextBase>())) .Returns(It.IsAny <UmbracoContextReference>()); this._sut = new UmbracoService(umbracoContextFactoryMock.Object); }
public void General_RetrieveItemsAndFieldsFromUmbraco_ReturnPopulatedClass() { const string fieldValue = "test field value"; const string name = "Target"; const string contentTypeAlias = "TestType"; const string contentTypeName = "Test Type"; const string contentTypeProperty = "TestProperty"; var context = WindsorContainer.GetContext(); var loader = new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration"); context.Load(loader); IContentType contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; ContentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = DataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); var firstDefinition = definitions.FirstOrDefault(); DataTypeService.Save(firstDefinition); var propertyType = new PropertyType(firstDefinition) { Alias = contentTypeProperty }; contentType.AddPropertyType(propertyType); ContentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.SetPropertyValue(contentTypeProperty, fieldValue); ContentService.Save(content); var umbracoService = new UmbracoService(ContentService, context); //Act var result = umbracoService.GetItem <AttributeStub>(content.Id); //Assert Assert.IsNotNull(result); Assert.AreEqual(fieldValue, result.TestProperty); Assert.AreEqual(content.Id, result.Id); Assert.AreEqual(content.Key, result.Key); Assert.AreEqual(name, result.Name); Assert.AreEqual(contentTypeName, result.ContentTypeName); Assert.AreEqual(content.ParentId + "," + content.Id, result.Path); Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias); Assert.AreEqual(content.Version, result.Version); }
static async Task Main(string[] args) { //---------- Configuration ------------------- const string filesPath = @"D:\Mushrooms"; const string trainingApiKey = "fb972b87bc4b45e5b80c396c2f36fc1d"; Guid projectId = new Guid("7fd23595-1444-41c6-a91e-4c2ab67c96a3"); //Uri apiBase = new Uri("http://localhost:22481/umbraco/api/"); Uri apiBase = new Uri("http://setia-dev.azurewebsites.net/umbraco/api/"); const string trainingEndpoint = "https://southcentralus.api.cognitive.microsoft.com"; const string readyFolderId = "clean"; //---------------------------------------------- //init services umbracoService = new UmbracoService(); umbracoService.ApiBase = apiBase; customVisionService = new CustomVisionService(trainingApiKey, trainingEndpoint, projectId); //---------------- string[] lettersFolders = default; try { lettersFolders = Directory.GetDirectories(filesPath); } catch (Exception ex) { ConsoleError("Error opening path." + ex.Message); Environment.Exit(0); } foreach (var letterFolder in lettersFolders) { var mushroomsFolders = Directory.GetDirectories(letterFolder).Where(folder => folder.Contains(readyFolderId, StringComparison.OrdinalIgnoreCase)); foreach (var mushroomFolder in mushroomsFolders) { try { await ProcessFolderAsync(mushroomFolder); } catch { continue; } } } Console.WriteLine(); ConsoleSuccess($"Import finished!"); Console.ReadLine(); }
public void General_RetrieveItemsAndFieldsFromUmbraco_ReturnPopulatedClass() { const string fieldValue = "test field value"; const string name = "Target"; const string contentTypeAlias = "TestType"; const string contentTypeName = "Test Type"; const string contentTypeProperty = "TestProperty"; var context = WindsorContainer.GetContext(); var loader = new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration"); context.Load(loader); IContentType contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; ContentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = DataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); var firstDefinition = definitions.FirstOrDefault(); DataTypeService.Save(firstDefinition); var propertyType = new PropertyType(firstDefinition) { Alias = contentTypeProperty }; contentType.AddPropertyType(propertyType); ContentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.SetPropertyValue(contentTypeProperty, fieldValue); ContentService.Save(content); var umbracoService = new UmbracoService(ContentService, context); //Act var result = umbracoService.GetItem<AttributeStub>(content.Id); //Assert Assert.IsNotNull(result); Assert.AreEqual(fieldValue, result.TestProperty); Assert.AreEqual(content.Id, result.Id); Assert.AreEqual(content.Key, result.Key); Assert.AreEqual(name, result.Name); Assert.AreEqual(contentTypeName, result.ContentTypeName); Assert.AreEqual(content.ParentId + "," + content.Id, result.Path); Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias); Assert.AreEqual(content.Version, result.Version); }
public void GetItem_UsingItemIdInt_ReturnsItem() { //Assign var context = Context.Create(DependencyResolver.CreateStandardResolver()); context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); var content = _contentService.GetById(new Guid("{24814F74-CE52-4975-B9F3-15ABCBB132D6}")); var service = new UmbracoService(_contentService, context); //Act var result = (StubClass)service.GetItem<StubClass>(content.Id); //Assert Assert.IsNotNull(result); }
public void GetItem_UsingItemId_ReturnsItemName() { //Assign var context = Context.Create(DependencyResolver.CreateStandardResolver()); context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); var service = new UmbracoService(_contentService, context); var id = new Guid("{24814F74-CE52-4975-B9F3-15ABCBB132D6}"); //Act var result = service.GetItem<StubClassWithProperty>(id); //Assert Assert.IsNotNull(result); Assert.AreEqual("EmptyItem", result.Name); }
public void GetItem_UsingItemIdInt_ReturnsItem() { //Assign var context = Context.Create(DependencyResolver.CreateStandardResolver()); context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); var content = _contentService.GetById(new Guid("{24814F74-CE52-4975-B9F3-15ABCBB132D6}")); var service = new UmbracoService(_contentService, context); //Act var result = (StubClass)service.GetItem <StubClass>(content.Id); //Assert Assert.IsNotNull(result); }
public void GetItem_UsingItemId_ReturnsItemName() { //Assign var context = Context.Create(DependencyResolver.CreateStandardResolver()); context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); var service = new UmbracoService(_contentService, context); var id = new Guid("{24814F74-CE52-4975-B9F3-15ABCBB132D6}"); //Act var result = service.GetItem <StubClassWithProperty>(id); //Assert Assert.IsNotNull(result); Assert.AreEqual("EmptyItem", result.Name); }
public void Setup() { if (_hasRun) return; _hasRun = true; _glassWatch = new Stopwatch(); _rawWatch= new Stopwatch(); _expected = "hello world"; _context = Context.Create(DependencyResolver.CreateStandardResolver()); _context.Load(new UmbracoAttributeConfigurationLoader("Glass.Mapper.Umb.Integration")); _service = new UmbracoService(_contentService, _context); var content = _contentService.GetById(new Guid("{2867D837-B258-4DF1-90F1-D5E849FCAF84}")); content.Properties["Property"].Value = _expected; _contentService.Save(content); }
public void General_RetrieveContentAndPropertiesFromUmbraco_ReturnPopulatedClass() { //Assign string fieldValue = "test field value"; string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; string contentTypeProperty = "TestProperty"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); var contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var dataTypeService = new DataTypeService(unitOfWork, repoFactory); var context = WindsorContainer.GetContext(); var loader = new UmbracoFluentConfigurationLoader(); var stubConfig = loader.Add <Stub>(); stubConfig.Configure(x => { x.Id(y => y.Id); x.Id(y => y.Key); x.Property(y => y.TestProperty); x.Info(y => y.Name).InfoType(UmbracoInfoType.Name); x.Info(y => y.ContentTypeName).InfoType(UmbracoInfoType.ContentTypeName); x.Info(y => y.ContentTypeAlias).InfoType(UmbracoInfoType.ContentTypeAlias); x.Info(y => y.Path).InfoType(UmbracoInfoType.Path); x.Info(y => y.Version).InfoType(UmbracoInfoType.Version); x.Info(y => y.CreateDate).InfoType(UmbracoInfoType.CreateDate); x.Info(y => y.UpdateDate).InfoType(UmbracoInfoType.UpdateDate); x.Info(y => y.Creator).InfoType(UmbracoInfoType.Creator); x.Delegate(y => y.Delegated).GetValue(GetDelegatedValue); }); context.Load(loader); IContentType contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); dataTypeService.Save(definitions.FirstOrDefault()); var propertyType = new PropertyType(definitions.FirstOrDefault()); propertyType.Alias = contentTypeProperty; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.SetPropertyValue(contentTypeProperty, fieldValue); contentService.Save(content); var umbracoService = new UmbracoService(contentService, context); //Act var result = umbracoService.GetItem <Stub>(content.Id); //Assert Assert.IsNotNull(result); Assert.AreEqual(fieldValue, result.TestProperty); Assert.AreEqual(content.Id, result.Id); Assert.AreEqual(content.Key, result.Key); Assert.AreEqual(name, result.Name); Assert.AreEqual(contentTypeName, result.ContentTypeName); Assert.AreEqual(content.ParentId + "," + content.Id, result.Path); Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias); Assert.AreEqual(content.Version, result.Version); Assert.AreEqual(content.CreateDate, result.CreateDate); Assert.AreEqual(content.UpdateDate, result.UpdateDate); Assert.AreEqual("admin", result.Creator); Assert.AreEqual("happy", result.Delegated); }
public void General_RetrieveContentAndPropertiesFromUmbraco_ReturnPopulatedClass() { //Assign string fieldValue = "test field value"; string name = "Target"; string contentTypeAlias = "TestType"; string contentTypeName = "Test Type"; string contentTypeProperty = "TestProperty"; var unitOfWork = Global.CreateUnitOfWork(); var repoFactory = new RepositoryFactory(); var contentService = new ContentService(unitOfWork, repoFactory); var contentTypeService = new ContentTypeService(unitOfWork, repoFactory, new ContentService(unitOfWork), new MediaService(unitOfWork, repoFactory)); var dataTypeService = new DataTypeService(unitOfWork, repoFactory); var context = WindsorContainer.GetContext(); var loader = new UmbracoFluentConfigurationLoader(); var stubConfig = loader.Add<Stub>(); stubConfig.Configure(x => { x.Id(y => y.Id); x.Id(y => y.Key); x.Property(y => y.TestProperty); x.Info(y => y.Name).InfoType(UmbracoInfoType.Name); x.Info(y => y.ContentTypeName).InfoType(UmbracoInfoType.ContentTypeName); x.Info(y => y.ContentTypeAlias).InfoType(UmbracoInfoType.ContentTypeAlias); x.Info(y => y.Path).InfoType(UmbracoInfoType.Path); x.Info(y => y.Version).InfoType(UmbracoInfoType.Version); x.Info(y => y.CreateDate).InfoType(UmbracoInfoType.CreateDate); x.Info(y => y.UpdateDate).InfoType(UmbracoInfoType.UpdateDate); x.Info(y => y.Creator).InfoType(UmbracoInfoType.Creator); }); context.Load(loader); IContentType contentType = new ContentType(-1); contentType.Name = contentTypeName; contentType.Alias = contentTypeAlias; contentType.Thumbnail = string.Empty; contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var definitions = dataTypeService.GetDataTypeDefinitionByControlId(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea")); dataTypeService.Save(definitions.FirstOrDefault()); var propertyType = new PropertyType(definitions.FirstOrDefault()); propertyType.Alias = contentTypeProperty; contentType.AddPropertyType(propertyType); contentTypeService.Save(contentType); Assert.Greater(contentType.Id, 0); var content = new Content(name, -1, contentType); content.SetPropertyValue(contentTypeProperty, fieldValue); contentService.Save(content); var umbracoService = new UmbracoService(contentService, context); //Act var result = umbracoService.GetItem<Stub>(content.Id); //Assert Assert.IsNotNull(result); Assert.AreEqual(fieldValue, result.TestProperty); Assert.AreEqual(content.Id, result.Id); Assert.AreEqual(content.Key, result.Key); Assert.AreEqual(name, result.Name); Assert.AreEqual(contentTypeName, result.ContentTypeName); Assert.AreEqual(content.ParentId + "," + content.Id, result.Path); Assert.AreEqual(contentTypeAlias, result.ContentTypeAlias); Assert.AreEqual(content.Version, result.Version); Assert.AreEqual(content.CreateDate, result.CreateDate); Assert.AreEqual(content.UpdateDate, result.UpdateDate); Assert.AreEqual("admin", result.Creator); }