public void Transform_Invokes_Property_Transformer()
        {
            const string name = "name";
            const string value = "1";

            var transformerMock1 = new Mock<IValueTransformer>();
            transformerMock1.Setup(x => x.Transform(value, name, It.IsAny<PropertyInfo>()))
                .Returns(value);
            transformerMock1.Setup(x => x.Order)
                .Returns(20);

            var transformerMock2 = new Mock<IValueTransformer>();
            transformerMock2.Setup(x => x.Transform(value, name, It.IsAny<PropertyInfo>()))
                .Returns(value);
            transformerMock2.Setup(x => x.Order)
                .Returns(10);

            var propertyInfoMock = new Mock<PropertyInfo>();
            propertyInfoMock.Setup(p => p.GetCustomAttributes(true))
                .Returns(() => new object[] { transformerMock1.Object });

            var transformer = new AggregateTransformer(transformerMock2.Object);

            var result = transformer.Transform(value, name, propertyInfoMock.Object);

            propertyInfoMock.Verify(p => p.GetCustomAttributes(true), Times.Once);
            transformerMock1.Verify(x => x.Transform(value, name, It.IsAny<PropertyInfo>()), Times.Once);
            transformerMock2.Verify(x => x.Transform(value, name, It.IsAny<PropertyInfo>()), Times.Once);
            Assert.AreEqual(value, result);
        }
        public void Transform_Invokes_All_Transformers_In_Order()
        {
            const string name = "some value";
            const string value = "1";

            var transformerMock1 = new Mock<IValueTransformer>();
            transformerMock1.Setup(x => x.Transform(value, name, null))
                .Returns(value);
            transformerMock1.Setup(x => x.Order)
                .Returns(20);

            var transformerMock2 = new Mock<IValueTransformer>();
            transformerMock2.Setup(x => x.Transform(value, name, null))
                .Returns(value);
            transformerMock2.Setup(x => x.Order)
                .Returns(10);

            var transformer = new AggregateTransformer(transformerMock1.Object, transformerMock2.Object);

            var result = transformer.Transform(value, name, null);

            transformerMock1.Verify(x => x.Transform(value, name, null), Times.Once);
            transformerMock1.Verify(x => x.Transform(value, name, null), Times.Once);
            Assert.AreEqual(value, result);
        }
Exemple #3
0
        public void Transform_Invokes_Property_Transformer()
        {
            const string name  = "name";
            const string value = "1";

            var transformerMock1Attribute = new Mock <Attribute>();
            var transformerMock1          = transformerMock1Attribute.As <IValueTransformer>();

            transformerMock1.Setup(x => x.Transform(value, name, It.IsAny <ICustomAttributeProvider>()))
            .Returns(value);
            transformerMock1.Setup(x => x.Order)
            .Returns(20);

            var transformerMock2 = new Mock <IValueTransformer>();

            transformerMock2.Setup(x => x.Transform(value, name, It.IsAny <ICustomAttributeProvider>()))
            .Returns(value);
            transformerMock2.Setup(x => x.Order)
            .Returns(10);

            var ICustomAttributeProviderMock = new Mock <ICustomAttributeProvider>();

            ICustomAttributeProviderMock.Setup(p => p.GetCustomAttributes(true))
            .Returns(() => new object[] { transformerMock1Attribute.Object });

            var transformer = new AggregateTransformer(transformerMock2.Object);

            var result = transformer.Transform(value, name, ICustomAttributeProviderMock.Object);

            ICustomAttributeProviderMock.Verify(p => p.GetCustomAttributes(true), Times.Once);
            transformerMock1.Verify(x => x.Transform(value, name, It.IsAny <ICustomAttributeProvider>()), Times.Once);
            transformerMock2.Verify(x => x.Transform(value, name, It.IsAny <ICustomAttributeProvider>()), Times.Once);
            Assert.AreEqual(value, result);
        }
Exemple #4
0
        public void Transform_Invokes_All_Transformers_In_Order()
        {
            const string name  = "some value";
            const string value = "1";

            var transformerMock1 = new Mock <IValueTransformer>();

            transformerMock1.Setup(x => x.Transform(value, name, null))
            .Returns(value);
            transformerMock1.Setup(x => x.Order)
            .Returns(20);

            var transformerMock2 = new Mock <IValueTransformer>();

            transformerMock2.Setup(x => x.Transform(value, name, null))
            .Returns(value);
            transformerMock2.Setup(x => x.Order)
            .Returns(10);

            var transformer = new AggregateTransformer(transformerMock1.Object, transformerMock2.Object);

            var result = transformer.Transform(value, name, null);

            transformerMock1.Verify(x => x.Transform(value, name, null), Times.Once);
            transformerMock1.Verify(x => x.Transform(value, name, null), Times.Once);
            Assert.AreEqual(value, result);
        }
        public void PassesEventsToSubTransformers()
        {
            var testEvent = TestIDEEvent(0, 1);

            var subTransformer1 = Mock.Of <IEventToIntervalTransformer <TestInterval> >();
            var subTransformer2 = Mock.Of <IEventToIntervalTransformer <TestInterval> >();
            var sut             = new AggregateTransformer(subTransformer1, subTransformer2);

            sut.ProcessEvent(testEvent);
            Mock.Get(subTransformer1).Verify(t => t.ProcessEvent(testEvent));
            Mock.Get(subTransformer2).Verify(t => t.ProcessEvent(testEvent));
        }
        public void ReturnsAllIntervalsFromSubTransformers()
        {
            var testInterval1 = ExpectedInterval(0, 1);
            var testInterval2 = ExpectedInterval(2, 3);

            var subTransformer1 = Mock.Of <IEventToIntervalTransformer <TestInterval> >();

            Mock.Get(subTransformer1).Setup(t => t.SignalEndOfEventStream()).Returns(new[] { testInterval1 });
            var subTransformer2 = Mock.Of <IEventToIntervalTransformer <TestInterval> >();

            Mock.Get(subTransformer2).Setup(t => t.SignalEndOfEventStream()).Returns(new[] { testInterval2 });

            var sut = new AggregateTransformer(subTransformer1, subTransformer2);

            CollectionAssert.AreEquivalent(new[] { testInterval1, testInterval2 }, sut.SignalEndOfEventStream());
        }