Esempio n. 1
0
        public void CategoryNode_creating_category_fails_on_duplicate_category_name()
        {
            // ARRANGE

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

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

            var category = DefaultCategory();

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(category, "c"))
            .Returns(DefaultCategory());

            var node = new CategoryNode(category);

            // ACT

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

            // ASSERT

            Assert.Equal($"Name is already used by and item of type '{nameof(TreeStoreItemType.Category)}'", result.Message);
        }
Esempio n. 2
0
        public void CategoryNode_rejects_creating_EntityNodeValue_with_duplicate_category_name()
        {
            // ARRANGE

            //todo: create entity with tag
            //this.ProviderContextMock
            //    .Setup(c => c.DynamicParameters)
            //    .Returns((object?)null);

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

            var category = DefaultCategory();

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

            this.CategoryRepositoryMock
            .Setup(r => r.FindByParentAndName(category, "Entity"))
            .Returns(DefaultCategory());

            var node = new CategoryNode(category);

            // ACT

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

            // ASSERT

            Assert.Equal($"Name is already used by and item of type '{nameof(TreeStoreItemType.Category)}'", result.Message);
        }
Esempio n. 3
0
        public void CategoryNode_creates_entity(string itemTypeName)
        {
            // ARRANGE

            //todo: create entity with tag
            //this.ProviderContextMock
            //    .Setup(c => c.DynamicParameters)
            //    .Returns((object?)null);

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

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

            var category = DefaultCategory();

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

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

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

            Entity createdEntity = null;

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

            var node = new CategoryNode(category);

            // ACT

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

            // ASSERT

            Assert.IsType <EntityNode>(result);
            Assert.Equal("Entity", createdEntity !.Name);
            Assert.Same(category, createdEntity !.Category);
        }
Esempio n. 4
0
        public void CategoryNode_creating_rejects_invalid_name_chararcters(char invalidChar)
        {
            // ARRANGE

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

            // ACT

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

            // ASSERT

            Assert.Equal($"category(name='{invalidName}' wasn't created: it contains invalid characters", result.Message);
        }
Esempio n. 5
0
        public void CategoryNode_creates_category()
        {
            // ARRANGE

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

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

            var category = DefaultCategory();

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

            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(category, "c"))
            .Returns((Entity?)null);

            var node = new CategoryNode(category);

            // ACT

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

            // ASSERT

            Assert.IsType <CategoryNode>(result);
        }