示例#1
0
        public async Task ShouldCheckCurrentCity()
        {
            IDialog <object> stateDialog = new StateDialog();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = "hi";
            Func <IDialog <object> > MakeRoot = () => stateDialog;

            using (new FiberTestBase.ResolveMoqAssembly(stateDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, stateDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(toUser.Text.Equals("Welcome to the Search City bot. I'm currently configured to search for things in Seattle"));

                    toBot.Text = "Thiago";
                    toUser     = await GetResponse(container, MakeRoot, toBot);

                    Assert.IsTrue(toUser.Text.StartsWith("Welcome Thiago!"));

                    toBot.Text = "current city";
                    toUser     = await GetResponse(container, MakeRoot, toBot);

                    Assert.IsTrue(toUser.Text.Equals("Hey Thiago, I'm currently configured to search for things in Seattle."));
                }
        }
示例#2
0
        public async Task ShouldReturnNoAppointmentToday()
        {
            Initialize();
            // Replace Dialog class to your own class
            IDialog <object> rootDialog = new RootDialog();
            var d365Mock = new Mock <ID365Service>();

            d365Mock.Setup(m => m.GetAppointmentsForToday()).Returns(Task.FromResult(new List <Appointment>()));

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(d365Mock.Object).As <ID365Service>();
            WebApiApplication.Container = builder.Build();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = Resource.Menu_Appointment_For_Today;
            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(toUser.Text.Equals(Resource.No_Appointment_Today));
                }
        }
示例#3
0
        private IMessageActivity GetResponse(IContainer container, Func <IDialog <object> > makeRoot)
        {
            using (var scope = DialogModule.BeginLifetimeScope(container, DialogTestBase.MakeTestMessage()))
            {
                DialogModule_MakeRoot.Register(scope, makeRoot);

                return(scope.Resolve <Queue <IMessageActivity> >().Dequeue());
            }
        }
        public async Task ShouldReturnEvents()
        {
            // Instantiate ShimsContext to use Fakes
            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };

                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.GetEvents()).ReturnsAsync(new List <Event>()
                {
                    new Event
                    {
                        Subject = "dummy event",
                        Start   = new DateTimeTimeZone()
                        {
                            DateTime = "2017-05-31 12:00",
                            TimeZone = "Standard Tokyo Time"
                        },
                        End = new DateTimeTimeZone()
                        {
                            DateTime = "2017-05-31 13:00",
                            TimeZone = "Standard Tokyo Time"
                        }
                    }
                });
                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                WebApiApplication.Container = builder.Build();

                // Instantiate dialog to test
                IDialog <object> rootDialog = new RootDialog();

                // Create in-memory bot environment
                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                    using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                    {
                        // Register global message handler
                        RegisterBotModules(container);

                        // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "get events";

                        // Send message and check the answer.
                        IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser.Text.Equals("2017-05-31 12:00-2017-05-31 13:00: dummy event"));
                    }
            }
        }
示例#5
0
        public async Task ShouldReturnProducts()
        {
            Initialize();
            // Replace Dialog class to your own class
            IDialog <object> rootDialog = new RootDialog();
            var d365Mock = new Mock <ID365Service>();

            d365Mock.Setup(m => m.GetProducts("dummy query")).Returns(
                Task.FromResult(
                    new List <Product>()
            {
                new Product()
                {
                    Name        = "Dummy Product",
                    Description = "Dummy Desc"
                }
            }));

            var azureBlobMock = new Mock <IAzureBlobService>();

            azureBlobMock.Setup(m => m.Upload("", "")).Returns("");

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(d365Mock.Object).As <ID365Service>();
            builder.RegisterInstance(azureBlobMock.Object).As <IAzureBlobService>();
            WebApiApplication.Container = builder.Build();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = Resource.Menu_SearchProduct;
            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    Assert.IsTrue(toUser.Text.Equals(Resource.Enter_ProductName));

                    toBot.Text = "dummy query";

                    toUser = await GetResponse(container, MakeRoot, toBot);

                    ThumbnailCard card = (ThumbnailCard)toUser.Attachments.First().Content;
                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(card.Title.Equals("Dummy Product"));
                    Assert.IsTrue(card.Buttons.First().Title.Equals(Resource.Detail));
                }
        }
