Exemple #1
0
        public void EntitiesNode_creates_EntityNodeValue_with_tags_attached()
        {
            // ARRANGE

            var tag = DefaultTag();

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.ProviderContextMock
            .Setup(c => c.DynamicParameters)
            .Returns(new EntitiesNode.NewItemParametersDefinition
            {
                Tags = new[] { "t" }
            });

            this.PersistenceMock
            .Setup(m => m.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            Entity?entity = null;

            this.EntityRepositoryMock
            .Setup(r => r.Upsert(It.Is <Entity>(t => t.Name.Equals("ee"))))
            .Callback <Entity>(e => entity = e)
            .Returns <Entity>(e => e);

            this.PersistenceMock
            .Setup(m => m.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var rootCategory = DefaultCategory(AsRoot);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, "ee"))
            .Returns((Category?)null);

            this.PersistenceMock
            .Setup(p => p.Tags)
            .Returns(this.TagRepositoryMock.Object);

            this.TagRepositoryMock
            .Setup(r => r.FindByName("t"))
            .Returns(tag);

            var node = new EntitiesNode();

            // ACT

            var result = node.NewItem(this.ProviderContextMock.Object, newItemName: "ee", itemTypeName: nameof(TreeStoreItemType.Entity), newItemValue: null !);

            // ASSERT

            Assert.Equal(tag, entity !.Tags.Single());
        }
Exemple #2
0
        public void EntitiesNodeValue_retrieves_CategoryNode_by_name_and_root_category(string name)
        {
            // ARRANGE

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var rootCategory = DefaultCategory(AsRoot);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, name))
            .Returns(DefaultCategory());

            // ACT

            var result = new EntitiesNode()
                         .Resolve(this.ProviderContextMock.Object, name)
                         .ToArray();

            // ASSERT

            Assert.IsType <CategoryNode>(result.Single());
        }
Exemple #3
0
        public void EntitiesNode_creating_item_rejects_entity_with_same_name_as_category(string newItemName)
        {
            // ARRANGE

            var node = new EntitiesNode();

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var subCategory  = DefaultCategory(c => c.Name = newItemName);
            var rootCategory = DefaultCategory(AsRoot, WithSubCategory(subCategory));

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, newItemName))
            .Returns(subCategory);

            // ACT

            var result = Assert.Throws <InvalidOperationException>(() => node.NewItem(this.ProviderContextMock.Object,
                                                                                      newItemName: newItemName, itemTypeName: nameof(TreeStoreItemType.Entity), newItemValue: null !));

            // ASSERT

            Assert.Equal("Name is already used by and item of type 'Category'", result.Message);
        }
Exemple #4
0
        public void CategoryNode_copying_fails_if_category_name_already_exists(string initialName, string destinationName, string resultName)
        {
            // ARRANGE

            this.ArrangeSubCategory(out var rootCategory, out var subCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.ProviderContextMock
            .Setup(p => p.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, resultName))
            .Returns(DefaultCategory());

            var entitiesNode = new EntitiesNode();
            var category     = DefaultCategory(c => subCategory.AddSubCategory(c));
            var node         = new CategoryNode(category);

            // ACT

            var result = Assert.Throws <InvalidOperationException>(
                () => node.CopyItem(this.ProviderContextMock.Object, initialName, destinationName, entitiesNode));

            // ASSERTS

            Assert.Equal($"Destination container contains already a category with name '{resultName}'", result.Message);
        }
Exemple #5
0
 public void AddEntities(EntitiesNode entitiesNode)
 {
     if (_entitiesNodes == null)
     {
         _entitiesNodes = new List <EntitiesNode>();
     }
     _entitiesNodes.Add(entitiesNode);
 }
 public EntitiesJob(Chunk chunk, EntitiesNode node, IEntitiesCreatedListener listener) : base(chunk, node.Id)
 {
     _chunk          = chunk;
     _listener       = listener;
     _node           = node;
     _sizeX          = chunk.SizeX;
     _sizeZ          = chunk.SizeZ;
     _requestOffsetX = chunk.X * _sizeX;
     _requestOffsetZ = chunk.Z * _sizeZ;
 }
