Esempio n. 1
0
        protected bool CompareSourceInformation(RecordingSourceInformation source1,
                                                RecordingSourceInformation source2, string itemToken, StringBuilder logger)
        {
            if (source1 == null && source2 == null)
            {
                return(true);
            }

            if (source1 == null)
            {
                logger.AppendFormat(
                    "RecordingSourceInformation is missing for item with token '{0}' (when got via GetRecordings){1}",
                    itemToken, Environment.NewLine);
                return(false);
            }
            if (source2 == null)
            {
                logger.AppendFormat(
                    "RecordingSourceInformation is missing for item with token '{0}' (when got via FindRecordingSearchResult){1}",
                    itemToken, Environment.NewLine);
                return(false);
            }

            bool ok = true;

            Action <string, Func <RecordingSourceInformation, string> > checkStringAction =
                new Action <string, Func <RecordingSourceInformation, string> >((name, fieldSelector) =>
            {
                string value1 = fieldSelector(source1);
                string value2 = fieldSelector(source2);
                if (value1 != value2)
                {
                    ok = false;
                    logger.AppendFormat("Source.{0} field is different for Recording with token '{1}' ('{2}' when got via GetRecordings, '{3}' when got via FindRecordingSearchResult){4}",
                                        name, itemToken, value1, value2, Environment.NewLine);
                }
            });

            checkStringAction("Address", S => S.Address);
            checkStringAction("Description", S => S.Description);
            checkStringAction("Location", S => S.Location);
            checkStringAction("Name", S => S.Name);
            checkStringAction("SourceId", S => S.SourceId);

            return(ok);
        }
