Exemple #1
0
        public static PropertiesValues RndPropertiesValues(int min = 2, int max = 10)
        {
            int count            = Rnd.Next(min, max);
            var propertiesValues = new PropertiesValues(count);

            for (int i = 0; i < count; i++)
            {
                string propCode = RndString();
                string value    = RndString();
                propertiesValues.Add(propCode, value);
            }
            return(propertiesValues);
        }
Exemple #2
0
        public void GetDataTest()
        {
            //1
            ActualSpan     = new TimeSpan(0, 0, 10);
            MessageSendler = new MessageSenderMoq();

            var              telemetriesDictionaryExpected        = new Dictionary <string, IList <Telemetry> >(3);
            var              telemetriesDictionaryUpdatedExpected = new Dictionary <string, Telemetry>(3);
            string           deviceCode1  = RndString();
            List <Telemetry> telemetries1 = RndTelemetries(deviceCode1);

            telemetriesDictionaryExpected.Add(deviceCode1, telemetries1);

            PropertiesValues propertiesValues1 = new PropertiesValues();

            foreach (Telemetry telemetry in telemetries1)
            {
                if (ActualCheck(telemetry))
                {
                    continue;
                }
                foreach (var kvp in telemetry.Values)
                {
                    if (propertiesValues1.ContainsKey(kvp.Key))
                    {
                        continue;
                    }
                    propertiesValues1.Add(kvp.Key, kvp.Value);
                }
            }
            Telemetry newTelemetries1 = new Telemetry(MyCode, propertiesValues1, DateTime.Now, deviceCode1);

            telemetriesDictionaryExpected[deviceCode1].Add(newTelemetries1);
            telemetriesDictionaryUpdatedExpected.Add(deviceCode1, newTelemetries1);

            string           deviceCode2  = RndString();
            List <Telemetry> telemetries2 = RndTelemetries(deviceCode2);

            telemetriesDictionaryExpected.Add(deviceCode2, telemetries2);

            PropertiesValues propertiesValues2 = new PropertiesValues();

            foreach (Telemetry telemetry in telemetries2)
            {
                if (ActualCheck(telemetry))
                {
                    continue;
                }
                foreach (var kvp in telemetry.Values)
                {
                    if (propertiesValues2.ContainsKey(kvp.Key))
                    {
                        continue;
                    }
                    propertiesValues2.Add(kvp.Key, kvp.Value);
                }
            }
            Telemetry newTelemetries2 = new Telemetry(MyCode, propertiesValues2, DateTime.Now, deviceCode2);

            telemetriesDictionaryExpected[deviceCode2].Add(newTelemetries2);
            telemetriesDictionaryUpdatedExpected.Add(deviceCode2, newTelemetries2);


            string           deviceCode3  = RndString();
            List <Telemetry> telemetries3 = RndTelemetries(deviceCode3);

            telemetriesDictionaryExpected.Add(deviceCode3, telemetries3);

            PropertiesValues propertiesValues3 = new PropertiesValues();

            foreach (Telemetry telemetry in telemetries3)
            {
                if (ActualCheck(telemetry))
                {
                    continue;
                }
                foreach (var kvp in telemetry.Values)
                {
                    if (propertiesValues3.ContainsKey(kvp.Key))
                    {
                        continue;
                    }
                    propertiesValues3.Add(kvp.Key, kvp.Value);
                }
            }
            Telemetry newTelemetries3 = new Telemetry(MyCode, propertiesValues3, DateTime.Now, deviceCode3);

            telemetriesDictionaryExpected[deviceCode3].Add(newTelemetries3);
            telemetriesDictionaryUpdatedExpected.Add(deviceCode3, newTelemetries3);

            var moq = new DbMoq {
                SetData = telemetriesDictionaryExpected
            };

            DbController = moq;

            var           telemetryName1 = telemetries1.SelectMany(t => t.Values.Keys);
            var           telemetryName2 = telemetries1.SelectMany(t => t.Values.Keys);
            var           telemetryName3 = telemetries1.SelectMany(t => t.Values.Keys);
            List <string> properties     = telemetryName1.Concat(telemetryName2.Concat(telemetryName3)).Distinct().ToList();

            //2
            IDictionary <string, IList <Telemetry> > telemetriesDictionary = new Dictionary <string, IList <Telemetry> >();
            var task = Task.Run(() => GetData(out telemetriesDictionary, properties));

            Task.Delay(3000).Wait();

            foreach (var telemetriesList in telemetriesDictionaryExpected)
            {
                foreach (Telemetry telemetry in telemetriesList.Value)
                {
                    moq.DataAddedInvok(this, telemetry);
                }
            }
            task.Wait();
            //3

            Assert.AreEqual(task.Result, ConnectionResult.Successful);
            Assert.AreEqual(telemetriesDictionaryExpected.Count, telemetriesDictionary.Count);
            foreach (var kvp in telemetriesDictionaryExpected)
            {
                var maxDate            = telemetriesDictionary[kvp.Key].Max(t => t.TimeMarker);
                var updatedTelemetries =
                    telemetriesDictionary[kvp.Key].Where(t => t.TimeMarker == maxDate);
                Assert.AreEqual(telemetriesDictionaryExpected[kvp.Key].Count, kvp.Value.Count);
                Assert.AreEqual(updatedTelemetries.Count(), 1);
                var act    = updatedTelemetries.First();
                var arrage = telemetriesDictionaryUpdatedExpected[kvp.Key];
                Assert.AreEqual(act.DeviceCode, arrage.DeviceCode);
                Assert.AreEqual(act.TimeMarker, arrage.TimeMarker);
                Assert.IsEmpty(act.Values.Keys.Except(arrage.Values.Keys));
                //foreach (Telemetry telemetry in telemetriesList.Value)
                //{

                //}
            }
        }