示例#6
0
        private async Task EchoDialogFlow(IDialog <object> echoDialog)
        {
            // arrange
            var toBot = DialogTestBase.MakeTestMessage();

            toBot.Text = "Test";

            Func <IDialog <object> > MakeRoot = () => echoDialog;

            // act: sending the message
            var toUser = await Conversation.SendAsync(toBot, MakeRoot);

            // assert: check if the dialog returned the right response
            Assert.IsTrue(toUser.Text.StartsWith("1"));
            Assert.IsTrue(toUser.Text.Contains("Test"));

            // act: send the message 10 times
            for (int i = 0; i < 10; i++)
            {
                // pretend we're the intercom switch, and copy the bot data from message to message
                toBot = toUser;

                // post the message
                toUser = await Conversation.SendAsync(toBot, MakeRoot);
            }

            // assert: check the counter at the end
            Assert.IsTrue(toUser.Text.StartsWith("11"));

            // act: send the reset
            toBot      = toUser;
            toBot.Text = "reset";
            toUser     = await Conversation.SendAsync(toBot, MakeRoot);

            // assert: verify confirmation
            Assert.IsTrue(toUser.Text.ToLower().Contains("are you sure"));

            //send yes as reply
            toBot      = toUser;
            toBot.Text = "yes";
            toUser     = await Conversation.SendAsync(toBot, MakeRoot);

            Assert.IsTrue(toUser.Text.ToLower().Contains("reset count"));

            //send a random message and check count
            toBot      = toUser;
            toBot.Text = "test";
            toUser     = await Conversation.SendAsync(toBot, MakeRoot);

            Assert.IsTrue(toUser.Text.StartsWith("1"));
        }
示例#7
0
        public async Task ShouldBeAbleToReset()
        {
            Initialize();
            // Replace Dialog class to your own class
            IDialog <object> rootDialog = new SystemAlertDialog("dummy title", "dummy desc", "dummy id", "dummy id");
            var d365Mock = new Mock <ID365Service>();

            d365Mock.Setup(m => m.CreateIoTCommand("dummy operetion", "dummy id", "dummy id")).Returns(
                Task.CompletedTask);

            var imageMock = new Mock <IImageService>();

            imageMock.Setup(m => m.GetImageUri("dummy")).Returns("");

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(d365Mock.Object).As <ID365Service>();
            builder.RegisterInstance(imageMock.Object).As <IImageService>();
            WebApiApplication.Container = builder.Build();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = "Reset";

            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    List <IMessageActivity> toUser = await GetResponses(container, MakeRoot, toBot);

                    // act: sending the message
                    // assert: check if menu (list) is back
                    Assert.IsTrue(toUser[0].AttachmentLayout.Equals("carousel"));

                    Assert.IsTrue(toUser[1].Text.Equals(string.Format(Resource.Done_Operation, "Reset")));
                }
        }