Esempio n. 2
0
        void CompareLists(IEnumerable <RecordingInformation> recordings1, IEnumerable <RecordingInformation> recordings2)
        {
            bool          ok     = true;
            StringBuilder logger = new StringBuilder();

            List <string> common = new List <string>();

            // check that all tokens from full list are present in list of found recordings
            foreach (RecordingInformation item in recordings1)
            {
                string token = item.RecordingToken;

                if (!recordings2.Any(RI => RI.RecordingToken == token))
                {
                    logger.AppendFormat("Recording with token {0} not found in second list{1}", item.RecordingToken, Environment.NewLine);
                    ok = false;
                }
                else
                {
                    common.Add(token);
                }
            }

            foreach (RecordingInformation item in recordings2)
            {
                string token = item.RecordingToken;

                if (!recordings1.Any(RI => RI.RecordingToken == token))
                {
                    logger.AppendFormat("Recording with token {0} not found in first list{1}", item.RecordingToken, Environment.NewLine);
                    ok = false;
                }
            }

            // for common only

            foreach (RecordingInformation info1 in recordings1)
            {
                string token = info1.RecordingToken;
                if (!common.Contains(token))
                {
                    continue;
                }

                RecordingInformation info2 = recordings2.FirstOrDefault(RI => RI.RecordingToken == token);

                StringBuilder dump = new StringBuilder(string.Format("Information for recording with token '{0}' is different:{1}", token, Environment.NewLine));

                bool localOk = true;

                if (info1.Content != info2.Content)
                {
                    localOk = false;
                    dump.AppendLine("   Content is different");
                }
                if (info1.RecordingStatus != info2.RecordingStatus)
                {
                    localOk = false;
                    dump.AppendLine("   RecordingStatus is different");
                }

                Action <Func <RecordingInformation, bool>, Func <RecordingInformation, System.DateTime>, string> check =
                    new Action <Func <RecordingInformation, bool>, Func <RecordingInformation, System.DateTime>, string>(
                        (specifiedSelector, valueSelector, fieldName) =>
                {
                    bool specified1 = specifiedSelector(info1);
                    bool specified2 = specifiedSelector(info2);

                    if (specified1 || specified2)
                    {
                        if (specified1 && specified2)
                        {
                            System.DateTime value1 = valueSelector(info1);
                            System.DateTime value2 = valueSelector(info2);

                            if (value1 != value2)
                            {
                                localOk = false;
                                dump.AppendFormat("   {0} is different{1}", fieldName, Environment.NewLine);
                            }
                        }
                        else
                        {
                            if (!specified1)
                            {
                                localOk = false;
                                dump.AppendFormat("   {0} not specified for the first list{1}", fieldName,
                                                  Environment.NewLine);
                            }
                            if (!specified2)
                            {
                                localOk = false;
                                dump.AppendFormat("   {0} not specified for the second list{1}", fieldName,
                                                  Environment.NewLine);
                            }
                        }
                    }
                });

                check(RI => RI.EarliestRecordingSpecified, RI => RI.EarliestRecording, "EarliestRecording");
                check(RI => RI.LatestRecordingSpecified, RI => RI.LatestRecording, "LatestRecording");

                RecordingSourceInformation source1 = info1.Source;
                RecordingSourceInformation source2 = info2.Source;

                if (source1 != null || source2 != null)
                {
                    if (source1 != null && source2 != null)
                    {
                        Action <string, Func <RecordingSourceInformation, string> > checkStringAction =
                            new Action <string, Func <RecordingSourceInformation, string> >(
                                (name, fieldSelector) =>
                        {
                            string value1 = fieldSelector(source1);
                            string value2 = fieldSelector(source2);
                            if (value1 != value2)
                            {
                                localOk = false;
                                dump.AppendFormat("   Source.{0} field is different {1}", name, Environment.NewLine);
                            }
                        });

                        checkStringAction("Address", S => S.Address);
                        checkStringAction("Description", S => S.Description);
                        checkStringAction("Location", S => S.Location);
                        checkStringAction("Name", S => S.Name);
                        checkStringAction("SourceId", S => S.SourceId);
                    }
                    else
                    {
                        if (source1 == null)
                        {
                            dump.AppendLine("   RecordingSourceInformation is missing for the item from the first list{0}");
                            localOk = false;
                        }
                        if (source2 == null)
                        {
                            dump.AppendLine("   RecordingSourceInformation is missing for the item from the second list{0}");
                            localOk = false;
                        }
                    }
                }

                bool trackList1Ok = info1.Track != null && info1.Track.Length > 0;
                bool trackList2Ok = info2.Track != null && info2.Track.Length > 0;

                if (trackList1Ok || trackList2Ok)
                {
                    if (trackList1Ok && trackList2Ok)
                    {
                        // compare track by track

                        bool tracksOk = true;

                        TrackInformation[] tracks1 = info1.Track;
                        TrackInformation[] tracks2 = info2.Track;

                        StringBuilder sb       = new StringBuilder();
                        bool          tokensOk = ArrayUtils.ValidateTokens(tracks1, TR => TR.TrackToken, sb);
                        if (!tokensOk)
                        {
                            dump.AppendFormat("   List of tracks is not valid for item from the first list - not all checks will be performed{0}", Environment.NewLine);
                            tracksOk = false;
                        }

                        sb       = new StringBuilder();
                        tokensOk = ArrayUtils.ValidateTokens(tracks2, TR => TR.TrackToken, sb);
                        if (!tokensOk)
                        {
                            dump.AppendFormat("   List of tracks is not valid for item from the second list - not all checks will be performed{0}", Environment.NewLine);
                            tracksOk = false;
                        }

                        {
                            List <string> commonTracks = new List <string>();

                            // compare tokens
                            foreach (TrackInformation info in tracks1)
                            {
                                TrackInformation inf = tracks2.FirstOrDefault(T => T.TrackToken == info.TrackToken);
                                if (inf == null)
                                {
                                    tracksOk = false;
                                    // not found
                                    dump.AppendFormat("   Track with token {0} not found for recording from second list{1}", info.TrackToken, Environment.NewLine);
                                }
                                else
                                {
                                    int cnt = tracks1.Count(T => T.TrackToken == info.TrackToken);
                                    if (cnt == 1)
                                    {
                                        commonTracks.Add(info.TrackToken);
                                    }
                                }
                            }
                            foreach (TrackInformation info in tracks2)
                            {
                                TrackInformation inf = tracks1.FirstOrDefault(T => T.TrackToken == info.TrackToken);
                                if (inf == null)
                                {
                                    tracksOk = false;
                                    // not found
                                    dump.AppendFormat("   Track with token {0} not found for recording from  first list{1}", info.TrackToken, Environment.NewLine);
                                }
                            }

                            {
                                // compare common

                                foreach (TrackInformation trackInfo1 in tracks1)
                                {
                                    string trackToken = trackInfo1.TrackToken;

                                    if (!commonTracks.Contains(trackToken))
                                    {
                                        continue;
                                    }

                                    TrackInformation[] infos = tracks2.Where(T => T.TrackToken == trackToken).ToArray();
                                    if (infos.Length != 1)
                                    {
                                        // error is added to log already
                                        continue;
                                    }
                                    TrackInformation trackInfo2 = infos[0];

                                    // DataFrom, DataTo, Description, TrackType

                                    if (trackInfo1.Description != trackInfo2.Description)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   Description is different for tracks with token '{0}'{1}", trackToken, Environment.NewLine);
                                    }

                                    if (trackInfo1.TrackType != trackInfo2.TrackType)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   TrackType is different for tracks with token '{0}' {1}", trackToken, Environment.NewLine);
                                    }

                                    if (trackInfo1.DataFrom != trackInfo2.DataFrom)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   DataFrom is different for tracks with token '{0}' {1}", trackToken, Environment.NewLine);
                                    }
                                    if (trackInfo1.DataTo != trackInfo2.DataTo)
                                    {
                                        tracksOk = false;
                                        dump.AppendFormat("   DataTo is different for tracks with token '{0}' {1}", trackToken, Environment.NewLine);
                                    }
                                }
                            }
                        }

                        localOk = localOk && tracksOk;
                    }
                    else
                    {
                        if (!trackList1Ok)
                        {
                            dump.AppendFormat("   Track list is missing for the item from the first list{0}",
                                              Environment.NewLine);
                            localOk = false;
                        }
                        if (!trackList2Ok)
                        {
                            dump.AppendFormat("   Track list is missing for the item from the first list{0}",
                                              Environment.NewLine);
                            localOk = false;
                        }
                    }
                }

                if (!localOk)
                {
                    logger.Append(dump.ToString());
                    ok = false;
                }
            }

            Assert(ok, logger.ToStringTrimNewLine(), "Check that all recordings are returned");
        }
