Пример #1
0
        public void CreateThrowsForNull()
        {
            Assert.ThrowsException <ArgumentNullException>(
                () => Projection.Create <object>((Func <int, object>)null));

            Assert.ThrowsException <ArgumentNullException>(
                () => Projection.Create <object, object>((Func <object, object>)null));
        }
Пример #2
0
        public void CreateCreatesFromPublicTypes()
        {
            var created = Projection.Create(MyPublicMethodIntToObject);

            Assert.AreEqual(23, created[23]);

            created = Projection.Create(MyPublicMethodIntToObjectStatic);
            Assert.AreEqual(23, created[23]);

            var createdGeneric = Projection.Create(MyGenericPublicMethod <int, MyGenericPublicMethodReturnValue <int> >);

            Assert.AreEqual(23, createdGeneric[23].Argument);

            createdGeneric = Projection.Create(MyGenericPublicMethodStatic <int, MyGenericPublicMethodReturnValue <int> >);
            Assert.AreEqual(23, createdGeneric[23].Argument);
        }
Пример #3
0
        public async Task Pipelines_affect_projections_in_reverse_order_relative_to_the_Pipeline_calls_when_next_is_called_after_modifying_the_projection()
        {
            var aggregator = Aggregator.Create <Projection <List <int>, string>, string>(async(projection, events) => projection.Value.Add(1))
                             .Pipeline(async(projection, batch, next) =>
            {
                projection.Value.Add(2);
                await next(projection, batch);
                return(projection);
            })
                             .Pipeline(async(projection, batch, next) =>
            {
                projection.Value.Add(3);
                await next(projection, batch);
                return(projection);
            });

            var result = await aggregator.Aggregate(Projection.Create(new List <int>(), ""), null);

            result.Value.Should().BeInDescendingOrder();
        }
Пример #4
0
        public async Task Pipelines_affect_projections_in_the_same_order_as_the_Pipeline_calls_when_next_is_called_before_modifying_the_projection()
        {
            var aggregator = Aggregator.Create <Projection <List <int>, string>, string>(async(projection, events) => projection.Value.Add(1))
                             .Pipeline(async(projection, batch, next) =>
            {
                await next(projection, batch);
                projection.Value.Add(2);
                return(projection);
            })
                             .Pipeline(async(projection, batch, next) =>
            {
                await next(projection, batch);
                projection.Value.Add(3);
                return(projection);
            });

            var result = await aggregator.Aggregate(Projection.Create(new List <int>(), ""), null);

            Console.WriteLine(result.ToLogString());

            result.Value.Should().BeInAscendingOrder();
        }
Пример #5
0
        public void CreateRejectsNonPublicMethods()
        {
            // int, T

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyPrivateMethodIntToObject));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyPrivateMethodIntToObjectStatic));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyProtectedMethodIntToObject));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyProtectedMethodIntToObjectStatic));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyInternalMethodIntToObject));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyInternalMethodIntToObjectStatic));

            // T1,T2

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyGenericPrivateMethod <int, object>));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyGenericPrivateMethodStatic <int, object>));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyGenericProtectedMethod <int, object>));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyGenericProtectedMethodStatic <int, object>));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyGenericInternalMethod <int, object>));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(MyGenericInternalMethodStatic <int, object>));

            // non-public nested

            var internalInstance = new InternalNestedType();

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(internalInstance.Method));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(InternalNestedType.MethodStatic));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(internalInstance.MethodGeneric <int, object>));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(InternalNestedType.MethodGenericStatic <int, object>));

            var protectedInstance = new ProtectedNestedType();

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(protectedInstance.Method));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(ProtectedNestedType.MethodStatic));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(protectedInstance.MethodGeneric <int, object>));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(ProtectedNestedType.MethodGenericStatic <int, object>));

            var privateInstance = new PrivateNestedType();

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(privateInstance.Method));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(PrivateNestedType.MethodStatic));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(privateInstance.MethodGeneric <int, object>));
            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create(PrivateNestedType.MethodGenericStatic <int, object>));

            // anonymous

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create <int, object>(i => i));

            Assert.ThrowsException <InvalidOperationException>(
                () => Projection.Create <DateTime, string>(x => x.ToString()));
        }