Ejemplo n.º 1
0
        public async Task RunFetchConcentratorFirmware_Succeeds()
        {
            var httpRequest     = new Mock <HttpRequest>();
            var queryCollection = new QueryCollection(new Dictionary <string, StringValues>()
            {
                { "StationEui", new StringValues(this.TestStationEui.ToString()) }
            });

            httpRequest.SetupGet(x => x.Query).Returns(queryCollection);

            var twin = new Twin();

            twin.Properties.Desired = new TwinCollection(JsonUtil.Strictify(@"{'cups': {
                'package': '1.0.1',
                'fwUrl': 'https://storage.blob.core.windows.net/container/blob',
                'fwKeyChecksum': 123456,
                'fwSignature': '123'
            }}"));
            this.registryManager.Setup(m => m.GetTwinAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(twin));

            var blobBytes = Encoding.UTF8.GetBytes(BlobContent);

            using var blobContentStream = new MemoryStream(blobBytes);
            using var streamingResult   = BlobsModelFactory.BlobDownloadStreamingResult(blobContentStream);
            this.blobClient.Setup(m => m.DownloadStreamingAsync(default, null, false, It.IsAny <CancellationToken>()))
Ejemplo n.º 2
0
        public async Task GetCursor()
        {
            // Arrange
            string manifestPath = "idx/segments/2020/03/25/0200/meta.json";

            Mock <BlobContainerClient> containerClient = new Mock <BlobContainerClient>(MockBehavior.Strict);
            Mock <BlobClient>          blobClient      = new Mock <BlobClient>(MockBehavior.Strict);
            Mock <ShardFactory>        shardFactory    = new Mock <ShardFactory>(MockBehavior.Strict);

            List <Mock <Shard> > shards = new List <Mock <Shard> >();
            int shardCount = 3;

            for (int i = 0; i < shardCount; i++)
            {
                shards.Add(new Mock <Shard>(MockBehavior.Strict));
            }

            DateTimeOffset dateTime         = new DateTimeOffset(2020, 3, 25, 2, 0, 0, TimeSpan.Zero);
            string         segmentPath      = "idx/segments/2020/03/25/0200/meta.json";
            string         currentShardPath = "log/00/2020/03/25/0200/";

            List <ShardCursor> shardCursors = new List <ShardCursor>
            {
                new ShardCursor("log/00/2020/03/25/0200/chunk1", 2, 3),
                new ShardCursor("log/01/2020/03/25/0200/chunk4", 5, 6),
                new ShardCursor("log/02/2020/03/25/0200/chunk7", 8, 9)
            };

            SegmentCursor expectedCursor = new SegmentCursor(
                segmentPath,
                shardCursors,
                currentShardPath);

            containerClient.Setup(r => r.GetBlobClient(It.IsAny <string>())).Returns(blobClient.Object);

            using FileStream stream = File.OpenRead(
                      $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}{"SegmentManifest.json"}");
            BlobDownloadStreamingResult            blobDownloadStreamingResult = BlobsModelFactory.BlobDownloadStreamingResult(content: stream);
            Response <BlobDownloadStreamingResult> downloadResponse            = Response.FromValue(blobDownloadStreamingResult, new MockResponse(200));

            if (IsAsync)
            {
                blobClient.Setup(r => r.DownloadStreamingAsync(default, default, default, default)).ReturnsAsync(downloadResponse);