Exemplo n.º 1
0
        public void BuildInnerExpressionPath()
        {
            //Property to set
            System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty");


            //expression and binding item
            string expr = "Root.Value";
            BindingItemExpression itembind = BindingItemExpression.Create(expr, prop);

            //Set the items value to be extracted as an inner property on the source
            PDFDataBindEventArgs args = CreateDataBindArgs();
            string     expected       = "This is the test";
            FakeSource root           = new FakeSource();

            root.Value = expected;

            args.Context.Items["Root"] = root;

            //bind the recipient - should have its property set to the item value
            FakeRecipient recip = new FakeRecipient();

            itembind.BindComponent(recip, args);

            string actual = recip.StringProperty;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void DistributeAsync_DistributesMultipleAtATimeByDefault()
        {
            var distributable1 = new FakeDistributable();
            var distributable2 = new FakeDistributable();
            var recipient = new FakeRecipient();
            var endpoint = new FakeEndpoint();

            var distributor = new Distributor<FakeDistributable, FakeRecipient>();

            var deliverer = new FakeLoggedDeliverer<FakeDistributable, FakeEndpoint>(new TimeSpan(0, 0, 0, 0, 100));

            var endpointRepository = new Mock<IEndpointRepository<FakeRecipient>>();
            endpointRepository.Setup(e => e.GetEndpointsForRecipient(recipient))
                .Returns(new[] { endpoint });

            distributor.RegisterDeliverer(deliverer);
            distributor.RegisterEndpointRepository(endpointRepository.Object);

            var task1 = distributor.DistributeAsync(distributable1, recipient);
            var task2 = distributor.DistributeAsync(distributable2, recipient);

            Task.WaitAll(task1, task2);

            var lastStartTime = deliverer.LogEntries.Max(e => e.StartDateTime);
            var firstEndTime = deliverer.LogEntries.Min(e => e.EndDateTime);

            lastStartTime.ShouldBeLessThan(firstEndTime);
        }
Exemplo n.º 3
0
        public void BuildInnerDynamicExpressionPath()
        {
            string  expected = "This is a dynamic property value";
            dynamic data     = new ExpandoObject();

            data.MyProperty = expected;

            //expression and binding item
            string expr = "Dynamic.MyProperty";

            //Property to set
            System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty");


            //Create the expression binding
            BindingItemExpression itembind = BindingItemExpression.Create(expr, prop);

            //Set the items value to be extracted as an inner property on the source
            PDFDataBindEventArgs args = CreateDataBindArgs();

            //Set the root entry to the top of the object braph
            args.Context.Items["Dynamic"] = data;

            //bind the recipient - should have its property set to the item value
            FakeRecipient recip = new FakeRecipient();

            itembind.BindComponent(recip, args);

            //String Property should be set to the expected value
            string actual = recip.StringProperty;

            Assert.AreEqual(expected, actual);

            //
            // with string indexing
            //

            expected        = "This is another dynamic property value";
            data.MyProperty = expected;

            //Create the expression binding
            expr     = "Dynamic['MyProperty']";
            itembind = BindingItemExpression.Create(expr, prop);

            //Set the items value to be extracted as an inner property on the source
            args = CreateDataBindArgs();

            //Set the root entry to the top of the object braph
            args.Context.Items["Dynamic"] = data;

            //bind the recipient - should have its property set to the item value
            recip = new FakeRecipient();
            itembind.BindComponent(recip, args);

            //String Property should be set to the expected value
            actual = recip.StringProperty;
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void DistributeAsync_DeliversToAnEndpointTypeWithNoDelivererThrowsAnError()
        {
            var distributable = new FakeDistributable();
            var recipient = new FakeRecipient();
            var endpoint = new FakeEndpoint();

            var endpointRepository = new Mock<IEndpointRepository<FakeRecipient>>();
            endpointRepository.Setup(e => e.GetEndpointsForRecipient(recipient))
                .Returns(new[] { endpoint });

            var distributor = new Distributor<FakeDistributable, FakeRecipient>();
            distributor.RegisterEndpointRepository(endpointRepository.Object);

            Should.ThrowAsync<InvalidOperationException>(distributor.DistributeAsync(distributable, recipient));
        }
Exemplo n.º 5
0
        public void BuildInnerInnerKeyedExpressionPath()
        {
            //Build the object graph
            string     expected   = "This is the test";
            FakeSource innerinner = new FakeSource();

            innerinner.Value = expected;

            FakeSource inner = new FakeSource();

            inner.Keys          = new Dictionary <string, FakeSource>();
            inner.Keys["First"] = innerinner;

            FakeSource root = new FakeSource();

            root.Items = new List <FakeSource>();
            root.Items.Add(null);
            root.Items.Add(inner);

            //expression and binding item
            string expr = "Root.Items[1].Keys['First'].Value";

            //Property to set
            System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty");


            //Create the expression binding
            BindingItemExpression itembind = BindingItemExpression.Create(expr, prop);

            //Set the items value to be extracted as an inner property on the source
            PDFDataBindEventArgs args = CreateDataBindArgs();

            //Set the root entry to the top of the object braph
            args.Context.Items["Root"] = root;

            //bind the recipient - should have its property set to the item value
            FakeRecipient recip = new FakeRecipient();

            itembind.BindComponent(recip, args);

            //String Property should be set to the expected value
            string actual = recip.StringProperty;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void DistributeAsync_DeliversADistributableToARegisteredDeliverer()
        {
            var distributable = new FakeDistributable();
            var recipient = new FakeRecipient();
            var endpoint = new FakeEndpoint();

            var deliverer = new Mock<IDeliverer<FakeDistributable, FakeEndpoint>>();
            var endpointRepository = new Mock<IEndpointRepository<FakeRecipient>>();
            endpointRepository.Setup(e => e.GetEndpointsForRecipient(recipient))
                .Returns(new [] { endpoint });

            var distributor = new Distributor<FakeDistributable, FakeRecipient>();
            distributor.RegisterEndpointRepository(endpointRepository.Object);
            distributor.RegisterDeliverer(deliverer.Object);

            distributor.DistributeAsync(distributable, recipient).Wait();

            deliverer.Verify(eds => eds.DeliverAsync(distributable, (IEndpoint) endpoint), Times.Once);
        }
Exemplo n.º 7
0
        public void BuildNotSetExpressionPath()
        {
            //Property to set
            System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty");


            //expression and binding item
            string expr = "Root";
            BindingItemExpression itembind = BindingItemExpression.Create(expr, prop);

            //DO NOT Set the items value to be extracted
            PDFDataBindEventArgs args = CreateDataBindArgs();
            //string expected = "This is the test";
            //args.Context.Items["Root"] = expected;

            //bind the recipient - should have its property set to the item value
            FakeRecipient recip = new FakeRecipient();

            itembind.BindComponent(recip, args);

            string actual = recip.StringProperty;

            Assert.IsNull(actual);
        }
Exemplo n.º 8
0
        public void DistributeAsync_DoesNotUseTheFirstDelivererWhenTwoAreRegistered()
        {
            var distributable = new FakeDistributable();
            var recipient = new FakeRecipient();
            var endpoint = new FakeEndpoint();

            var deliverer1 = new Mock<IDeliverer<FakeDistributable, FakeEndpoint>>();
            var deliverer2 = new Mock<IDeliverer<FakeDistributable, FakeEndpoint>>();
            var endpointRepository = new Mock<IEndpointRepository<FakeRecipient>>();
            endpointRepository.Setup(e => e.GetEndpointsForRecipient(recipient))
                .Returns(new[] { endpoint });

            var distributor = new Distributor<FakeDistributable, FakeRecipient>();
            distributor.RegisterEndpointRepository(endpointRepository.Object);
            distributor.RegisterDeliverer(deliverer1.Object);
            distributor.RegisterDeliverer(deliverer2.Object);

            distributor.DistributeAsync(distributable, recipient).Wait();

            deliverer1.Verify(eds => eds.DeliverAsync(distributable, (IEndpoint) endpoint), Times.Never);
        }