public async Task FixtureSetUp() { _fixture = new Fixture(); _repoMock = new Mock <ISightingRepository <StubReportedSighting> >(); _protoTranslator = new Mock <IProtocolTranslator>(); _repertoir = new Mock <ISightingAnalyzerRepertoire>(); _routeRegistry = new Mock <IRouteRegistry>(); _harness = new InMemoryTestHarness(); _consumer = _harness.Consumer(() => new SightingInvestigationConsumer <StubReportedSighting>( _repoMock.Object, _protoTranslator.Object, _repertoir.Object, _routeRegistry.Object)); var ev = _fixture.Create <NewSightingReported>(); var chiefInvestigatorQ = new Uri("mq://chiefInspectorJapp"); var dbRecord = new StubReportedSighting(); var investigateCommand = new InvestigateSighting { Origin = "meh" }; _repertoir.Setup(e => e.All()).Returns(new[] { new RiggedAnalyzer(true), new RiggedAnalyzer(false) }); _routeRegistry.Setup(e => e.For <InvestigateSighting>()).Returns(chiefInvestigatorQ); _protoTranslator.Setup(e => e.TranslateToRecord <StubReportedSighting>(It.IsAny <NewSightingReported>(), It.Is <IAnalysisResults[]>(p => p.Length == 2))) .Returns(dbRecord); _protoTranslator.Setup(e => e.Translate(It.IsAny <NewSightingReported>(), It.Is <IAnalysisResults[]>(p => p.All(x => x.IsSuspicious)))) .Returns(investigateCommand); _repoMock.Setup(e => e.Add(dbRecord)).Returns(dbRecord); await _harness.Start(); await _harness.InputQueueSendEndpoint.Send(ev); }
public async Task Consume(ConsumeContext <NewSightingReported> context) { var reportedAnalysis = _analyzerRepertoire.All() .Select(e => e.Analyze(context.Message, _sightingRepository)) .ToArray(); var sightingRecord = _protocolTranslator.TranslateToRecord <T>(context.Message, reportedAnalysis); _sightingRepository.Add(sightingRecord); var suspiciousResults = reportedAnalysis.Where(e => e.IsSuspicious).ToArray(); if (suspiciousResults.Any()) { InvestigateSighting investigateCommand = _protocolTranslator.Translate(context.Message, suspiciousResults); await context.Send(_routeRegistry.For <InvestigateSighting>(), investigateCommand); } }