示例#8
0
        public async Task ShouldBeAbleToAddDailyReport()
        {
            Initialize();
            // Replace Dialog class to your own class
            IDialog <object> rootDialog = new RootDialog();
            var d365Mock = new Mock <ID365Service>();

            d365Mock.Setup(m => m.CreateDailyReport("dummy")).Returns(
                Task.CompletedTask);

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(d365Mock.Object).As <ID365Service>();
            WebApiApplication.Container = builder.Build();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = Resource.Menu_Daily_Report;

            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if menu (list) is back
                    Assert.IsTrue(toUser.Text.Equals(Resource.Ask_DailyReport));

                    toBot.Text = "dummy report";

                    toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(toUser.Text.Equals(Resource.Created_DailyReport));
                }
        }
        public async Task ShouldReturnCount()
        {
            // Instantiate dialog to test
            IDialog <object> rootDialog = new RootDialog();

            // Create in-memory bot environment
            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    // Create a message to send to bot
                    var toBot = DialogTestBase.MakeTestMessage();
                    toBot.From.Id = Guid.NewGuid().ToString();
                    toBot.Text    = "hi!";

                    // Send message and check the answer.
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // Verify the result
                    Assert.IsTrue(toUser.Text.Equals("You sent hi! which was 3 characters"));
                }
        }
示例#10
0
        public async Task ShouldReturnNewAppointmentCard()
        {
            Initialize();
            // Replace Dialog class to your own class
            IDialog <object> rootDialog = new RootDialog();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = Resource.Menu_Create_Appointment;
            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    ThumbnailCard card = (ThumbnailCard)toUser.Attachments.First().Content;
                    Assert.IsTrue(card.Text.Equals(Resource.Create_Appointment));
                    Assert.IsTrue(card.Title.Equals(Resource.Open_In_Browser));
                }
        }
示例#11
0
        public async Task ShouldCreateEvent()
        {
            // Instantiate ShimsContext to use Fakes
            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };


                // Mock the LUIS service
                var luis1 = new Mock <ILuisService>();
                // Mock other services
                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.CreateEvent(It.IsAny <Event>())).Returns(Task.FromResult(true));
                var subscriptionId          = Guid.NewGuid().ToString();
                var mockNotificationService = new Mock <INotificationService>();
                mockNotificationService.Setup(x => x.SubscribeEventChange()).ReturnsAsync(subscriptionId);
                mockNotificationService.Setup(x => x.RenewSubscribeEventChange(It.IsAny <string>())).Returns(Task.FromResult(true));

                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                builder.RegisterInstance(mockNotificationService.Object).As <INotificationService>();
                WebApiApplication.Container = builder.Build();

                /// Instantiate dialog to test
                LuisRootDialog rootDialog = new LuisRootDialog();

                // Create in-memory bot environment
                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(luis1.Object))
                    using (var container = Build(Options.ResolveDialogFromContainer, luis1.Object))
                    {
                        var dialogBuilder = new ContainerBuilder();
                        dialogBuilder
                        .RegisterInstance(rootDialog)
                        .As <IDialog <object> >();
                        dialogBuilder.Update(container);

                        // Register global message handler
                        RegisterBotModules(container);

                        // create datetimeV2 resolution
                        Dictionary <string, object> resolution = new Dictionary <string, object>();
                        JArray values = new JArray();
                        Dictionary <string, object> resolutionData = new Dictionary <string, object>();
                        resolutionData.Add("type", "datetime");
                        resolutionData.Add("value", DateTime.Now.AddDays(1));
                        values.Add(JToken.FromObject(resolutionData));
                        resolution.Add("values", values);

                        // Specify "Calendar.Find" intent as LUIS result
                        SetupLuis <LuisRootDialog>(luis1, d => d.GetEvents(null, null, null), 1.0,
                                                   new EntityRecommendation(type: "Calendar.Subject", entity: "dummy subject"),
                                                   new EntityRecommendation(type: "builtin.datetimeV2.datetime", resolution: resolution));

                        // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "eat dinner with my wife at outback stakehouse at shinagawa at 7 pm next Wednesday";

                        // Send message and check the answer.
                        var toUser = await GetResponses(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser[0].Text.Equals("Creating an event."));
                        Assert.IsTrue((toUser[1].Attachments[0].Content as HeroCard).Text.Equals("Is this all day event?"));

                        toBot.Text = "No";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("How many hours?"));

                        toBot.Text = "3";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("The event is created."));
                    }
            }
        }
