Exemplo n.º 1
0
        public async Task TestGetLengthWork()
        {
            int userId = 1;
            var start  = (int)DateTime.Now.AddHours(2).ToUnixTime();
            var end    = (int)DateTime.Now.AddHours(4).ToUnixTime();
            var note   = $"Test visit";

            var visits = Enumerable.Range(0, 1).Select(x => new Visit()
            {
                StartAt     = start,
                EndAt       = end,
                Description = note,
                AssignedTo  = new List <Assigned>()
                {
                    new Assigned()
                    {
                        Id = userId
                    }
                },
                Title = "Test visit"
            }).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsVisitsAssignedForToday(visits, userId)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.GetLengthWorkday)
                                     .Build();

            fulfillmentRequest.UserId = userId;
            var fulfiller = new GetLengthWorkdayIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            Assert.IsTrue(response.Speech.Contains("Your work is"));
        }
        public async Task TestIfMultipleClientsMatch()
        {
            var johnSmith = new Client {
                Name = "John Smith"
            };
            var johnAppleseed = new Client {
                Name = "John Appleseed"
            };

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .SearchReturnsClients("John", new List <Client> {
                johnSmith, johnAppleseed
            })
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.ClientRequestedCreateJob)
                                     .WithParameter(Constants.Variables.ClientName, "John")
                                     .Build();

            var fulfiller = new ClientRequestedCreateJobIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response
            .AssertResponseSpeech("There a few people who have a smiliar name to John, can you be a bit more specific?")
            .AssertContainsOutgoingContext(Constants.Contexts.CreateJobClientRequested)
            .AssertOutgoingContextHasLifespanOf(Constants.Contexts.CreateJobClientRequested, 1);
        }
Exemplo n.º 3
0
        public async Task TestNoUnassignedVisits()
        {
            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsVisitsForToday(new List <Visit>())
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.UnassignedVisits)
                                     .Build();

            var fulfiller = new UnassignedVisitsIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("There are no visits left to be assigned today!");
        }
        public async Task TestNoSendableInvoices()
        {
            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsDraftInvoices(new List <Invoice>())
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.SendableInvoices)
                                     .Build();

            var fulfiller = new SendableInvoicesIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("Looks like you have no invoices that need to be sent!");
        }
        public async Task TestIfNoClientMatches()
        {
            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .SearchReturnsClients("John", new List <Client>())
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.ClientRequestedCreateJob)
                                     .WithParameter(Constants.Variables.ClientName, "John")
                                     .Build();

            var fulfiller = new ClientRequestedCreateJobIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("Sorry I don't know who John is.");
        }
        public async Task TestMultipleSendableInvoices()
        {
            var Invoices = Enumerable.Range(0, 2).Select(x => new Invoice()).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsDraftInvoices(Invoices)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.SendableInvoices)
                                     .Build();

            var fulfiller = new SendableInvoicesIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("There are 2 invoices ready to be sent.");
        }
Exemplo n.º 7
0
        public async Task TestNextNoVisit()
        {
            int userId           = 1;
            var visits           = Enumerable.Empty <Visit>().ToList();
            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsVisitsAssignedForToday(visits, userId)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.GetNextVisit)
                                     .Build();

            fulfillmentRequest.UserId = userId;
            var fulfiller = new GetNextVisitIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            Assert.IsTrue(response.Speech.Contains($"Your remaining day looks clear"));
        }
Exemplo n.º 8
0
        public async Task TestGetLengthNoWork()
        {
            long userId = 1;
            var  visits = Enumerable.Empty <Visit>();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsVisitsAssignedForToday(visits, userId)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.GetLengthWorkday)
                                     .Build();

            fulfillmentRequest.UserId = userId;
            var fulfiller = new GetLengthWorkdayIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech($"You have no work today.");
        }
