public async Task StatusLoadAndSafe_OneUnresolvedReadModel(PersistenceLayerProvider layerProvider)
        {
            var statusRepository = layerProvider.StatusRepository;

            List <EventsPublishedByService> services = new List <EventsPublishedByService> {
                EventsPublishedByService.Reachable(new ServiceEndPoint(new Uri("http://service1.de"), "Name1"), new []
                {
                    new EventSchema("Event1"),
                    new EventSchema("Event2")
                })
            };
            var subscribedEventCollection = new EventsSubscribedByService(
                new []
            {
                new EventSchema("Event1"),
                new EventSchema("Event2")
            },
                new [] { new ReadModelSubscription("Rm1", new EventSchema("Event3")) });
            var eventLocation = new EventLocation(services, subscribedEventCollection);

            await statusRepository.SaveEventLocation(eventLocation);

            await statusRepository.SaveEventLocation(eventLocation);

            var location = await statusRepository.GetEventLocation();

            Assert.AreEqual("Rm1", location.UnresolvedReadModeSubscriptions.Single().ReadModelName);
            Assert.AreEqual("Event3", location.UnresolvedReadModeSubscriptions.Single().GetsCreatedOn.Name);
            Assert.IsTrue(!location.UnresolvedEventSubscriptions.Any());
        }
Exemplo n.º 2
0
        public async Task <EventsPublishedByService> GetPublishedEventTypes(Uri serviceAdress)
        {
            var client = await _factory.GetClient(serviceAdress);

            try
            {
                var response = await client.GetAsync("Dicovery/PublishedEvents");

                _logger.LogTrace($"Response for Servicediscovery was {response.StatusCode}");
                if (!response.IsSuccessStatusCode)
                {
                    return(EventsPublishedByService.NotReachable(new ServiceEndPoint(serviceAdress)));
                }
                var content = await response.Content.ReadAsStringAsync();

                var events = JsonConvert.DeserializeObject <PublishedEventsByServiceDto>(content);

                return(EventsPublishedByService.Reachable(
                           new ServiceEndPoint(serviceAdress, events.ServiceName),
                           events.PublishedEvents));
            }
            catch (HttpRequestException)
            {
                return(EventsPublishedByService.NotReachable(new ServiceEndPoint(serviceAdress)));
            }
            catch (IOException)
            {
                return(EventsPublishedByService.NotReachable(new ServiceEndPoint(serviceAdress)));
            }
        }
        public async Task StatusLoadAndSafe_HappyPath(PersistenceLayerProvider layerProvider)
        {
            var statusRepository = layerProvider.StatusRepository;

            List <EventsPublishedByService> services = new List <EventsPublishedByService> {
                EventsPublishedByService.Reachable(new ServiceEndPoint(new Uri("http://service1.de"), "Name1"), new []
                {
                    new EventSchema("Event1"),
                    new EventSchema("Event2"),
                    new EventSchema("Event3")
                })
            };
            var subscribedEventCollection = new EventsSubscribedByService(
                new []
            {
                new EventSchema("Event1"),
                new EventSchema("Event2")
            },
                new [] { new ReadModelSubscription("Rm1", new EventSchema("Event3")) });
            var eventLocation = new EventLocation(services, subscribedEventCollection);

            await statusRepository.SaveEventLocation(eventLocation);

            var location = await statusRepository.GetEventLocation();

            var microwaveServiceNodes = location.Services.ToList();

            Assert.IsNotNull(microwaveServiceNodes);
            Assert.AreEqual(1, microwaveServiceNodes.Count);
            Assert.AreEqual(2, microwaveServiceNodes[0].SubscribedEvents.Count());
            Assert.AreEqual(1, microwaveServiceNodes[0].ReadModels.Count());
            Assert.IsTrue(!location.UnresolvedEventSubscriptions.Any());
            Assert.IsTrue(!location.UnresolvedReadModeSubscriptions.Any());
        }
