コード例 #1
0
        public async Task AllowsOnlyAuthenticatedPrincipal()
        {
            var aggregatedSensorData = new List <AggregatedSensorData> {
                new AggregatedSensorData(), new AggregatedSensorData()
            };

            var sensorInputService = A.Fake <ISensorInputService>();

            A.CallTo(() => sensorInputService.ProcessInputAsync(SensorInput)).Returns(aggregatedSensorData);

            var function = new SensorInputFunction(sensorInputService, A.Fake <ILogger <SensorInputFunction> >());

            var outputCollector = A.Fake <IAsyncCollector <AggregatedSensorData> >();

            var result = await function.Run(SensorInput,
                                            new ClaimsPrincipal(new ClaimsIdentity()),
                                            outputCollector,
                                            CancellationToken.None);

            result.Should().BeOfType <UnauthorizedResult>();
        }
コード例 #2
0
        public async Task CreatesOutputForEachAggregation()
        {
            var aggregatedSensorData = new List <AggregatedSensorData> {
                new AggregatedSensorData(), new AggregatedSensorData()
            };

            var sensorInputService = A.Fake <ISensorInputService>();

            A.CallTo(() => sensorInputService.ProcessInputAsync(SensorInput)).Returns(aggregatedSensorData);

            var function = new SensorInputFunction(sensorInputService, A.Fake <ILogger <SensorInputFunction> >());

            var outputCollector = A.Fake <IAsyncCollector <AggregatedSensorData> >();

            var result = await function.Run(SensorInput,
                                            new ClaimsPrincipal(new ClaimsIdentity("Test")),
                                            outputCollector,
                                            CancellationToken.None);

            result.Should().BeOfType <OkResult>();
            A.CallTo(() => outputCollector.AddAsync(A <AggregatedSensorData> ._, A <CancellationToken> ._)).MustHaveHappened(aggregatedSensorData.Count, Times.Exactly);
            A.CallTo(() => outputCollector.FlushAsync(A <CancellationToken> ._)).MustHaveHappenedOnceExactly();
        }