Exemple #7
0
        public void EntitiesNode_has_name_and_IsContainer()
        {
            // ACT

            var result = new EntitiesNode();

            // ASSERT

            Assert.Equal("Entities", result.Name);
            Assert.True(result.IsContainer);
        }
Exemple #8
0
        public void EntitiesNode_provides_new_item_parameters()
        {
            // ACT

            var result = new EntitiesNode().NewItemParameters;

            // ASSERT

            Assert.IsType <EntitiesNode.NewItemParametersDefinition>(result);
            Assert.Empty(((EntitiesNode.NewItemParametersDefinition)result !).Tags);
        }
Exemple #9
0
        public void EntitiesNodeValue_provides_Item()
        {
            // ACT

            var result = new EntitiesNode().GetItem(this.ProviderContextMock.Object);

            // ASSERT

            Assert.IsType <EntitiesNode.Item>(result.ImmediateBaseObject);

            var resultValue = (EntitiesNode.Item)result.ImmediateBaseObject;

            Assert.Equal("Entities", resultValue.Name);
        }
Exemple #10
0
        public void EntitiesNode_provides_NewItemTypesNames()
        {
            // ACT

            var result = new EntitiesNode().NewItemTypeNames;

            // ASSERT

            Assert.Equal(new[]
            {
                nameof(TreeStoreItemType.Category),
                nameof(TreeStoreItemType.Entity)
            }, result);
        }
Exemple #11
0
        public void EntitiesNode_creates_EntityNodeValue(string itemTypeName)
        {
            // ARRANGE

            this.ProviderContextMock
            .Setup(c => c.DynamicParameters)
            .Returns((object?)null);

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(m => m.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            Entity newEntity = null;

            this.EntityRepositoryMock
            .Setup(r => r.Upsert(It.IsAny <Entity>()))
            .Callback <Entity>(e => newEntity = e)
            .Returns <Entity>(e => e);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var rootCategory = DefaultCategory(AsRoot);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, "Entity"))
            .Returns((Category?)null);

            var node = new EntitiesNode();

            // ACT

            var result = node.NewItem(this.ProviderContextMock.Object, newItemName: "Entity", itemTypeName: itemTypeName, newItemValue: null !);

            // ASSERT

            Assert.IsType <EntityNode>(result);
            Assert.Equal("Entity", newEntity !.Name);
            Assert.Equal(rootCategory, newEntity !.Category);
        }
Exemple #12
0
        public void EntitiesNode_creating_item_rejects_invalid_item_type(string itemTypeName)
        {
            // ARRANGE

            var node = new EntitiesNode();

            // ACT

            var result = Assert.Throws <InvalidOperationException>(() => node.NewItem(this.ProviderContextMock.Object,
                                                                                      newItemName: "c", itemTypeName: itemTypeName, newItemValue: null !));

            // ASSERT

            Assert.Equal($"ItemType '{itemTypeName}' not allowed in the context", result.Message);
        }
Exemple #13
0
        public void EntityNode_moves_itself_to_root_category(string initialName, string destinationName, string resultName)
        {
            // ARRANGE

            this.ArrangeSubCategory(out var rootCategory, out var subCategeory);

            this.ProviderContextMock
            .Setup(p => p.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.PersistenceMock
            .Setup(p => p.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, resultName))
            .Returns((Category?)null);

            this.EntityRepositoryMock
            .Setup(r => r.FindByCategoryAndName(rootCategory, resultName))
            .Returns((Entity?)null);

            var e = DefaultEntity(e => e.Name = initialName, WithEntityCategory(subCategeory));

            this.EntityRepositoryMock
            .Setup(r => r.Upsert(e))
            .Returns <Entity>(e => e);

            var entitiesNode = new EntitiesNode();
            var node         = new EntityNode(e);

            // ACT

            node.MoveItem(this.ProviderContextMock.Object, initialName, destinationName, entitiesNode);

            // ASSERT

            Assert.Equal(rootCategory, e.Category);
            Assert.Equal(resultName, e.Name);
        }
