public void ItUpdatesSimulationStatistics() { // Arrange var statisticsRecordId = $"{SIM_ID}__{NODE_IDS[0]}"; var inputStatistics = new SimulationStatisticsModel { ActiveDevices = 5, TotalMessagesSent = 300, FailedDeviceConnections = 6, FailedDevicePropertiesUpdates = 8, FailedMessages = 10 }; var expectedStatistics = new SimulationStatisticsRecord { SimulationId = SIM_ID, NodeId = NODE_IDS[0], Statistics = inputStatistics }; IDataRecord newRecord = new DataRecord { Id = statisticsRecordId, Data = JsonConvert.SerializeObject(expectedStatistics), }; this.clusterNodes.Setup(x => x.GetCurrentNodeId()).Returns(NODE_IDS[0]); this.simulationStatisticsStorage.Setup(x => x.GetAsync(statisticsRecordId)).ReturnsAsync(newRecord); // Act var result = this.target.UpdateAsync(SIM_ID, inputStatistics).CompleteOrTimeout(); // Assert this.simulationStatisticsStorage.Verify(x => x.UpsertAsync(It.Is <IDataRecord>( a => a.GetId() == newRecord.GetId() && a.GetData() == newRecord.GetData()), 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()))); }