Exemplo n.º 4
0
        public void SubscribedEventPropertiesArePropertiesOfConsumingService()
        {
            var eventLocation = new EventLocation(
                new List <EventsPublishedByService>
            {
                EventsPublishedByService.Reachable(
                    new ServiceEndPoint(new Uri("http://jeah.de")), new []
                {
                    new EventSchema("Event2",
                                    new [] { new PropertyType("VorName", "String"),
                                             new PropertyType("LastName", "Int") })
                })
            },
                new EventsSubscribedByService(
                    new List <EventSchema> {
                new EventSchema("Event2", new [] { new PropertyType("VorName", "String"), })
            },
                    new [] { new ReadModelSubscription("ReadModel2", new EventSchema("Event1")) }));

            var serviceAfter2 = eventLocation.GetServiceForEvent(typeof(Event2));

            Assert.AreEqual(nameof(Event2), serviceAfter2.SubscribedEvents.Single().Name);
            Assert.AreEqual("VorName", serviceAfter2.SubscribedEvents.Single().Properties.Single().Name);
            Assert.AreEqual("String", serviceAfter2.SubscribedEvents.Single().Properties.Single().Type);
        }
Exemplo n.º 5
0
        public async Task OnGetAsync()
        {
            var consumingServices = await _discoveryHandler.GetConsumingServices();

            var publishedEvents = await _discoveryHandler.GetPublishedEvents();

            ConsumingServices = consumingServices;
            PublishedEvents   = publishedEvents;
        }
Exemplo n.º 6
0
 public DiscoveryHandler(
     ServiceBaseAddressCollection serviceBaseAddressCollection,
     EventsSubscribedByService eventsSubscribedByService,
     EventsPublishedByService eventsPublishedByService,
     IServiceDiscoveryRepository discoveryRepository,
     IStatusRepository statusRepository,
     DiscoveryConfiguration configuration)
 {
     _serviceBaseAddressCollection = serviceBaseAddressCollection;
     _eventsSubscribedByService    = eventsSubscribedByService;
     _eventsPublishedByService     = eventsPublishedByService;
     _discoveryRepository          = discoveryRepository;
     _statusRepository             = statusRepository;
     _configuration = configuration;
 }
        public async Task GetPublishedEvents()
        {
            var discoveryHandler = new DiscoveryHandler(
                null,
                null,
                EventsPublishedByService.Reachable(
                    new ServiceEndPoint(null),
                    new List <EventSchema>()),
                null,
                null,
                null);

            var events = await discoveryHandler.GetPublishedEvents();

            Assert.IsNotNull(events);
        }
Exemplo n.º 8
0
        public async Task GetConsumingServices()
        {
            var mock = new Mock <IDiscoveryHandler>();

            mock.Setup(m => m.GetConsumingServices()).ReturnsAsync(new EventLocation(
                                                                       new List <MicrowaveServiceNode>(),
                                                                       new List <EventSchema>(),
                                                                       new List <ReadModelSubscription>()));

            mock.Setup(m => m.GetPublishedEvents()).ReturnsAsync(EventsPublishedByService.Reachable(new
                                                                                                    ServiceEndPoint(null), new List <EventSchema>()));
            var indexModel = new IndexModel(mock.Object, new MicrowaveWebApiConfiguration());

            await indexModel.OnGetAsync();

            Assert.IsNotNull(indexModel.ConsumingServices);
        }
        private static void AddPublishedEventCollection(IServiceCollection services,
                                                        IEnumerable <Assembly> domainEventAssemblies, MicrowaveWebApiConfiguration microwaveWebApiConfiguration)
        {
            var publishedEvents = new List <EventSchema>();

            foreach (var assembly in domainEventAssemblies)
            {
                var eventsForPublish = GetEventsForPublish(assembly);
                var notAddedYet      = eventsForPublish.Where(e => publishedEvents.All(w => w.Name != e.Name));
                publishedEvents.AddRange(notAddedYet);
            }

            var publishedEventCollection = EventsPublishedByService.Reachable(
                new ServiceEndPoint(null, microwaveWebApiConfiguration.ServiceName),
                publishedEvents);

            services.AddSingleton(publishedEventCollection);
        }
