示例#1
0
        public void ItUpdatesSimulationStatistics()
        {
            // Arrange
            var statisticsRecordId = $"{SIM_ID}__{NODE_IDS[0]}";

            SimulationStatisticsModel inputStatistics = new SimulationStatisticsModel
            {
                ActiveDevices                 = 5,
                TotalMessagesSent             = 300,
                FailedDeviceConnections       = 6,
                FailedDevicePropertiesUpdates = 8,
                FailedMessages                = 10
            };

            SimulationStatisticsRecord expectedStatistics = new SimulationStatisticsRecord
            {
                SimulationId = SIM_ID,
                NodeId       = NODE_IDS[0],
                Statistics   = inputStatistics
            };

            StorageRecord storageRecord = new StorageRecord
            {
                Id   = statisticsRecordId,
                Data = JsonConvert.SerializeObject(expectedStatistics),
            };

            this.clusterNodes.Setup(x => x.GetCurrentNodeId()).Returns(NODE_IDS[0]);
            this.simulationStatisticsStorage.Setup(x => x.ExistsAsync(statisticsRecordId)).ReturnsAsync(true);
            this.simulationStatisticsStorage.Setup(x => x.GetAsync(statisticsRecordId)).ReturnsAsync(storageRecord);

            // Act
            var result = this.target.CreateOrUpdateAsync(SIM_ID, inputStatistics).CompleteOrTimeout();

            // Assert
            this.simulationStatisticsStorage.Verify(x => x.GetAsync(It.Is <string>(
                                                                        a => a == statisticsRecordId)));
            this.simulationStatisticsStorage.Verify(x => x.UpsertAsync(It.Is <StorageRecord>(
                                                                           a => a.Id == storageRecord.Id &&
                                                                           a.Data == storageRecord.Data),
                                                                       It.IsAny <string>()));
        }
        public void ItCreatesSimulationStatistics()
        {
            // Arrange
            var statisticsRecordId = $"{SIM_ID}__{NODE_IDS[0]}";

            SimulationStatisticsModel statistics = new SimulationStatisticsModel
            {
                ActiveDevices                 = 5,
                TotalMessagesSent             = 300,
                FailedDeviceConnections       = 6,
                FailedDevicePropertiesUpdates = 8,
                FailedMessages                = 10
            };

            SimulationStatisticsRecord statisticsRecord = new SimulationStatisticsRecord
            {
                NodeId       = NODE_IDS[0],
                SimulationId = SIM_ID,
                Statistics   = statistics
            };

            IDataRecord storageRecord = new DataRecord
            {
                Id   = statisticsRecordId,
                Data = JsonConvert.SerializeObject(statisticsRecord)
            };

            this.clusterNodes.Setup(x => x.GetCurrentNodeId()).Returns(NODE_IDS[0]);

            this.simulationStatisticsStorage.Setup(x => x.ExistsAsync(NODE_IDS[0])).ReturnsAsync(false);

            // Act
            this.target.CreateOrUpdateAsync(SIM_ID, statistics).CompleteOrTimeout();

            // Assert
            this.simulationStatisticsStorage.Verify(x => x.CreateAsync(It.Is <IDataRecord>(
                                                                           a => a.GetId() == storageRecord.GetId() &&
                                                                           a.GetData() == storageRecord.GetData())));
        }