Exemple #14
0
        public void EntitesNode_creating_item_rejects_invalid_chars(char invalidChar)
        {
            // ARRANGE

            var invalidName = new string("p".ToCharArray().Append(invalidChar).ToArray());
            var node        = new EntitiesNode();

            // ACT

            var result = Assert.Throws <InvalidOperationException>(() => node.NewItem(this.ProviderContextMock.Object,
                                                                                      newItemName: invalidName, itemTypeName: nameof(TreeStoreItemType.Entity), newItemValue: null !));

            // ASSERT

            Assert.Equal($"entity(name='{invalidName}' wasn't created: it contains invalid characters", result.Message);
        }
Exemple #15
0
        public void EntityNode_copies_itself_as_new_entity()
        {
            // ARRANGE

            this.ArrangeRootCategory(out var rootCategory);

            var entity = DefaultEntity(WithAssignedDefaultTag, WithEntityCategory(rootCategory));

            entity.SetFacetProperty(entity.Tags.Single().Facet.Properties.Single(), "1");

            this.CategoryRepositoryMock // destination name is unused
            .Setup(r => r.FindByParentAndName(rootCategory, "ee"))
            .Returns((Category?)null);

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(m => m.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            this.EntityRepositoryMock // detsinatin name is unused
            .Setup(r => r.FindByCategoryAndName(rootCategory, "ee"))
            .Returns((Entity?)null);

            Entity?createdEntity = null;

            this.EntityRepositoryMock
            .Setup(r => r.Upsert(It.IsAny <Entity>()))
            .Callback <Entity>(e => createdEntity = e)
            .Returns(entity);

            var entityContainer = new EntitiesNode();

            // ACT

            new EntityNode(entity).CopyItem(this.ProviderContextMock.Object, "e", "ee", entityContainer);

            // ASSERT

            Assert.Equal("ee", createdEntity !.Name);
            Assert.Equal(rootCategory, createdEntity !.Category);
            Assert.Equal(entity.Tags.Single(), createdEntity !.Tags.Single());
            Assert.Equal(entity.Values.Single().Value, createdEntity !.Values.Single().Value);
            Assert.Equal(entity.Values.Single().Key, createdEntity !.Values.Single().Key);
        }
Exemple #16
0
        public void CategoryNode_renaming_rejects_invalid_name_chararcters(char invalidChar)
        {
            // ARRANGE

            var category     = DefaultCategory(c => c.Name = "c");
            var invalidName  = new string("p".ToCharArray().Append(invalidChar).ToArray());
            var entitiesNode = new EntitiesNode();
            var node         = new CategoryNode(category);

            // ACT

            var result = Assert.Throws <InvalidOperationException>(() => node.RenameItem(this.ProviderContextMock.Object, "c", invalidName));

            // ASSERT

            Assert.Equal($"category(name='{invalidName}' wasn't renamed: it contains invalid characters", result.Message);
        }
Exemple #17
0
        public void EntityNode_copying_rejects_invalid_name_chararcters(char invalidChar)
        {
            // ARRANGE

            var entity          = DefaultEntity(WithAssignedDefaultTag, WithEntityCategory(DefaultCategory()));
            var entityContainer = new EntitiesNode();
            var invalidName     = new string("p".ToCharArray().Append(invalidChar).ToArray());
            var node            = new EntityNode(entity);

            // ACT

            var result = Assert.Throws <InvalidOperationException>(() => node.CopyItem(this.ProviderContextMock.Object, "e", invalidName, entityContainer));

            // ASSERT

            Assert.Equal($"entity(name='{invalidName}' wasn't copied: it contains invalid characters", result.Message);
        }
Exemple #18
0
        public void EntitiesNodeValue_retrieves_all_entities_and_categories_by_null_name()
        {
            // ARRANGE

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var subCategory  = DefaultCategory();
            var rootCategory = DefaultCategory(AsRoot, WithSubCategory(subCategory));

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParent(rootCategory))
            .Returns(subCategory.Yield());

            this.PersistenceMock
            .Setup(s => s.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            this.EntityRepositoryMock
            .Setup(r => r.FindByCategory(rootCategory))
            .Returns(DefaultEntity().Yield());

            // ACT

            var result = new EntitiesNode()
                         .Resolve(this.ProviderContextMock.Object, null)
                         .ToArray();

            // ASSERT

            Assert.Equal(2, result.Length);
            Assert.IsType <CategoryNode>(result.First());
            Assert.IsType <EntityNode>(result.Last());
        }
Exemple #19
0
        // ----

        public void Save(string fileName)
        {
            // Update entities node
            EntitiesNode.Children.Clear();
            foreach (var kvp in Entities)
            {
                EntitiesNode.Add(kvp.Value);
            }

            using var writer = new StreamWriter(fileName);
            var document = new YamlDocument(Root);
            var stream   = new YamlStream(document);
            var emitter  = new Emitter(writer);
            var fixer    = new TypeTagPreserver(emitter);

            stream.Save(fixer, false);

            writer.Flush();
        }
Exemple #20
0
        public void EntitiesNode_creates_CategoryNodeValue()
        {
            // ARRANGE

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(m => m.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var rootCategory = DefaultCategory(AsRoot);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.Upsert(It.Is <Category>(c => c.Name.Equals("c"))))
            .Returns <Category>(c => c);

            this.PersistenceMock
            .Setup(p => p.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            this.EntityRepositoryMock
            .Setup(r => r.FindByCategoryAndName(rootCategory, "c"))
            .Returns((Entity?)null);

            var node = new EntitiesNode();

            // ACT

            var result = node
                         .NewItem(this.ProviderContextMock.Object, newItemName: "c", itemTypeName: nameof(TreeStoreItemType.Category), newItemValue: null !);

            // ASSERT

            Assert.IsType <CategoryNode>(result);
        }
Exemple #21
0
        public void EntitiesNodeValue_returns_null_on_unknown_name()
        {
            // ARRANGE

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(p => p.Categories)
            .Returns(this.CategoryRepositoryMock.Object);

            var rootCategory = DefaultCategory(AsRoot);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(rootCategory, "unknown"))
            .Returns((Category?)null);

            this.PersistenceMock
            .Setup(s => s.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            this.EntityRepositoryMock
            .Setup(r => r.FindByCategoryAndName(rootCategory, "unknown"))
            .Returns((Entity?)null);

            // ACT

            var result = new EntitiesNode()
                         .Resolve(this.ProviderContextMock.Object, "unknown")
                         .ToArray();

            // ASSERT

            Assert.Empty(result);
        }
Exemple #22
0
        public void StartEntitiesJob(EntitiesNode node)
        {
            if (!IsInitialized)
            {
                return;
            }
            if (_entitiesList == null)
            {
                _entitiesList = new Dictionary <int, List <GameObject> >();
            }
            if (IsWorkingOnEntities(node.Id))
            {
                return;
            }
            if (_entitiesList.ContainsKey(node.Id))
            {
                return;
            }
            EntitiesJob entitiesJob = new EntitiesJob(this, node, this);

            _entitiesJobQueue.Start(entitiesJob);
        }
Exemple #23
0
        public void CategoryNode_copies_itself_as_new_category()
        {
            // ARRANGE

            this.ArrangeSubCategory(out var rootCategory, out var subCategory);

            this.CategoryRepositoryMock
            .Setup(r => r.Root())
            .Returns(rootCategory);

            this.CategoryRepositoryMock // destination name is unused
            .Setup(r => r.FindByParentAndName(rootCategory, "cc"))
            .Returns((Category?)null);

            this.ProviderContextMock
            .Setup(c => c.Persistence)
            .Returns(this.PersistenceMock.Object);

            this.PersistenceMock
            .Setup(m => m.Entities)
            .Returns(this.EntityRepositoryMock.Object);

            this.EntityRepositoryMock // destination name is unused
            .Setup(r => r.FindByCategoryAndName(rootCategory, "cc"))
            .Returns((Entity?)null);

            this.ProviderContextMock
            .Setup(p => p.Recurse)
            .Returns(false);

            this.PersistenceMock
            .Setup(p => p.CopyCategory(subCategory, rootCategory, false));

            var entityContainer = new EntitiesNode();

            // ACT

            new CategoryNode(subCategory).CopyItem(this.ProviderContextMock.Object, "c", "cc", entityContainer);
        }
Exemple #24
0
 public virtual void Enter(EntitiesNode entitiesNode)
 {
 }
Exemple #25
0
 public virtual UstNode Visit(EntitiesNode entitiesNode)
 {
     return(VisitChildren(entitiesNode));
 }
Exemple #26
0
 public virtual void Exit(EntitiesNode entitiesNode)
 {
 }
Exemple #27
0
        /// <summary>
        /// Get a list of Populo entities
        /// </summary>
        /// <param name="url"></param>
        /// <param name="poppuloListType"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        private async Task <List <XmlNode> > GetListEntitiesAsync(string url, PoppuloListType poppuloListType, int?pageSize = null)
        {
            // Documentation: https://developer.poppulo.com/api-basics/api-list.html

            List <XmlNode> ListEntities = new List <XmlNode>();

            url += (pageSize == null || pageSize < 1) ? "" : string.Format(@"?page_size={0}", pageSize);

            string strEntityTypeName, strEntitiesTypeName;

            switch (poppuloListType)
            {
            case PoppuloListType.Accounts:
                strEntityTypeName   = "account";
                strEntitiesTypeName = "accounts";
                break;

            case PoppuloListType.Tags:
                strEntityTypeName   = "tag";
                strEntitiesTypeName = "tags";
                break;

            case PoppuloListType.Subscribers:
                strEntityTypeName   = "subscriber";
                strEntitiesTypeName = "subscribers";
                break;

            default:
                throw new Exception("Unsupported PoppuloListType, please review.");
                break;
            }

            XmlNode EntitiesNode;

            int Page = 0;

            int TotalResults = 0;

            do
            {
                Page++;

                string PageURL = url + ((url.Contains(@"?")) ? @"&" : @"?") + string.Format(@"page={0}", Page);

                string strEntities;

                using (HttpResponseMessage r = await HTTPClientSendAsync(url: PageURL, method: HttpMethod.Get))
                {
                    using (HttpContent c = r.Content)
                    {
                        strEntities = await c.ReadAsStringAsync();
                    }
                }

                XmlDocument XMLPageEntities = new XmlDocument();

                XMLPageEntities.LoadXml(strEntities);

                // extract the nodes
                XmlNodeList EntitiesType = XMLPageEntities.GetElementsByTagName(strEntitiesTypeName);

                if (EntitiesType != null && EntitiesType.Count > 0)
                {
                    EntitiesNode = XMLPageEntities.GetElementsByTagName(strEntitiesTypeName)[0];
                }
                else
                {
                    throw new Exception("No EntitiesType type returned, Please review.");
                }

                // Get the TotalResults
                var TotalResultsNodes = EntitiesNode.SelectNodes("totalResults");

                if (TotalResultsNodes != null)
                {
                    int.TryParse(TotalResultsNodes[0].InnerText, out TotalResults);
                }

                XmlNodeList EntityNodes = XMLPageEntities.GetElementsByTagName(strEntityTypeName);

                foreach (XmlNode n in EntityNodes)
                {
                    ListEntities.Add(n);
                }
            } while (ListEntities.Count < TotalResults);

            return(ListEntities);
        }