Ejemplo n.º 1
0
        public void property_does_not_exists_save_should_create_property()
        {
            //arange

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

            var container   = new AttributeSetsContainer();
            var attsetsMock = MockFactory.CreateAttributeSets(container);

            var applicationMock = new Mock <IApplicationService>();

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

            var businessClass = new MyBusinessClass(applicationMock.Object);

            //act

            businessClass.SaveMyProperty(value, id);

            //assert

            container.AttributeSets.Count.Should().Be(1);
            container.AttributeSets.Single(x => x.Name == "one").Should().NotBeNull();
            var containerAttributeSet = container.AttributeSets[1]; // somehow COM starts a 1 not at zero

            var containerAttribute = containerAttributeSet[id];

            (containerAttribute.Value as string).Should().Be(value);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static Mock <AttributeSets> CreateAttributeSets(AttributeSetsContainer container)
        {
            var attSetsMock = new Mock <AttributeSets>();

            attSetsMock.Setup(x => x.Count).Returns(() => { return(container.AttributeSets.Count); });
            attSetsMock.Setup(m => m[It.IsAny <int>()]).Returns <int>(i => container.AttributeSets.ElementAt(i));
            attSetsMock.As <IEnumerable>().Setup(m => m.GetEnumerator()).Returns(() => container.AttributeSets.GetEnumerator());
            attSetsMock.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns <string, bool>(
                (s, b) =>
            {
                var c = new AttributeSetContainer()
                {
                    Name = s
                };
                var attributeSet = CreateAttributeSet(c, attSetsMock.Object);
                container.Containers.Add(c);
                container.AttributeSets.Add(attributeSet.Object);

                return(attributeSet.Object);
            });
            attSetsMock.Setup(x => x.get_NameIsUsed(It.IsAny <string>())).Returns <string>(r => container.AttributeSets.Any(y => y.Name == r));

            return(attSetsMock);
        }