public string GetPathForRecord(DailyDeviceReading record)
        {
            DateTime dt       = UnixTimeStampToDateTime(record.readAt);
            string   filePath = String.Format("devicesim/year={0}/month={1}/day={2}/{3}", dt.Year, dt.Month, dt.Day, record.deviceId);

            return(filePath);
        }
Ejemplo n.º 2
0
        public void GivenReading20191217_WhenGetPath_ThenPathPartitioned()
        {
            DailyDeviceReading record = new DailyDeviceReading
            {
                deviceId = "foo"
            };
            DateTime readAt = new DateTime(2019, 12, 17);

            record.readAt = (long)readAt.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            Assert.True(_sut.GetPathForRecord(record).Equals("devicesim/year=2019/month=12/day=17/foo"));
        }
        public async Task SaveOverwriteIfExistsAsync(DailyDeviceReading record)
        {
            string path = GetPathForRecord(record);

            _logger.LogInformation("Writing to ADLS as file:\n\t {0}\n", path);
            BlobClient fileClient = _adlsClient.GetBlobClient(path);
            string     recordJson = JsonConvert.SerializeObject(record);

            byte[] byteArray = Encoding.UTF8.GetBytes(recordJson);
            using MemoryStream stream = new MemoryStream(byteArray);
            await fileClient.DeleteIfExistsAsync(Azure.Storage.Blobs.Models.DeleteSnapshotsOption.IncludeSnapshots);

            await fileClient.UploadAsync(stream);
        }
Ejemplo n.º 4
0
        public void GivenNumRecordsMarker_WhenGenerateReading1_ThenGenerateDeleteCreateSameNumRecordsMarker()
        {
            //Given
            double marker = 0.1;

            DailyDeviceReading[] records = new DailyDeviceReading[_numReadings];
            _mockRecordsGenerator.Setup(arg => arg.Generate(_numReadings, marker)).Returns(records.ToList());

            //When
            _sut.CreateReading1(marker);

            //Then
            _mockRecordsGenerator.Verify(arg => arg.Generate(It.Is <int>(i => i == _numReadings), It.Is <double>(d => d == marker)), Times.Once());
            //_mockRepository.Verify(arg => arg.DeleteRecords(It.Is<List<DailyDeviceReading>>(o => o.Count == _numReadings)), Times.Never());
            _mockRepository.Verify(arg => arg.DeleteRecords(It.Is <List <DailyDeviceReading> >(o => o.Count == _numReadings)), Times.Once());
            _mockRepository.Verify(arg => arg.CreateRecords(It.Is <List <DailyDeviceReading> >(o => o.Count == _numReadings)), Times.Once());
        }
        public async void GivenChangedRecord_WhenHandleChangesAsync_ThenCallStorage()
        {
            //Given
            DailyDeviceReading record = new DailyDeviceReading
            {
                deviceId = "foo"
            };
            DateTime readAt = new DateTime(2019, 12, 17);

            record.readAt = (long)readAt.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            DailyDeviceReading [] records           = new DailyDeviceReading[] { record };
            CancellationToken     cancellationToken = new CancellationToken();
            Task task = Task.CompletedTask;

            _mockStorage.Setup(arg => arg.SaveOverwriteIfExistsAsync(record)).Returns(task);

            //When
            await _sut.HandleChangesAsync(records, cancellationToken);

            //Then
            _mockStorage.Verify(arg => arg.SaveOverwriteIfExistsAsync(record), Times.Once());
        }