Beispiel #1
0
        public void property_exists_save_should_update_property()
        {
            //arange

            string value  = Guid.NewGuid().ToString();
            string value2 = Guid.NewGuid().ToString();
            string id     = "12345";

            var setsContainer = new AttributeSetsContainer();

            var attsetsMock = MockFactory.CreateAttributeSets(setsContainer);

            var setContainer = new AttributeSetContainer();

            setContainer.Name = "one";
            var attributeSet = MockFactory.CreateAttributeSet(setContainer, attsetsMock.Object).Object;

            setsContainer.AttributeSets.Add(attributeSet);
            setContainer.Attributes.Add(MockFactory.CreateAttribute(id, ValueTypeEnum.kStringType, value, attributeSet));
            var applicationMock = new Mock <IApplicationService>();

            applicationMock.Setup(x => x.GetCurrentDocumentAttributeSets()).Returns(attsetsMock.Object);

            var businessClass = new MyBusinessClass(applicationMock.Object);

            //act

            businessClass.SaveMyProperty(value2, id);

            //assert

            setContainer.Attributes.Count.Should().Be(1);

            (setContainer.Attributes[1].Value as string).Should().Be(value2);
        }
        public static Mock <AttributeSet> CreateAttributeSet(AttributeSetContainer container, AttributeSets parent)
        {
            var attMock = new Mock <AttributeSet>();

            attMock.Setup(x => x.Name).Returns(container.Name);
            attMock.As <AttributeSet>().Setup(x => x.Count).Returns(() =>
            {
                return(container.Attributes.Count);
            });
            attMock.Setup(m => m[It.IsAny <int>()]).Returns <int>(i => container.Attributes.ElementAt(i).Value);
            attMock.As <IEnumerable>().Setup(m => m.GetEnumerator()).Returns(() => container.Attributes.GetEnumerator());
            attMock.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <ValueTypeEnum>(), It.IsAny <object>()))
            .Returns <string, ValueTypeEnum, object>(
                (s, v, o) =>
            {
                var item = MockFactory.CreateAttribute(s, v, o, attMock.Object);
                container.Attributes.Add(item);
                return(item);
            });
            attMock.Setup(x => x.get_NameIsUsed(It.IsAny <string>())).Returns <string>(r => container.Attributes.Any(y => y.Name == r));
            attMock.Setup(x => x.Parent).Returns(parent);
            return(attMock);
        }