示例#12
0
        public async Task ShouldCreateAllDayEvent()
        {
            // Instantiate ShimsContext to use Fakes
            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };

                // Mock the service and register
                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.CreateEvent(It.IsAny <Event>())).Returns(Task.FromResult(true));

                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                WebApiApplication.Container = builder.Build();

                // Instantiate dialog to test
                IDialog <object> rootDialog = new RootDialog();

                // Create in-memory bot environment
                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                    using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                    {
                        // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        // Specify local as US English
                        toBot.Locale  = "en-US";
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "add appointment";

                        // Send message and check the answer.
                        var toUser = await GetResponses(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser[0].Text.Equals("Creating an event."));
                        Assert.IsTrue(toUser[1].Text.Equals("What is the title?"));

                        toBot.Text = "Learn BotFramework";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("What is the detail?"));

                        toBot.Text = "Implement O365Bot";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("When do you start? Use dd/MM/yyyy HH:mm format."));

                        toBot.Text = "01/07/2017 13:00";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue((toUser[0].Attachments[0].Content as HeroCard).Text.Equals("Is this all day event?"));

                        toBot.Text = "Yes";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("The event is created."));
                    }
            }
        }
示例#13
0
        private async Task EchoDialogFlow(IDialog <object> echoDialog)
        {
            // arrange
            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = "Test";

            Func <IDialog <object> > MakeRoot = () => echoDialog;

            using (new FiberTestBase.ResolveMoqAssembly(echoDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, echoDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(toUser.Text.StartsWith("1"));
                    Assert.IsTrue(toUser.Text.Contains("Test"));

                    // act: send the message 10 times
                    for (int i = 0; i < 10; i++)
                    {
                        // pretend we're the intercom switch, and copy the bot data from message to message
                        toBot.Text = toUser.Text;
                        toUser     = await GetResponse(container, MakeRoot, toBot);
                    }

                    // assert: check the counter at the end
                    Assert.IsTrue(toUser.Text.StartsWith("11"));

                    toBot.Text = "reset";
                    toUser     = await GetResponse(container, MakeRoot, toBot);

                    // checking if there is any cards in the attachment and promote the card.text to message.text
                    if (toUser.Attachments != null && toUser.Attachments.Count > 0)
                    {
                        var card = (HeroCard)toUser.Attachments.First().Content;
                        toUser.Text = card.Text;
                    }
                    Assert.IsTrue(toUser.Text.ToLower().Contains("are you sure"));

                    toBot.Text = "yes";
                    toUser     = await GetResponse(container, MakeRoot, toBot);

                    Assert.IsTrue(toUser.Text.ToLower().Contains("reset count"));

                    //send a random message and check count
                    toBot.Text = "test";
                    toUser     = await GetResponse(container, MakeRoot, toBot);

                    Assert.IsTrue(toUser.Text.StartsWith("1"));

                    toBot.Text = "/deleteprofile";
                    toUser     = await GetResponse(container, MakeRoot, toBot);

                    Assert.IsTrue(toUser.Text.ToLower().Contains("deleted"));
                    using (var scope = DialogModule.BeginLifetimeScope(container, toBot))
                    {
                        var botData = scope.Resolve <IBotData>();
                        await botData.LoadAsync(default(CancellationToken));

                        var stack = scope.Resolve <IDialogStack>();
                        Assert.AreEqual(0, stack.Frames.Count);
                    }
                }
        }
        public async Task ShouldCancelCurrrentDialog()
        {
                        // Instantiate ShimsContext to use Fakes
                            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };

                // Mock the service and register
                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.CreateEvent(It.IsAny <Event>())).Returns(Task.FromResult(true));

                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                WebApiApplication.Container = builder.Build();

                // Instantiate dialog to test
                IDialog <object> rootDialog = new RootDialog();

                                // Create in-memory bot environment
                                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                    using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                    {
                                            // Register global message handler
                                            RegisterBotModules(container);

                                           
                        // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        // Specify local as US English
                        toBot.Locale  = "en-US";
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "add appointment";

                        // Send message and check the answer.
                        var toUser = await GetResponses(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser[0].Text.Equals("Creating an event."));
                        Assert.IsTrue(toUser[1].Text.Equals("What is the title?"));

                        toBot.Text = "Learn BotFramework";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("What is the detail?"));

                        toBot.Text = "Cancel";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser.Count.Equals(0));

                        toBot.Text = "add appointment";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser[0].Text.Equals("Creating an event."));
                        Assert.IsTrue(toUser[1].Text.Equals("What is the title?"));
                    }
            }
        }
        public async Task ShouldInterruptCurrentDialog()
        {
            // Instantiate ShimsContext to use Fakes
            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };

                // Mock the service and register
                                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.CreateEvent(It.IsAny <Event>())).Returns(Task.FromResult(true));
                mockEventService.Setup(x => x.GetEvents()).ReturnsAsync(new List <Event>()
                {
                    new Event
                    {
                        Subject = "dummy event",
                        Start   = new DateTimeTimeZone()
                        {
                            DateTime = "2017-05-31 12:00",
                            TimeZone = "Standard Tokyo Time"
                        },
                        End = new DateTimeTimeZone()
                        {
                            DateTime = "2017-05-31 13:00",
                            TimeZone = "Standard Tokyo Time"
                        }
                    }
                });
                var mockNotificationService = new Mock <INotificationService>();
                mockNotificationService.Setup(x => x.SubscribeEventChange()).ReturnsAsync(Guid.NewGuid().ToString());
                mockNotificationService.Setup(x => x.RenewSubscribeEventChange(It.IsAny <string>())).Returns(Task.FromResult(true));

                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                builder.RegisterInstance(mockNotificationService.Object).As <INotificationService>();
                WebApiApplication.Container = builder.Build();

                // Instantiate dialog to test
                IDialog <object> rootDialog = new RootDialog();

                                // Create in-memory bot environment
                                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                    using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                    {
                                            // Register global message handler
                                            RegisterBotModules(container);

                                            // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        // Specify local as US English
                        toBot.Locale  = "en-US";
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "add appointment";

                        // Send message and check the answer.
                        var toUser = await GetResponses(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser[0].Text.Equals("Creating an event."));
                        Assert.IsTrue(toUser[1].Text.Equals("What is the title?"));

                        toBot.Text = "Learn BotFramework";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("What is the detail?"));

                        toBot.Text = "Get Events";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("2017-05-31 12:00-2017-05-31 13:00: dummy event"));

                        toBot.Text = "Glbal Message Handler for O365Bot";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("When do you start? Use dd/MM/yyyy HH:mm format."));
                    }
            }
        }
        public async Task ShouldReceiveNotifyEventChageDialog()
        {
            // Instantiate ShimsContext to use Fakes
            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };

                // Mock the service and register
                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.CreateEvent(It.IsAny <Event>())).Returns(Task.FromResult(true));
                mockEventService.Setup(x => x.GetEvent(It.IsAny <string>())).ReturnsAsync(new Event()
                {
                    Subject = "dummy event",
                    Start   = new DateTimeTimeZone()
                    {
                        DateTime = "2017-05-31 12:00",
                        TimeZone = "Standard Tokyo Time"
                    },
                    End = new DateTimeTimeZone()
                    {
                        DateTime = "2017-05-31 13:00",
                        TimeZone = "Standard Tokyo Time"
                    },
                    Body = new ItemBody()
                    {
                        Content = "Dummy Body"
                    },
                    Location = new Location()
                    {
                        DisplayName = "Dummy Location"
                    }
                });

                var subscriptionId          = Guid.NewGuid().ToString();
                var mockNotificationService = new Mock <INotificationService>();
                mockNotificationService.Setup(x => x.SubscribeEventChange()).ReturnsAsync(subscriptionId);
                mockNotificationService.Setup(x => x.RenewSubscribeEventChange(It.IsAny <string>())).Returns(Task.FromResult(true));

                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                builder.RegisterInstance(mockNotificationService.Object).As <INotificationService>();
                WebApiApplication.Container = builder.Build();

                // Instantiate dialog to test
                IDialog <object> rootDialog = new RootDialog();

                                // Create in-memory bot environment
                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                    using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                    {
                        // Register global message handler
                        RegisterBotModules(container);

                        // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        // Specify local as US English
                        toBot.Locale  = "en-US";
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "add appointment";

                        // Send message and check the answer.
                        var toUser = await GetResponses(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser[0].Text.Equals("Creating an event."));
                        Assert.IsTrue(toUser[1].Text.Equals("What is the title?"));

                        toBot.Text = "Learn BotFramework";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("What is the detail?"));

                        // Send Proactive Message
                        // Use current subscriptionid to get ConversationReference。
                        var conversationReference = CacheService.caches[subscriptionId] as ConversationReference;
                        // Get an Event Id
                        var id = Guid.NewGuid().ToString();

                        // Get local and set it
                        var activity = conversationReference.GetPostToBotMessage();
                        var locale   = CacheService.caches[activity.From.Id].ToString();
                        Thread.CurrentThread.CurrentCulture   = new CultureInfo(locale);
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale);
                        toUser = await Resume(container, new NotifyEventChageDialog(id), activity);

                        Assert.IsTrue((toUser[0].Attachments[0].Content as HeroCard).Text.Equals("One of your events has been updated."));

                        toBot.Text = "Check the detail";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("Check the detail"));
                        Assert.IsTrue(toUser[1].Text.Equals("2017-05-31 12:00-2017-05-31 13:00: dummy event@Dummy Location-Dummy Body"));

                        toBot.Text = "Implement O365Bot";
                        toUser     = await GetResponses(container, MakeRoot, toBot);

                        Assert.IsTrue(toUser[0].Text.Equals("When do you start? Use dd/MM/yyyy HH:mm format."));
                    }
            }
        }
