public CommandsTest(ITestOutputHelper outputHelper) { var botResponse = new FakeBotResponse(outputHelper); IBotClient botClient = new FakeBotClient(botResponse); _commandFactory = new ServiceHelper().CreateCSF(botClient); }
public void SetUp() { fakeClient = new FakeBotClient(); register = new CommandRegister(fakeClient); register.RegisterCommand("ping", new Ping()); register.RegisterCommand("fake", new Ping()); }
public async Task ToJsonButtonCommand_HandleAsync_Success(int updateId) { var message = new CallbackQueryUpdateMessage { ChatId = 1, UpdateId = updateId }; var botResponseMock = new Mock <FakeBotResponse>(); botResponseMock.Setup(x => x.Response(It.IsAny <string>())); IBotClient botClient = new FakeBotClient(botResponseMock.Object); var metricRepoMock = new Mock <IMetricRepository>(); var testData = new TestData(); var metrics = testData.GetMetrics(updateId); metricRepoMock.Setup(x => x.GetBySourceIdWithValues(It.IsAny <long>())).Returns(metrics); var sourceRepoMock = new Mock <ISourceRepository>(); sourceRepoMock.Setup(x => x.GetByExternalId(It.IsAny <long>())).Returns(testData.Source); var command = new ToJsonButtonCommand(botClient, metricRepoMock.Object, sourceRepoMock.Object); await command.HandleAsync(message); var filename = FileName.GetJsonFilename(updateId.ToString()); botResponseMock.Verify(x => x.Response(filename)); }
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); }
public async Task ParseAsync_Success(int updateId) { IBotClient botClient = new FakeBotClient(new FakeBotResponse()); var parser = new MetricsJsonParser(botClient); var filename = FileName.GetJsonFilename(updateId.ToString()); var newMetrics = await parser.ParseAsync(filename); var testMetrics = new TestData().GetMetrics(updateId); Assert.NotNull(newMetrics); Assert.Equal(newMetrics.Count(), testMetrics.Count()); foreach (var newMetric in newMetrics) { var testMetric = testMetrics.FirstOrDefault(x => x.Name == newMetric.Name && x.Unit == newMetric.Unit); Assert.NotNull(testMetric); Assert.Equal(newMetric.Values.Count(), testMetric.Values.Count()); foreach (var value in newMetric.Values) { Assert.NotNull(testMetric.Values.FirstOrDefault(x => x.Content == value.Content && x.ValueDate == value.ValueDate)); } } }