Пример #1
0
        public async Task Process_CommandMessage_SourceHasNotMetric(LangCode langCode, string content, StateType sourceState,
                                                                    MessageCode returnCode)
        {
            int    externalId = 1;
            string name       = "Koko";
            var    source     = new Source(externalId, name);

            source.UpdateState(sourceState);
            SourceRepoMock.Setup(r => r.FindOrCreateNew(externalId, name)).Returns(() => source);

            var message = new CommandUpdateMessage
            {
                ChatId       = externalId,
                Username     = name,
                Content      = content,
                LanguageCode = langCode,
            };

            await message.Accept(MessageProcessor);

            var localizer = new Localizer();
            var text      = localizer.GetMessage(langCode, returnCode);

            BotResponseMock.Verify(x => x.Response(text), Times.Once);
        }
Пример #2
0
        public async Task Process_TextMessage_SourceHasNoMetric(LangCode langCode, StateType initialState)
        {
            int    externalId = 1;
            string name       = "Koko";
            Source source     = new Source(externalId, name);

            source.UpdateState(initialState);

            var mainMetric = new Metric("Some metric");

            mainMetric.UpdateSource(source);
            mainMetric.UpdateMain(true);

            MetricRepoMock.Setup(r => r.GetMainBySourceId(It.IsAny <long>())).Returns(() => mainMetric);
            MetricRepoMock.Setup(r => r.GetNotCreatedMetric(It.IsAny <long>())).Returns(() => mainMetric);

            SourceRepoMock.Setup(r => r.FindOrCreateNew(externalId, name)).Returns(() => source);
            SourceRepoMock.Setup(r => r.Update(source));

            MetricRepoMock.Setup(r => r.Add(It.IsAny <Metric>()));
            MetricRepoMock.Setup(r => r.Update(It.IsAny <Metric>()));

            var message = new TextUpdateMessage
            {
                ChatId       = externalId,
                Username     = name,
                Content      = "name or unit of metric",
                LanguageCode = langCode,
            };

            await message.Accept(MessageProcessor);

            var localizer = new Localizer();
            var text      = localizer.GetMessage(langCode, ProcessMessageVisitor.GetMessageCode(source.State));

            BotResponseMock.Verify(x => x.Response(text), Times.Once);
        }