Esempio n. 3
0
 protected bool CompareSourceInformation(RecordingSourceInformation source1,
                                         RecordingSourceInformation source2, string itemToken, StringBuilder logger)
 {
     return(StorageTestsUtils.CompareSourceInformation(source1, source2, "GetRecording",
                                                       "FindRecordingSearchResult", itemToken, logger));
 }
Esempio n. 4
0
        public static bool CompareSourceInformation(RecordingSourceInformation source1,
                                                    RecordingSourceInformation source2, string descr1, string descr2,
                                                    string itemToken, StringBuilder logger)
        {
            if (source1 == null && source2 == null)
            {
                return(true);
            }

            bool specifyToken = !string.IsNullOrEmpty(itemToken);

            string infoMissingFormatString = specifyToken ?
                                             string.Format("Source Information is missing for recording with token '{0}' (when got via {{0}}){1}", itemToken, Environment.NewLine) :
                                             string.Format("Source Information is missing (when got via {{0}}){0}", Environment.NewLine);

            if (source1 == null)
            {
                logger.AppendFormat(
                    infoMissingFormatString,
                    descr1, Environment.NewLine);
                return(false);
            }
            if (source2 == null)
            {
                logger.AppendFormat(
                    infoMissingFormatString,
                    descr2, Environment.NewLine);
                return(false);
            }

            bool          ok   = true;
            StringBuilder dump = specifyToken ?
                                 new StringBuilder(string.Format("Source information is different for Recording with token '{0}'{1}", itemToken, Environment.NewLine)) :
                                 new StringBuilder(string.Format("Source information is different {0}", Environment.NewLine));

            Action <string, Func <RecordingSourceInformation, string> > checkStringAction =
                new Action <string, Func <RecordingSourceInformation, string> >((name, fieldSelector) =>
            {
                string value1 = fieldSelector(source1);
                string value2 = fieldSelector(source2);
                if (value1 != value2)
                {
                    ok = false;
                    dump.AppendFormat("   {0} field is different ('{1}' when got via {2}, '{3}' when got via {4}){5}",
                                      name, value1, descr1, value2, descr2, Environment.NewLine);
                }
            });

            checkStringAction("Address", S => S.Address);
            checkStringAction("Description", S => S.Description);
            checkStringAction("Location", S => S.Location);
            checkStringAction("Name", S => S.Name);
            checkStringAction("SourceId", S => S.SourceId);

            if (!ok)
            {
                logger.Append(dump.ToString());
            }

            return(ok);
        }
Esempio n. 5
0
        public static bool CompareConfigurations(RecordingConfiguration configuration1,
                                                 RecordingConfiguration configuration2, StringBuilder dump, string descr1, string descr2)
        {
            bool equal = true;
            bool local;

            if (configuration1.Content != configuration2.Content)
            {
                equal = false;
                dump.AppendFormat("Content field is different: '{0}' in {1}, '{2}' in {3}{4}",
                                  configuration1.Content, descr1, configuration2.Content, descr2, Environment.NewLine);
            }

            // convert configuration1.MaximumRetentionTime
            var MaxRetTime1 = new TimeSpan();

            try
            {
                MaxRetTime1 = System.Xml.XmlConvert.ToTimeSpan(configuration1.MaximumRetentionTime);
            }
            catch (Exception e)
            {
                dump.AppendFormat("Invalid format for Maximum Retention Time: {0} {1}", e.Message, Environment.NewLine);
                equal = false;

                return(equal);
            }

            // convert configuration2.MaximumRetentionTime
            var MaxRetTime2 = new TimeSpan();

            try
            {
                MaxRetTime2 = System.Xml.XmlConvert.ToTimeSpan(configuration2.MaximumRetentionTime);
            }
            catch (Exception e)
            {
                dump.AppendFormat("Invalid format for Maximum Retention Time: {0} {1}", e.Message, Environment.NewLine);
                equal = false;

                return(equal);
            }

            // compare  them
            if (MaxRetTime1 != MaxRetTime2)
            {
                equal = false;
                dump.AppendFormat("MaximumRetentionTime field is different: '{0}' ({1}) in {2}, '{3}' ({4}) in {5}{6}",
                                  configuration1.MaximumRetentionTime, MaxRetTime1.ToString(), descr1,
                                  configuration2.MaximumRetentionTime, MaxRetTime2.ToString(), descr2,
                                  Environment.NewLine);
            }

            RecordingSourceInformation source1 = configuration1.Source;
            RecordingSourceInformation source2 = configuration2.Source;

            local = StorageTestsUtils.CompareSourceInformation(source1, source2, descr1, descr2, null, dump);

            equal = equal && local;


            return(equal);
        }