public void ShouldPublishForEachWeatherEvent()
        {
            // Create mock object response from sampledata.json
            var s3ResponseWithSampleData = new GetObjectResponse
            {
                ResponseStream = File.OpenRead(Path.Combine(TEST_DATA_PATH, "sampledata.json"))
            };

            // Tell fake S3 to return to return the mock object response created above.
            A.CallTo(() =>
                     _fakeS3.GetObjectAsync(A <GetObjectRequest> .That.Matches(x => x.BucketName == _s3GetObjectRequest.BucketName && x.Key == _s3GetObjectRequest.Key), A <CancellationToken> ._))
            .Returns(Task.FromResult(s3ResponseWithSampleData));


            var bulkEventsLambda = new BulkEventsLambda(_fakeS3, _fakeSns, _snsTopic);

            bulkEventsLambda.S3EventHandler(_fakeS3Event);

            // 3 events in sampledata.json => expect 3 sns publish calls.
            A.CallTo(() =>
                     _fakeSns.PublishAsync(_snsTopic, A <string> ._, CancellationToken.None))
            .MustHaveHappened(3, Times.Exactly);


            var expectedMessage = "{\"LocationName\":\"New York, NY\",\"Temperature\":91,\"Timestamp\":1564428897,\"Longitude\":-73.99,\"Latitude\":40.7}";

            A.CallTo(() =>
                     _fakeSns.PublishAsync(_snsTopic, expectedMessage, CancellationToken.None))
            .MustHaveHappenedOnceExactly();
        }
Exemplo n.º 2
0
        public void ShouldThrowWithBadData()
        {
            var mockS3Response = new GetObjectResponse
            {
                ResponseStream = File.OpenRead(Path.Combine(TEST_DATA_PATH, "baddata.json"))
            };

            var lambda = new BulkEventsLambda(null, null, "dummy");

            Action act = () => lambda.ReadWeatherEvents(mockS3Response);

            act.Should().Throw <System.Text.Json.JsonException>();
        }
        public void ShouldThrowWithInvalidJson()
        {
            var s3ResponseWithBadData = new GetObjectResponse
            {
                ResponseStream = File.OpenRead(Path.Combine(TEST_DATA_PATH, "baddata.json"))
            };

            // Tell fake S3 to return to return the mock object response created above.
            A.CallTo(() =>
                     _fakeS3.GetObjectAsync(A <GetObjectRequest> .That.Matches(x => x.BucketName == _s3GetObjectRequest.BucketName && x.Key == _s3GetObjectRequest.Key), A <CancellationToken> ._))
            .Returns(Task.FromResult(s3ResponseWithBadData));

            var    bulkEventsLambda = new BulkEventsLambda(_fakeS3, _fakeSns, _snsTopic);
            Action act = () => bulkEventsLambda.S3EventHandler(_fakeS3Event);

            act.Should().Throw <System.Text.Json.JsonException>();
        }
Exemplo n.º 4
0
        public void ShouldReadWeatherEvents()
        {
            var bulkEventsLambda = new BulkEventsLambda(null, null, "dummyTopic");
            var mockS3Response   = new GetObjectResponse
            {
                ResponseStream = File.OpenRead(Path.Combine(TEST_DATA_PATH, "sampledata.json"))
            };

            var weatherEvents = bulkEventsLambda.ReadWeatherEvents(mockS3Response);

            weatherEvents.Count.Should().Be(3);

            weatherEvents[0].LocationName.Should().Be("New York, NY");
            weatherEvents[0].Temperature.Should().Be(91);
            weatherEvents[0].Timestamp.Should().Be(1564428897);
            weatherEvents[0].Latitude.Should().Be(40.70);
            weatherEvents[0].Longitude.Should().Be(-73.99);
        }