Exemplo n.º 10
0
        public async Task GetPublishedEvents()
        {
            var mock = new Mock <IDiscoveryHandler>();
            var eventsPublishedByService = EventsPublishedByService.Reachable(
                new ServiceEndPoint(new Uri("http://123.de"), "Name"),
                new List <EventSchema>());

            mock.Setup(m => m.GetPublishedEvents()).ReturnsAsync(eventsPublishedByService);
            var discoveryController = new DiscoveryController(mock.Object);

            await discoveryController.GetPublishedEvents();

            var result = await discoveryController.GetPublishedEvents();

            var viewResult = result as OkObjectResult;
            var publishedEventsByServiceDto = viewResult.Value as PublishedEventsByServiceDto;

            Assert.AreEqual(0, publishedEventsByServiceDto.PublishedEvents.Count);
            Assert.AreEqual("Name", publishedEventsByServiceDto.ServiceName);
        }
Exemplo n.º 11
0
        public void ReadmodelProperties_PropertyNotFound()
        {
            var eventLocation = new EventLocation(
                new List <EventsPublishedByService>
            {
                EventsPublishedByService.Reachable(
                    new ServiceEndPoint(new Uri("http://jeah.de")), new []
                {
                    new EventSchema("Event2",
                                    new [] { new PropertyType("VorName", "String"),
                                             new PropertyType("LastName", "Int") })
                })
            },
                new EventsSubscribedByService(
                    new List <EventSchema>(),
                    new [] { new ReadModelSubscription("ReadModel2", new EventSchema("Event2",
                                                                                     new []
                {
                    new PropertyType("VorNameNotInService", "String"),
                    new PropertyType("VorName", "String")
                })) }));

            var service = eventLocation.GetServiceForReadModel(typeof(ReadModel2));

            Assert.AreEqual(nameof(ReadModel2), service.ReadModels.Single().ReadModelName);
            var getsCreatedOn = service.ReadModels.Single().GetsCreatedOn;
            var propertyTypes = getsCreatedOn.Properties.ToList();

            Assert.AreEqual(2, propertyTypes.Count);
            Assert.AreEqual(nameof(Event2), getsCreatedOn.Name);

            Assert.AreEqual("VorNameNotInService", propertyTypes[0].Name);
            Assert.AreEqual("String", propertyTypes[0].Type);
            Assert.IsFalse(propertyTypes[0].IsPresentInRemote);

            Assert.AreEqual("VorName", propertyTypes[1].Name);
            Assert.AreEqual("String", propertyTypes[1].Type);
            Assert.IsTrue(propertyTypes[1].IsPresentInRemote);
        }
Exemplo n.º 12
0
        public void AddFeedDoesReplaceOldOne()
        {
            var eventLocation = new EventLocation(
                new List <EventsPublishedByService>
            {
                EventsPublishedByService.Reachable(
                    new ServiceEndPoint(new Uri("http://jeah.de")), new []
                {
                    new EventSchema("Event2")
                })
            },
                new EventsSubscribedByService(
                    new List <EventSchema> {
                new EventSchema("Event2")
            },
                    new [] { new ReadModelSubscription("ReadModel2", new EventSchema("Event1")) }));

            var serviceAfter2 = eventLocation.GetServiceForEvent(typeof(Event2));
            var serviceAfter1 = eventLocation.GetServiceForEvent(typeof(Event1));

            Assert.AreEqual(nameof(Event2), serviceAfter2.SubscribedEvents.Single().Name);
            Assert.IsNull(serviceAfter1);
        }