Esempio n. 1
0
        public async Task SendScheduledTimesheetShouldStoreStatistics()
        {
            var date = new DateTime(2020, 7, 1, 20, 0, 0, DateTimeKind.Local);
            var timesheetProcessor        = Substitute.For <ITimesheetProcessor>();
            var propertiesAccessor        = Substitute.For <IPluginPropertiesAccessor>();
            var deconstructionInformation = new TextDeconstructionInformation(null, null);
            var analysisResult            = new CognitiveTextAnalysisResult(deconstructionInformation, timesheetProcessor, propertiesAccessor);

            _cognitiveService.GetCognitiveTextAnalysisResultAsync(null, null).ReturnsForAnyArgs(analysisResult);
            propertiesAccessor
            .GetPluginPropertyGroup("OpenAir.GlobalReport")
            .Returns(
                new[]
            {
                new []
                {
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.GlobalReport.Cron",
                        Value = "20 Wed"
                    },
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.GlobalReport.Email",
                        Value = "[email protected]"
                    },
                }
            });

            timesheetProcessor
            .GetTimesheetsAsync(Arg.Any <DateTime>(), TimesheetStates.Unsubmitted, "[email protected]", true, null)
            .Returns(new[] {
                new Timesheet
                {
                    UserEmail          = "[email protected]",
                    UserName           = "******",
                    DepartmentName     = "Account",
                    ManagerName        = "*****@*****.**",
                    Total              = 5,
                    UtilizationInHours = 10
                }
            });

            await _timesheetService.SendScheduledTimesheetNotificationsAsync(date);

            _storageService
            .Received()
            .AddOrUpdateStatisticsAsync(Arg.Any <Statistics <TimesheetStatistics[]> >());
        }
        /// <inheritdoc/>
        public Task <CognitiveTextAnalysisResult> ProcessAsync(ChatEvent chatEvent)
        {
            var text = chatEvent?.Message.Text ??
                       throw new ArgumentNullException(nameof(chatEvent), "The text message is null.");

            text = BotSelfPoint.Replace(text, string.Empty).Trim();

            var question =
                text.EndsWith("?", StringComparison.InvariantCulture) ||
                Regex.IsMatch(text, "^(([Ww]hat)|([Ww]here)|([Hh]ow)|([Ww]hy)|([Ww]ho))\\s");

            var definition = new TextDeconstructionInformation(text.TrimEnd('?', '.', '!'), null, question ? SentenceTypes.Question : SentenceTypes.Command, null);

            var command = StupidMachineLearningPool.FirstOrDefault(it =>
                                                                   it.Key.SentenceType == definition.SentenceType &&
                                                                   text.IndexOf(it.Key.TextSentanceChunk, StringComparison.InvariantCultureIgnoreCase) > -1);

            var result = new CognitiveTextAnalysisResult(definition, command.Value, 1.0);

            return(Task.FromResult(result));
        }
Esempio n. 3
0
        public async Task SendScheduledTimesheetShouldSendToSpace()
        {
            var date = new DateTime(2020, 7, 1, 20, 0, 0, DateTimeKind.Local);
            var timesheetProcessor        = Substitute.For <ITimesheetProcessor>();
            var propertiesAccessor        = Substitute.For <IPluginPropertiesAccessor>();
            var deconstructionInformation = new TextDeconstructionInformation(null, null);
            var analysisResult            = new CognitiveTextAnalysisResult(deconstructionInformation, timesheetProcessor, propertiesAccessor);
            var address   = new GoogleChatAddress("S1", "Space 1", "RM", "U1", "User 1");
            var timesheet = new Timesheet {
                UserEmail = "[email protected]", UserName = "******", DepartmentName = "Account", ManagerName = "*****@*****.**", Total = 5, UtilizationInHours = 10
            };
            var excludeCustomers = new[] { "C1" };

            _cognitiveService.GetCognitiveTextAnalysisResultAsync(null, null).ReturnsForAnyArgs(analysisResult);

            propertiesAccessor.GetAllPluginPropertyValues <string>("OpenAir.Filters.Customer").Returns(excludeCustomers);
            propertiesAccessor
            .GetPluginPropertyGroup("OpenAir.AutoNotifications")
            .Returns(
                new[]
            {
                new []
                {
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.AutoNotifications.Spaces",
                        Value = "S1"
                    },
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.AutoNotifications.Email",
                        Value = "[email protected]"
                    },
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.AutoNotifications.ReportName",
                        Value = "unsubmitted"
                    },
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.AutoNotifications.Cron",
                        Value = "20 Wed"
                    },
                    new PluginPropertyValue
                    {
                        Key   = "OpenAir.AutoNotifications.Notify",
                        Value = false
                    },
                }
            });

            _hangoutsChatConnector.GetAddressByName("spaces/S1").Returns(address);
            timesheetProcessor
            .GetTimesheetsAsync(Arg.Any <DateTime>(), TimesheetStates.Unsubmitted, "[email protected]", true, excludeCustomers)
            .Returns(new[] { timesheet });

            await _timesheetService.SendScheduledTimesheetNotificationsAsync(date);

            timesheetProcessor
            .Received()
            .SendTimesheetNotificationsToUsersAsync(
                Arg.Is <IReadOnlyList <Timesheet> >(it => it[0].UserName == "Jhon Doe"),
                "[email protected]",
                null,
                false,
                false,
                TimesheetStates.Unsubmitted,
                address,
                _hangoutsChatConnector);
        }