Exemplo n.º 9
0
        public async Task TestAmountVisitsNoWork()
        {
            long userId = 1;
            var  visits = Enumerable.Empty <Visit>();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsVisitsAssignedForToday(visits, userId)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.GetAmountVisits)
                                     .Build();

            fulfillmentRequest.UserId = userId;
            var fulfiller = new GetAmountVisitsIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            Assert.IsTrue(response.Speech.Contains($"Your day looks clear today"));
        }
        public async Task TestDefaultTimeUnitRevenue()
        {
            var Transactions = Enumerable.Range(0, 1).Select(x => new Transaction()
            {
                Amount = "100.00", Type = "Invoice"
            }).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsRangedTransactions(Transactions)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.GetRevenue)
                                     .Build();

            var fulfiller = new GetRevenueIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("We made $100.00 last week");
        }
Exemplo n.º 11
0
        public async Task TestMultipleUnassignedVisits()
        {
            var Visits = Enumerable.Range(0, 2).Select(x => new Visit()
            {
                AssignedTo = new List <Assigned>()
            }).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsVisitsForToday(Visits)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.UnassignedVisits)
                                     .Build();

            var fulfiller = new UnassignedVisitsIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("You have 2 unassigned visits for today.");
        }
Exemplo n.º 12
0
        public async Task TestMultipleConvertibleQuotes()
        {
            var Quotes = Enumerable.Range(0, 2).Select(x => new Quote()
            {
                ApprovedAt = 1
            }).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsQuotesAsync(Quotes)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.ConvertibleQuotes)
                                     .Build();

            var fulfiller = new ConvertibleQuoteIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("There are 2 quotes ready to be converted into jobs.");
        }
        public async Task TestTimeUnitRevenue()
        {
            var Transactions = Enumerable.Range(0, 2).Select(x => new Transaction()
            {
                Amount = "100.25", Type = "Invoice"
            }).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsRangedTransactions(Transactions)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.GetRevenue)
                                     .WithParameter(Constants.Variables.TimeUnitOriginal, "in last March")
                                     .Build();

            var fulfiller = new GetRevenueIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("We made $200.50 in last March");
        }
        public async Task TestIfOneClientMatches()
        {
            var john = new Client
            {
                Name         = "John Smith",
                MyProperties = new List <Property>
                {
                    new Property
                    {
                        MapAddress = "Rogers Place, Edmonton"
                    }
                }
            };

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .SearchReturnsClients("John", new List <Client> {
                john
            })
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.ClientRequestedCreateJob)
                                     .WithParameter(Constants.Variables.ClientName, "John")
                                     .Build();

            var fulfiller = new ClientRequestedCreateJobIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response
            .AssertResponseSpeech("Okay! What are you going to do for John Smith?")
            .AssertContainsOutgoingContext(Constants.Contexts.CreateJobClientSet)
            .AssertOutgoingContextHasLifespanOf(Constants.Contexts.CreateJobClientSet, 1)
            .AssertOutgoingContextHasParameter(Constants.Contexts.CreateJobClientSet, Constants.Variables.CreateJobContext);

            var createJobContext = response.GetContextParameterAs <CreateJobContext>(
                Constants.Contexts.CreateJobClientSet, Constants.Variables.CreateJobContext);

            Assert.AreEqual("John Smith", createJobContext.Client.Name);
            Assert.AreEqual("Rogers Place, Edmonton", createJobContext.Property.MapAddress);
        }
Exemplo n.º 15
0
        public async Task TestSingleConvertibleQuotes()
        {
            var Quotes = Enumerable.Range(0, 1).Select(x => new Quote()
            {
                ApprovedAt = 1, Client = new Client()
                {
                    Name = "John Doe"
                }
            }).ToList();

            var mockJobberClient = MockJobberClientBuilder.Create()
                                   .ReturnsQuotesAsync(Quotes)
                                   .Build();

            var fulfillmentRequest = FulfillmentRequestBuilder.Create(Constants.Intents.ConvertibleQuotes)
                                     .Build();

            var fulfiller = new ConvertibleQuoteIntentFulfiller();
            var response  = await fulfiller.FulfillAsync(fulfillmentRequest, mockJobberClient.Object);

            response.AssertResponseSpeech("You have one quote that can be converted for John Doe.");
        }