public void TheSecondOfThreeCloseMessagesIsInterpolated() { var storeMessaggioPosizione = new StoreMessaggioPosizione_DB(dbContext.MessaggiPosizioneCollection); var interpolationDecorator = new StoreMessaggioPosizione_DeleteInterpolatedMessages_Decorator(storeMessaggioPosizione, dbContext.MessaggiPosizioneCollection); interpolationDecorator.InterpolationThreshold_mt = 100; var msg1 = new MessaggioPosizione() { CodiceMezzo = "Test", IstanteAcquisizione = DateTime.UtcNow.AddMinutes(-2), Localizzazione = new Localizzazione { Lat = 1, Lon = 1 }, }; var msgTime = DateTime.UtcNow.AddMinutes(-1); var msg2 = new MessaggioPosizione() { CodiceMezzo = "Test", IstanteAcquisizione = msgTime, Localizzazione = new Localizzazione { Lat = 1, Lon = 1 }, }; var msg3 = new MessaggioPosizione() { CodiceMezzo = "Test", IstanteAcquisizione = DateTime.UtcNow.AddMinutes(0), Localizzazione = new Localizzazione { Lat = 1, Lon = 1 }, }; interpolationDecorator.Store(msg1); interpolationDecorator.Store(msg2); interpolationDecorator.Store(msg3); var storedMsgs = dbContext.MessaggiPosizioneCollection .Find(m => m.CodiceMezzo == "Test") .ToList(); Assert.Multiple(() => { Assert.That(storedMsgs.Count, Is.EqualTo(2)); Assert.That(storedMsgs.Single(m => m.Id == msg1.Id).InterpolationData, Is.Null); Assert.That(storedMsgs.Single(m => m.Id == msg3.Id).InterpolationData.Messages, Is.EqualTo(1)); Assert.That(storedMsgs.Single(m => m.Id == msg3.Id).InterpolationData.Length_sec, Is.EqualTo(60)); Assert.That(storedMsgs.Single(m => m.Id == msg3.Id).InterpolationData.LastMsgTime.Value.Subtract(msgTime).TotalMilliseconds, Is.LessThan(10)); }); }
public void WhenThirdMessagesIsNotSoCloseMessagesAreNotInterpolated() { var storeMessaggioPosizione = new StoreMessaggioPosizione_DB(dbContext.MessaggiPosizioneCollection); var interpolationDecorator = new StoreMessaggioPosizione_DeleteInterpolatedMessages_Decorator(storeMessaggioPosizione, dbContext.MessaggiPosizioneCollection); interpolationDecorator.InterpolationThreshold_mt = 10; var msg1 = new MessaggioPosizione() { CodiceMezzo = "Test", IstanteAcquisizione = DateTime.UtcNow.AddMinutes(-2), Localizzazione = new Localizzazione { Lat = 1, Lon = 1 }, }; var msg2 = new MessaggioPosizione() { CodiceMezzo = "Test", IstanteAcquisizione = DateTime.UtcNow.AddMinutes(-1), Localizzazione = new Localizzazione { Lat = 1, Lon = 1 }, }; var msg3 = new MessaggioPosizione() { CodiceMezzo = "Test", IstanteAcquisizione = DateTime.UtcNow.AddMinutes(0), Localizzazione = new Localizzazione { Lat = 1.00015, Lon = 1 }, //few more than 10 mt }; interpolationDecorator.Store(msg1); interpolationDecorator.Store(msg2); interpolationDecorator.Store(msg3); var storedMsgs = dbContext.MessaggiPosizioneCollection .Find(m => m.CodiceMezzo == "Test") .ToList(); Assert.Multiple(() => { Assert.That(storedMsgs.Count, Is.EqualTo(3)); Assert.That(storedMsgs.Single(m => m.Id == msg1.Id).InterpolationData, Is.Null); Assert.That(storedMsgs.Single(m => m.Id == msg2.Id).InterpolationData, Is.Null); Assert.That(storedMsgs.Single(m => m.Id == msg3.Id).InterpolationData, Is.Null); }); }