示例#17
0
        public async Task ShouldReturnEvents()
        {
            // Instantiate ShimsContext to use Fakes
            using (ShimsContext.Create())
            {
                // Return "dummyToken" when calling GetAccessToken method
                AuthBot.Fakes.ShimContextExtensions.GetAccessTokenIBotContextString =
                    async(a, e) => { return("dummyToken"); };


                // Mock the LUIS service
                var luis1 = new Mock <ILuisService>();
                // Mock other services
                var mockEventService = new Mock <IEventService>();
                mockEventService.Setup(x => x.GetEvents()).ReturnsAsync(new List <Event>()
                {
                    new Event
                    {
                        Subject = "dummy event",
                        Start   = new DateTimeTimeZone()
                        {
                            DateTime = "2017-05-31 12:00",
                            TimeZone = "Standard Tokyo Time"
                        },
                        End = new DateTimeTimeZone()
                        {
                            DateTime = "2017-05-31 13:00",
                            TimeZone = "Standard Tokyo Time"
                        }
                    }
                });
                var subscriptionId          = Guid.NewGuid().ToString();
                var mockNotificationService = new Mock <INotificationService>();
                mockNotificationService.Setup(x => x.SubscribeEventChange()).ReturnsAsync(subscriptionId);
                mockNotificationService.Setup(x => x.RenewSubscribeEventChange(It.IsAny <string>())).Returns(Task.FromResult(true));

                var builder = new ContainerBuilder();
                builder.RegisterInstance(mockEventService.Object).As <IEventService>();
                builder.RegisterInstance(mockNotificationService.Object).As <INotificationService>();
                WebApiApplication.Container = builder.Build();

                /// Instantiate dialog to test
                LuisRootDialog rootDialog = new LuisRootDialog();

                // Create in-memory bot environment
                Func <IDialog <object> > MakeRoot = () => rootDialog;
                using (new FiberTestBase.ResolveMoqAssembly(luis1.Object))
                    using (var container = Build(Options.ResolveDialogFromContainer, luis1.Object))
                    {
                        var dialogBuilder = new ContainerBuilder();
                        dialogBuilder
                        .RegisterInstance(rootDialog)
                        .As <IDialog <object> >();
                        dialogBuilder.Update(container);

                        // Register global message handler
                        RegisterBotModules(container);

                        // Specify "Calendar.Find" intent as LUIS result
                        SetupLuis <LuisRootDialog>(luis1, d => d.GetEvents(null, null, null), 1.0, new EntityRecommendation(type: "Calendar.Find"));

                        // Create a message to send to bot
                        var toBot = DialogTestBase.MakeTestMessage();
                        toBot.From.Id = Guid.NewGuid().ToString();
                        toBot.Text    = "get events";

                        // Send message and check the answer.
                        IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                        // Verify the result
                        Assert.IsTrue(toUser.Text.Equals("2017-05-31 12:00-2017-05-31 13:00: dummy event"));
                    }
            }
        }
