Ejemplo n.º 1
0
        public ProcessMessageVisitorTest()
        {
            BotResponseMock = new Mock <FakeBotResponse>();
            BotResponseMock.Setup(x => x.Response(It.IsAny <string>()));
            IBotClient botClient = new FakeBotClient(BotResponseMock.Object);

            SourceRepoMock = new Mock <ISourceRepository>();
            ValueRepoMock  = new Mock <IValueRepository>();
            MetricRepoMock = new Mock <IMetricRepository>();

            var valueHandlerLoggerMock = new Mock <ILogger <ValueHandlerService> >();
            var valueHandlerService    = new ValueHandlerService(
                valueHandlerLoggerMock.Object,
                botClient,
                MetricRepoMock.Object,
                ValueRepoMock.Object);

            var helper               = new ServiceHelper();
            var commandFactory       = helper.CreateCSF(botClient);
            var buttonCommandFactory = helper.CreateButtonCSF(
                botClient,
                SourceRepoMock.Object,
                MetricRepoMock.Object,
                ValueRepoMock.Object);

            MessageProcessor = new ProcessMessageVisitor(
                botClient,
                commandFactory,
                SourceRepoMock.Object,
                buttonCommandFactory,
                valueHandlerService,
                MetricRepoMock.Object);
        }
Ejemplo n.º 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);
        }