示例#1
0
        public void TestDeleteEventsByTitle()
        {
            EventsManager eventManager = new EventsManager();
            EventsProcessor eventProcessor = new EventsProcessor(eventManager);

            DateTime date = DateTime.ParseExact("2011-03-26T09:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

            Event calendarEvent = new Event
            {
                EventDate = date,
                Title = "C# exam",
                Location = null
            };

            EventsManager eventsManager = new EventsManager();

            eventsManager.AddEvent(calendarEvent);

            eventsManager.DeleteEventsByTitle("C# exam");

            IEnumerable<Event> eventsList = eventManager.ListEvents(date, 3);

            int expected = 0;
            int actual = 0;

            foreach (Event currentEvent in eventsList)
            {
                actual++;
            }

            Assert.AreEqual(expected, actual);
        }
示例#2
0
    /// <summary>
    /// Registers all types required to send and receive messages to/from
    /// Azure Service Bus.
    /// </summary>
    /// <param name="hostBuilder">Generic host builder</param>
    /// <param name="registerHandlers">Action to register message handlers in DI container</param>
    /// <param name="subscribeToEvents">Action to map events to their handlers</param>
    /// <param name="options">Azure Service Bus configuration parameters</param>
    /// <returns></returns>
    public static IHostBuilder UseAzureServiceBus(
        this IHostBuilder hostBuilder,
        Action <IServiceCollection> registerHandlers,
        Action <IEventsProcessor> subscribeToEvents,
        Action <ServiceBusConfiguration>?options = null)
    {
        hostBuilder.ConfigureServices((ctx, services) =>
        {
            ServiceBusConfiguration?config = null;
            if (options is not null)
            {
                config = new ServiceBusConfiguration();
                options(config);
            }

            // Common services
            services.AddScoped <IMessageSerializer, MessageSerializer>();

            // Event bus client
            services.AddSingleton <IEventBusClient, EventBusClient>(provider =>
            {
                var configuration = provider.GetRequiredService <IConfiguration>();
                return(new EventBusClient(
                           connectionString: config?.AzureServiceBusConnectionString ??
                           configuration["ServiceBusSettings:EventBusConnection"]));
            });

            // Sending message types
            services.AddScoped <IEventsPublisher, EventsPublisher>();

            // Processing message types
            services.AddSingleton <IEventsSubscriptionManager, EventsSubscriptionManager>();
            services.AddSingleton <IEventsProcessor, EventsProcessor>(provider =>
            {
                var subscriptionManager = provider.GetRequiredService <IEventsSubscriptionManager>();
                var logger             = provider.GetRequiredService <ILogger <EventsProcessor> >();
                var configuration      = provider.GetRequiredService <IConfiguration>();
                var processingPipeline = provider.GetRequiredService <IMessageProcessingPipeline>();
                var eventBusClient     = provider.GetRequiredService <IEventBusClient>();
                var eventProcessor     = new EventsProcessor(
                    subscriptionManager: subscriptionManager,
                    logger: logger,
                    subscriptionClientName: config?.SubscriptionClientName ??
                    configuration["ServiceBusSettings:SubscriptionClientName"],
                    processingPipeline: processingPipeline,
                    eventBusClient: eventBusClient);

                subscribeToEvents(eventProcessor);

                return(eventProcessor);
            });

            services.AddSingleton <IMessageProcessingPipeline, EventProcessingPipeline>();
            services.AddHostedService <EventsProcessorHostedService>();

            registerHandlers(services);
        });

        return(hostBuilder);
    }
示例#3
0
        public void TestAddEvent()
        {
            EventsManager eventManager = new EventsManager();
            EventsProcessor eventProcessor = new EventsProcessor(eventManager);

            DateTime date = DateTime.ParseExact("2012-03-26T09:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

            Event calendarEvent = new Event
            {
                EventDate = date,
                Title = "C# exam",
                Location = null
            };

            EventsManager eventsManager = new EventsManager();

            eventsManager.AddEvent(calendarEvent);

            string expectedTitle = "C# exam";
            string expectedLocation = null;

            IEnumerable<Event> eventsList = eventsManager.ListEvents(date, 1);
            Event testEvent = new Event();

            foreach (Event ev in eventsList)
            {
                testEvent = ev;
            }

            Assert.AreEqual(date, testEvent.EventDate);
            Assert.AreEqual(expectedTitle, testEvent.Title);
            Assert.AreEqual(expectedLocation, testEvent.Location);
        }
示例#4
0
        public void TestListEventsAll()
        {
            EventsManager eventManager = new EventsManager();
            EventsProcessor eventProcessor = new EventsProcessor(eventManager);

            DateTime firstEventDate = DateTime.ParseExact("2009-03-26T12:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

            Event firstEvent = new Event
            {
                EventDate = firstEventDate,
                Title = "C# exam",
                Location = null
            };

            DateTime secondEventDate = DateTime.ParseExact("2010-03-26T10:00:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

            Event secondEvent = new Event
            {
                EventDate = secondEventDate,
                Title = "C# exam",
                Location = "Gabrovo"
            };

            DateTime thirdEventDate = DateTime.ParseExact("2013-03-26T07:43:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

            Event thirdEvent = new Event
            {
                EventDate = thirdEventDate,
                Title = "C# exam",
                Location = null
            };

            DateTime listingDateTime = DateTime.ParseExact("2001-03-26T07:43:00", "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

            EventsManager eventsManager = new EventsManager();

            eventsManager.AddEvent(firstEvent);
            eventsManager.AddEvent(secondEvent);
            eventsManager.AddEvent(thirdEvent);

            IEnumerable<Event> eventsList = eventsManager.ListEvents(listingDateTime, 3);

            int expectedEventsCount = 3;
            int actualEventsCount = 0;

            foreach (Event calendarEv in eventsList)
            {
                actualEventsCount++;
            }

            Assert.AreEqual(expectedEventsCount, actualEventsCount);
        }
示例#5
0
        public BlindDateBot(IBlindDateBotClient botClient, ILogger <BlindDateBot> logger, IConfiguration config)
        {
            _logger = logger;
            _config = config;

            _botClient = botClient.BotClient;

            _updateProcessor = new(_botClient, logger, config);
            _eventsProcessor = new EventsProcessor(botClient.BotClient, logger, config);

            foreach (var date in LoadDatesFromDatabase())
            {
                TransactionsContainer.AddDate(new DateTransactionModel(date));
            }
        }
        public static void Run([TimerTrigger("0 0 6 1/1 * * ", RunOnStartup = true)] TimerInfo myTimer, TraceWriter log, ExecutionContext context)
        {
            var logger = new AppInsightLogger();

            try
            {
                var settingsProvider = new SettingsProvider(context.FunctionAppDirectory, "Values");
                logger.LogInfo($"C# Timer trigger function executing at: {DateTime.Now}");
                var processor = new EventsProcessor(new TableStorage <Event>("Events", settingsProvider.GetSetting("StorageAccountConnectionString")), new NotificationChannelFactory(settingsProvider));

                processor.ProcessEvents();
                logger.LogInfo($"C# Timer trigger function executed at: {DateTime.Now}");
            }
            catch (Exception ex)
            {
                logger.LogException(ex);
            }
        }
        public EventsProcessorFixture()
        {
            ServiceBusProcessor = new FakeServiceBusProcessor();
            ServiceBusClient    = new FakeServiceBusClient(ServiceBusProcessor);

            SubscriptionManager = Mock.Of <IEventsSubscriptionManager>();
            Logger             = Mock.Of <ILogger <EventsProcessor> >();
            ProcessingPipeline = Mock.Of <IMessageProcessingPipeline>();
            EventBusClient     = Mock.Of <IEventBusClient>();
            Mock.Get(EventBusClient)
            .Setup(s => s.Client)
            .Returns(ServiceBusClient);

            Processor = new EventsProcessor(
                SubscriptionManager,
                Logger,
                nameof(EventsProcessor),
                ProcessingPipeline,
                EventBusClient);
        }
 public StartGame(string playerName)
 {
     while (true)
     {
         InitializeEnvironment();
         Random randomGenerator = new Random();
         Game   game            = new Game(Settings.Game.Lifes);
         game.PlayersName = playerName;
         Menu             menu        = new Menu();
         Protagonist      protagonist = new Protagonist();
         List <GameEvent> events      = new List <GameEvent>();
         List <IHostile>  hostiles    = new List <IHostile>();
         hostiles.Add(new Hostile(4, 4));
         MovementHandler     movementHandler   = new MovementHandler();
         EventsProcessor     eventsProcessor   = new EventsProcessor(events, randomGenerator);
         HostilesProcessor   hostilesProcessor = new HostilesProcessor(hostiles, game);
         Display.Board       board             = new Board();
         Display.Information information       = new Information();
         Engine         engine    = new Engine(protagonist, events, hostiles, game, movementHandler, eventsProcessor, hostilesProcessor, board, information, menu);
         ConsoleKeyInfo cki       = new ConsoleKeyInfo();
         Stopwatch      stopwatch = new Stopwatch();
         engine.Start(cki, stopwatch);
     }
 }
示例#9
0
        public EventsProcessorTests(ITestOutputHelper output)
        {
            var logger = output.BuildLoggerFor <EventsProcessor>();  new Mock <ILogger <EventsProcessor> >();

            this.target = new EventsProcessor(logger);
        }
        static void Main(string[] args)
        {
            var processor = new EventsProcessor();

            processor.Run();
        }