示例#18
0
        public async Task ShouldReturnNextTask()
        {
            Initialize();
            // Replace Dialog class to your own class
            IDialog <object> rootDialog = new RootDialog();
            var d365Mock = new Mock <ID365Service>();

            d365Mock.Setup(m => m.GetTasks()).Returns(
                Task.FromResult(
                    new List <CrmTask>()
            {
                new CrmTask()
                {
                    Title       = "Dummy Task",
                    Description = "Dummy Desc",
                    DueDateTime = DateTime.Parse("2017/01/01 12:00:00"),
                    Type        = "D365"
                },
                new CrmTask()
                {
                    Title       = "Dummy Task 2",
                    Description = "Dummy Desc 2",
                    DueDateTime = DateTime.Parse("2017/01/01 15:00:00"),
                    Type        = "D365"
                }
            }));

            var o365Mock = new Mock <IO365Service>();

            o365Mock.Setup(m => m.GetTasks()).Returns(
                Task.FromResult(
                    new List <PlannerTask>()
            {
                new PlannerTask()
                {
                    Title       = "Dummy Task 3",
                    Description = "Dummy Desc",
                    DueDateTime = DateTime.Parse("2017/01/01 13:00:00"),
                    Type        = "O365"
                },
                new PlannerTask()
                {
                    Title       = "Dummy Task 4",
                    Description = "Dummy Desc 2",
                    DueDateTime = DateTime.Parse("2017/01/01 14:00:00"),
                    Type        = "O365"
                }
            }));

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(d365Mock.Object).As <ID365Service>();
            builder.RegisterInstance(o365Mock.Object).As <IO365Service>();
            WebApiApplication.Container = builder.Build();

            var toBot = DialogTestBase.MakeTestMessage();

            toBot.From.Id = Guid.NewGuid().ToString();
            toBot.Text    = Resource.Menu_Task_Menu;
            Func <IDialog <object> > MakeRoot = () => rootDialog;

            using (new FiberTestBase.ResolveMoqAssembly(rootDialog))
                using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog))
                {
                    // act: sending the message
                    IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if menu (list) is back
                    Assert.IsTrue(toUser.AttachmentLayout.Equals("list"));

                    toBot.Text = Resource.Get_NextTask;

                    toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(toUser.Text.Equals("01/01 12:00 Dummy Task-Dummy Desc"));

                    toBot.Text = Resource.Get_NextTask;

                    toUser = await GetResponse(container, MakeRoot, toBot);

                    // assert: check if the dialog returned the right response
                    Assert.IsTrue(toUser.Text.Equals("01/01 13:00 Dummy Task 3-Dummy Desc"));
                }
        }