Beispiel #1
0
        public async Task LastWriteWinsConsistency()
        {
            Func <IDialog <object> > MakeRoot = () => chain;

            using (new FiberTestBase.ResolveMoqAssembly(chain))
                using (var container = Build(Options.MockConnectorFactory | Options.LastWriteWinsCachingBotDataStore, chain))
                {
                    var msg = DialogTestBase.MakeTestMessage();
                    msg.Text = "test";
                    using (var scope = DialogModule.BeginLifetimeScope(container, msg))
                    {
                        connectorFactory = scope.Resolve <IConnectorClientFactory>();

                        scope.Resolve <Func <IDialog <object> > >(TypedParameter.From(MakeRoot));
                        await Conversation.SendAsync(scope, msg);

                        var reply = scope.Resolve <Queue <IMessageActivity> >().Dequeue();
                        Assert.AreEqual("1:test", reply.Text);
                        var stateClient = connectorFactory.MakeStateClient();
                        var data        = await stateClient.BotState.GetPrivateConversationDataAsync(msg.ChannelId, msg.Conversation.Id, msg.From.Id);

                        Assert.AreEqual(1, data.GetProperty <int>("count"));
                        Assert.AreEqual(0, data.GetProperty <int>("mycount")); // The overwritten data should be 0
                    }
                }
        }
        public static IContainer Build(Options options, params object[] singletons)
        {
            var builder = new ContainerBuilder();

            if (options.HasFlag(Options.ResolveDialogFromContainer))
            {
                builder.RegisterModule(new DialogModule());
            }
            else
            {
                builder.RegisterModule(new DialogModule_MakeRoot());
            }

            // make a "singleton" MockConnectorFactory per unit test execution
            IConnectorClientFactory factory = null;

            builder
            .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve <IAddress>().BotId)))
            .As <IConnectorClientFactory>()
            .InstancePerLifetimeScope();

            if (options.HasFlag(Options.Reflection))
            {
                builder.RegisterModule(new ReflectionSurrogateModule());
            }

            foreach (var singleton in singletons)
            {
                builder
                .Register(c => singleton)
                .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType());
            }

            return(builder.Build());
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventNotificationController"/> class.
 /// </summary>
 /// <param name="eventDataProvider">Event data provider instance</param>
 /// <param name="userManagementHelper">UserManagementHelper instance</param>
 /// <param name="connectorClientFactory">Connector client factory instance</param>
 /// <param name="logProvider">The instance of <see cref="ILogProvider"/></param>
 public EventNotificationController(IEventDataProvider eventDataProvider, IUserManagementHelper userManagementHelper, IConnectorClientFactory connectorClientFactory, ILogProvider logProvider)
 {
     this.eventDataProvider           = eventDataProvider;
     this.userManagementHelper        = userManagementHelper;
     this.connectorClientFactory      = connectorClientFactory;
     this.logProvider                 = logProvider;
     this.teamToEventNotificationsMap = new Dictionary <string, List <EventNotificationData> >();
 }
        public static IContainer Build(Options options, params object[] singletons)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new DialogModule_MakeRoot());

            // make a "singleton" MockConnectorFactory per unit test execution
            IConnectorClientFactory factory = null;

            builder
            .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve <IAddress>().BotId)))
            .As <IConnectorClientFactory>()
            .InstancePerLifetimeScope();

            var r =
                builder
                .Register <Queue <IMessageActivity> >(c => new Queue <IMessageActivity>())
                .AsSelf()
                .InstancePerLifetimeScope();

            // truncate AlwaysSendDirect_BotToUser/IConnectorClient with null implementation
            builder
            .RegisterType <BotToUserQueue>()
            .Keyed <IBotToUser>(typeof(AlwaysSendDirect_BotToUser))
            .InstancePerLifetimeScope();

            if (options.HasFlag(Options.InMemoryBotDataStore))
            {
                //Note: memory store will be single instance for the bot
                builder.RegisterType <InMemoryDataStore>()
                .AsSelf()
                .SingleInstance();

                builder.Register(c => new CachingBotDataStore(c.Resolve <InMemoryDataStore>(),
                                                              CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency))
                .As <IBotDataStore <BotData> >()
                .AsSelf()
                .InstancePerLifetimeScope();
            }

            if (options.HasFlag(Options.NeedsInputHint))
            {
                builder.Register(
                    c => new AlwaysNeedInputHintChannelCapability(new ChannelCapability(c.Resolve <IAddress>())))
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();
            }

            foreach (var singleton in singletons)
            {
                builder
                .Register(c => singleton)
                .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType());
            }

            return(builder.Build());
        }
 public CoordinateLoggerActivityHandler(
     ILogger<CoordinateLoggerActivityHandler> logger, 
     MicrosoftAppCredentials appCredentials, 
     IConnectorClientFactory connectorClientFactory)
 {
     this.logger = logger;
     this.appCredentials = appCredentials;
     this.connectorClientFactory = connectorClientFactory;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PreviewController"/> class.
 /// </summary>
 /// <param name="eventDataProvider">Event data provider instance.</param>
 /// <param name="userManagementHelper">UserManagementHelper instance</param>
 /// <param name="logProvider">Log provider instance</param>
 /// <param name="connectorClientFactory">The connector client factory</param>
 /// <param name="configProvider">Configuration provider instance</param>
 public PreviewController(IEventDataProvider eventDataProvider, IUserManagementHelper userManagementHelper, ILogProvider logProvider, IConnectorClientFactory connectorClientFactory, IConfigProvider configProvider)
 {
     this.eventDataProvider               = eventDataProvider;
     this.userManagementHelper            = userManagementHelper;
     this.logProvider                     = logProvider;
     this.connectorClientFactory          = connectorClientFactory;
     this.timeToPostPreview               = TimeSpan.Parse(configProvider.GetSetting(ApplicationConfig.TimeToPostCelebration), CultureInfo.InvariantCulture);
     this.daysInAdvanceToSendEventPreview = Convert.ToInt32(configProvider.GetSetting(ApplicationConfig.DaysInAdvanceToSendEventPreview));
     this.minimumTimeToProcessEvent       = TimeSpan.FromHours(Convert.ToInt32(configProvider.GetSetting(ApplicationConfig.MinTimeToProcessEventInHours)));
 }
        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="connectorClientFactory">Connector client factory</param>
        /// <returns>Tracking task</returns>
        public async Task <ResourceResponse> SendAsync(IConnectorClientFactory connectorClientFactory)
        {
            if (string.IsNullOrEmpty(this.Activity.ServiceUrl))
            {
                throw new InvalidOperationException("The service URL must be set");
            }

            var client = connectorClientFactory.GetConnectorClient(this.Activity.ServiceUrl);

            try
            {
                var response = await this.SendAsyncWorker(client.Conversations);

                this.MessageSendResult = new MessageSendResult()
                {
                    LastAttemptTime = DateTime.UtcNow,
                    StatusCode      = (int)HttpStatusCode.OK,
                    ResponseBody    = string.Empty,
                };
                return(response);
            }
            catch (HttpException httpException)
            {
                this.MessageSendResult = new MessageSendResult()
                {
                    LastAttemptTime = DateTime.UtcNow,
                    StatusCode      = httpException.GetHttpCode(),
                    ResponseBody    = httpException.GetHtmlErrorMessage(),
                };
                throw;
            }
            catch (ErrorResponseException errorResponseException)
            {
                this.MessageSendResult = new MessageSendResult()
                {
                    LastAttemptTime = DateTime.UtcNow,
                    StatusCode      = (int)errorResponseException.Response.StatusCode,
                    ResponseBody    = errorResponseException.Response.Content,
                };
                throw;
            }
            catch (Exception ex)
            {
                this.MessageSendResult = new MessageSendResult()
                {
                    LastAttemptTime = DateTime.UtcNow,
                    StatusCode      = -1,
                    ResponseBody    = ex.ToString(),
                };
                throw;
            }
        }
Beispiel #8
0
        public async Task EnforceETagConsistency()
        {
            Func <IDialog <object> > MakeRoot = () => chain;

            using (new FiberTestBase.ResolveMoqAssembly(chain))
                using (var container = Build(Options.MockConnectorFactory, chain))
                {
                    var msg = DialogTestBase.MakeTestMessage();
                    msg.Text = "test";
                    using (var scope = DialogModule.BeginLifetimeScope(container, msg))
                    {
                        connectorFactory = scope.Resolve <IConnectorClientFactory>();

                        scope.Resolve <Func <IDialog <object> > >(TypedParameter.From(MakeRoot));
                        try
                        {
                            await Conversation.SendAsync(scope, msg);

                            Assert.Fail();
                        }
                        catch (HttpOperationException e)
                        {
                            Assert.AreEqual(e.Response.StatusCode, HttpStatusCode.PreconditionFailed);
                            var connectorFactory = scope.Resolve <IConnectorClientFactory>();
                            var stateClient      = connectorFactory.MakeStateClient();
                            var data             = await stateClient.BotState.GetPrivateConversationDataAsync(msg.ChannelId, msg.Conversation.Id, msg.From.Id);

                            Assert.AreEqual(10, data.GetProperty <int>("mycount"));
                        }
                        catch (Exception)
                        {
                            Assert.Fail();
                        }
                    }
                }
        }
        public static IContainer Build(Options options, params object[] singletons)
        {
            var builder = new ContainerBuilder();
            if (options.HasFlag(Options.ResolveDialogFromContainer))
            {
                builder.RegisterModule(new DialogModule());
            }
            else
            {
                builder.RegisterModule(new DialogModule_MakeRoot());
            }

            // make a "singleton" MockConnectorFactory per unit test execution
            IConnectorClientFactory factory = null;
            builder
                .Register((c, p) => factory ?? (factory = new MockConnectorFactory(c.Resolve<IAddress>().BotId)))
                .As<IConnectorClientFactory>()
                .InstancePerLifetimeScope();

            if (options.HasFlag(Options.Reflection))
            {
                builder.RegisterModule(new ReflectionSurrogateModule());
            }

            var r =
                builder
                .Register<Queue<IMessageActivity>>(c => new Queue<IMessageActivity>())
                .AsSelf();

            if (options.HasFlag(Options.ScopedQueue))
            {
                r.InstancePerLifetimeScope();
            }
            else
            {
                r.SingleInstance();
            }

            builder
                .RegisterType<BotToUserQueue>()
                .AsSelf()
                .InstancePerLifetimeScope();

            builder
                .Register(c => new MapToChannelData_BotToUser(
                    c.Resolve<BotToUserQueue>(),
                    new List<IMessageActivityMapper> { new KeyboardCardMapper() }))
                .As<IBotToUser>()
                .InstancePerLifetimeScope();

            if (options.HasFlag(Options.LastWriteWinsCachingBotDataStore))
            {
                builder.Register<CachingBotDataStore>(c => new CachingBotDataStore(c.ResolveKeyed<IBotDataStore<BotData>>(typeof(ConnectorStore)), CachingBotDataStoreConsistencyPolicy.LastWriteWins))
                    .As<IBotDataStore<BotData>>()
                    .AsSelf()
                    .InstancePerLifetimeScope();
            }

            foreach (var singleton in singletons)
            {
                builder
                    .Register(c => singleton)
                    .Keyed(FiberModule.Key_DoNotSerialize, singleton.GetType());
            }

            return builder.Build();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageDeliveryController"/> class.
 /// </summary>
 /// <param name="eventDataProvider">Event data provider instance</param>
 /// <param name="logProvider">The instance of <see cref="ILogProvider"/></param>
 /// <param name="connectorClientFactory">Connector client factory</param>
 public MessageDeliveryController(IEventDataProvider eventDataProvider, ILogProvider logProvider, IConnectorClientFactory connectorClientFactory)
 {
     this.eventDataProvider      = eventDataProvider;
     this.logProvider            = logProvider;
     this.connectorClientFactory = connectorClientFactory;
 }