コード例 #1
0
ファイル: ExpectEvent.cs プロジェクト: ostat/Beef
        /// <summary>
        /// Verify/compare expected versus sent.
        /// </summary>
        private static void AreSentCompare(List <ExpectedEvent> expectedEvents, string?correlationId, string testText, string expectText, string actualText, string checkText)
        {
            if (expectedEvents == null)
            {
                throw new ArgumentNullException(nameof(expectedEvents));
            }

            var actualEvents = GetSentEvents(correlationId);

            if (actualEvents.Count != expectedEvents.Count)
            {
                Assert.Fail($"{testText} {expectedEvents.Count} Event(s) {checkText} {expectText}; there were {actualEvents.Count} {actualText}.");
            }

            for (int i = 0; i < actualEvents.Count; i++)
            {
                // Assert subject and action.
                var exp = expectedEvents[i].EventData;
                var act = actualEvents[i];

                if (!EventSubjectMatcher.Match(_eventPublisher.TemplateWildcard, _eventPublisher.PathSeparator, exp.Subject, act.Subject))
                {
                    Assert.Fail($"{testText} {expectText} Event[{i}].Subject '{exp.Subject}' is not equal to actual '{act.Subject}' {actualText}.");
                }

                if (!string.IsNullOrEmpty(exp.Action) && string.CompareOrdinal(exp.Action, act.Action) != 0)
                {
                    Assert.Fail($"{testText} {expectText} Event[{i}].Action '{exp.Action}' is not equal to actual '{act.Action}' {actualText}.");
                }

                // Where there is *no* expected value then skip value comparison.
                if (!exp.HasValue)
                {
                    continue;
                }

                // Assert value.
                var eVal = exp.GetValue();
                var aVal = act.GetValue();

                var comparisonConfig = TestSetUp.GetDefaultComparisonConfig();
                comparisonConfig.AttributesToIgnore.AddRange(new Type[] { typeof(ReferenceDataInterfaceAttribute) });

                var type = eVal?.GetType() ?? aVal?.GetType();
                if (type != null)
                {
                    TestSetUp.InferAdditionalMembersToIgnore(comparisonConfig, type);
                }

                var cl = new CompareLogic(comparisonConfig);
                var cr = cl.Compare(eVal, aVal);
                if (!cr.AreEqual)
                {
                    Assert.Fail($"{testText} {expectText} Event[{i}].Value is not equal to actual {actualText}: {cr.DifferencesString}");
                }
            }
        }