Exemple #1
0
        public void when_converting_to_a_storage_event_it_succeeds()
        {
            var id       = Guid.NewGuid();
            var body     = new OrderCreated("TEST-ORDER");
            var metadata = new TestMetadata {
                Value = "TEST-VALUE"
            };
            var sut = new DocumentDbStorageEvent
            {
                StreamId     = "TEST-STREAM",
                Body         = JObject.FromObject(body),
                BodyType     = "OrderCreated",
                Metadata     = JObject.FromObject(metadata),
                MetadataType = "TestMetadata",
                EventNumber  = 1,
                EventId      = id
            };
            var typeMap = new ConfigurableSerializationTypeMap().RegisterTypes(
                typeof(OrderCreated).GetTypeInfo().Assembly,
                t => t.Namespace != null && t.Namespace.EndsWith("Events"),
                t => t.Name);
            var result = sut.ToStorageEvent(typeMap);

            Assert.That(result.StreamId, Is.EqualTo(sut.StreamId));
            Assert.That(((OrderCreated)result.EventBody).OrderId, Is.EqualTo(body.OrderId));
            Assert.That(((TestMetadata)result.Metadata).Value, Is.EqualTo(metadata.Value));
            Assert.That(result.EventNumber, Is.EqualTo(sut.EventNumber));
            Assert.That(result.EventId, Is.EqualTo(sut.EventId));
        }
Exemple #2
0
        public void when_registering_a_type_then_the_name_can_be_found()
        {
            var sut = new ConfigurableSerializationTypeMap();

            sut.RegisterType("OrderCreated", typeof(OrderCreated));

            Assert.That(sut.GetNameFromType(typeof(OrderCreated)), Is.EqualTo("OrderCreated"));
        }
Exemple #3
0
        public void when_registering_multiple_types_then_the_type_can_be_found()
        {
            var sut = new ConfigurableSerializationTypeMap();

            sut.RegisterTypes(typeof(OrderCreated).GetTypeInfo().Assembly, t => t.Namespace != null && t.Namespace.EndsWith("Events"), t => t.Name);

            Assert.That(sut.GetTypeFromName("OrderCreated"), Is.EqualTo(typeof(OrderCreated)));
        }
        static async Task Main(string[] args)
        {
            var config = new ConfigurationBuilder().AddEnvironmentVariables("GraphProjection_").Build();

            var docCollection = new DocumentCollectionInfo()
            {
                CollectionName = config["SourceCollection"],
                Uri            = new Uri(config["Uri"]),
                MasterKey      = config["MasterKey"],
                DatabaseName   = config["SourceDatabase"]
            };

            var auxCollection = new DocumentCollectionInfo()
            {
                CollectionName = config["CheckpointCollection"],
                Uri            = new Uri(config["Uri"]),
                MasterKey      = config["MasterKey"],
                DatabaseName   = config["CheckpointDatabase"]
            };

            var host = new ChangeFeedEventHost(
                "GraphProjectionObserver",
                docCollection,
                auxCollection,
                new ChangeFeedOptions {
                StartFromBeginning = true
            },
                new ChangeFeedHostOptions()
                );

            var typeMap = new ConfigurableSerializationTypeMap()
                          .RegisterTypes(
                typeof(Program).GetTypeInfo().Assembly,
                t => t.Namespace.EndsWith("Events"),
                t => t.Name);

            var client     = new DocumentClient(new Uri(config["GraphUri"]), config["GraphMasterKey"]);
            var collection = await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri("Support", "SupportGraph"));

            await host.RegisterObserverFactoryAsync(new GraphProjectionObserverFactory(client, collection, typeMap));

            Console.WriteLine("Running - press any key to exit");
            Console.Read();
        }
Exemple #5
0
        public void when_registering_multiple_types_if_no_types_are_found_then_an_exception_is_thrown()
        {
            var sut = new ConfigurableSerializationTypeMap();

            Assert.Throws <NoTypesFoundException>(() => sut.RegisterTypes(typeof(OrderCreated).GetTypeInfo().Assembly, t => false, t => t.Name));
        }
Exemple #6
0
        public void when_registering_types_with_a_null_naming_function_then_an_exception_is_thrown()
        {
            var sut = new ConfigurableSerializationTypeMap();

            Assert.Throws <ArgumentNullException>(() => sut.RegisterTypes(typeof(OrderCreated).GetTypeInfo().Assembly, t => true, null));
        }
Exemple #7
0
        public void when_registering_types_with_a_null_assembly_then_an_exception_is_thrown()
        {
            var sut = new ConfigurableSerializationTypeMap();

            Assert.Throws <ArgumentNullException>(() => sut.RegisterTypes(null, t => true, t => t.Name));
        }
Exemple #8
0
        public void when_registering_a_type_with_a_null_type_then_an_exception_is_thrown()
        {
            var sut = new ConfigurableSerializationTypeMap();

            Assert.Throws <ArgumentNullException>(() => sut.RegisterType("TEST", null));
        }
Exemple #9
0
        public void when_registering_a_type_with_a_null_event_type_then_an_exception_is_thrown()
        {
            var sut = new ConfigurableSerializationTypeMap();

            Assert.Throws <ArgumentException>(() => sut.RegisterType(null, typeof(OrderCreated)));
        }