public static void ShouldBeEqual <T>(this T actual, T expected)
        {
            var compare = new KellermanSoftware.CompareNetObjects.CompareLogic();
            var result  = compare.Compare(actual, expected);

            result.Differences.ShouldBeEmpty();
        }
Example #2
0
        public void ExceptionTelemetryDeepCloneCopiesAllProperties()
        {
            var telemetry = CreateExceptionTelemetry(CreateExceptionWithStackTrace());
            var other     = telemetry.DeepClone();

            CompareLogic deepComparator = new CompareLogic();

            var result = deepComparator.Compare(telemetry, other);

            Assert.IsTrue(result.AreEqual, result.DifferencesString);
        }
Example #3
0
        /// <summary>
        /// Asserts that two objects are equal.
        /// Uses reflection to compare members.
        /// No Equals override required.
        /// </summary>
        /// <typeparam name="T">Objects type.</typeparam>
        /// <param name="expected">The expected.</param>
        /// <param name="actual">The actual.</param>
        /// <exception cref="XunitException"></exception>
        /// <remarks>
        /// This comparison method should not be used in production code,
        /// because of the performance hit caused by reflection.
        /// </remarks>
        /// <remarks>
        /// Depends on Compare-Net-Objects.
        /// See https://github.com/GregFinzer/Compare-Net-Objects
        /// </remarks>
        public static void Equal <T>(T expected, T actual)
        {
            var compareLogic = new KellermanSoftware.CompareNetObjects.CompareLogic();
            var result       = compareLogic.Compare(expected, actual);

            if (result.AreEqual)
            {
                return;
            }
            throw new XunitException(result.DifferencesString);
        }
Example #4
0
        public void EventTelemetryDeepCloneCopiesAllProperties()
        {
            var eventTelemetry = new EventTelemetry();

            eventTelemetry.Name = "Test Event";
            eventTelemetry.Properties["Test Property"] = "Test Value";
            eventTelemetry.Metrics["Test Property"]    = 4.2;
            EventTelemetry other = (EventTelemetry)eventTelemetry.DeepClone();

            CompareLogic deepComparator = new CompareLogic();

            var result = deepComparator.Compare(eventTelemetry, other);

            Assert.IsTrue(result.AreEqual, result.DifferencesString);
        }
        public void PerformanceCounterTelemetryDeepCloneCopiesAllProperties()
        {
            PerformanceCounterTelemetry item = new PerformanceCounterTelemetry("someCategory", "someCounter", "an instance", 15.7);

            item.Timestamp = DateTimeOffset.Now;
            item.Properties.Add("p1", "p1Val");

            PerformanceCounterTelemetry other = (PerformanceCounterTelemetry)item.DeepClone();

            CompareLogic deepComparator = new CompareLogic();

            var result = deepComparator.Compare(item, other);

            Assert.IsTrue(result.AreEqual, result.DifferencesString);
        }
Example #6
0
        //~ func TestCopy_response(t *testing.T) {
        public void TestCopy_response()
        {
            // Make a non-pointer one so that it can't be modified directly
            //~ expected := logical.Response{
            //~     Data: map[string]interface{}{
            //~         "foo": "bar",
            //~     },
            //~     WrapInfo: &logical.ResponseWrapInfo{
            //~         TTL:             60,
            //~         Token:           "foo",
            //~         CreationTime:    time.Now(),
            //~         WrappedAccessor: "abcd1234",
            //~     },
            //~ }
            //~ arg := expected
            var expected = new Logical.Response
            {
                Data = new Dictionary <string, object>
                {
                    ["foo"] = "bar"
                },
                WrapInfo = new Logical.ResponseWrapInfo
                {
                    TTL             = TimeSpan.FromSeconds(60),
                    Token           = "foo",
                    CreationTime    = DateTime.Now,
                    WrappedAccessor = "abcd1234",
                },
            };
            var arg = expected;

            // Copy it
            //~ dup, err := copystructure.Copy(&arg)
            //~ if err != nil {
            //~     t.Fatalf("err: %s", err)
            //~ }
            var dup = arg.DeepCopy();

            // Check equality
            //~ arg2 := dup.(*logical.Response)
            //~ if !reflect.DeepEqual(*arg2, expected) {
            //~     t.Fatalf("bad:\n\n%#v\n\n%#v", *arg2, expected)
            //~ }
            var arg2    = dup as Logical.Response;
            var compare = new KellermanSoftware.CompareNetObjects.CompareLogic();

            Assert.IsTrue(compare.Compare(expected, arg2).AreEqual);
        }
        public void PageViewTelemetryDeepCloneCopiesAllProperties()
        {
            var pageView = new PageViewTelemetry("My Page");

            pageView.Url      = new Uri("http://temp.org/page1");
            pageView.Duration = TimeSpan.FromSeconds(123);
            pageView.Metrics.Add("Metric1", 30);
            pageView.Properties.Add("Property1", "Value1");
            pageView.Extension = new MyTestExtension();
            PageViewTelemetry other = (PageViewTelemetry)pageView.DeepClone();

            CompareLogic deepComparator = new CompareLogic();
            var          result         = deepComparator.Compare(pageView, other);

            Assert.IsTrue(result.AreEqual, result.DifferencesString);
        }
        public void TraceTelemetryDeepCloneCopiesAllProperties()
        {
            var trace = new TraceTelemetry();

            trace.Message = "My Test";
            trace.Properties.Add("Property2", "Value2");
            trace.SeverityLevel = SeverityLevel.Warning;
            trace.Sequence      = "123456";
            trace.Timestamp     = DateTimeOffset.Now;
            var other = trace.DeepClone();

            var deepComparator = new CompareLogic();
            var result         = deepComparator.Compare(trace, other);

            Assert.IsTrue(result.AreEqual, result.DifferencesString);
        }
Example #9
0
 public async Task WriteHistory(LeaveAllocation oldAllocation, LeaveAllocation newAllocation)
 {
     await Task.Factory.StartNew(() => {
         KellermanSoftware.CompareNetObjects.CompareLogic compareLogic = new KellermanSoftware.CompareNetObjects.CompareLogic {
             Config = new KellermanSoftware.CompareNetObjects.ComparisonConfig()
             {
                 ComparePrivateFields     = false,
                 ComparePrivateProperties = false,
                 TypesToInclude           = new List <Type> {
                     typeof(LeaveAllocation)
                 }
             }
         };
         var compareResult = compareLogic.Compare(oldAllocation, newAllocation);
         _Logger.LogInformation(_Localizer["Edition of leaving id"],
                                compareResult.DifferencesString);
     });
 }
        public void MetricTelemetryDeepCloneCopiesAllProperties()
        {
            var metric = new MetricTelemetry();

            metric.Name = "My Page";
#pragma warning disable CS0618
            metric.Value = 42;
#pragma warning restore CS0618
            metric.Count             = 5;
            metric.Min               = 1.2;
            metric.Max               = 6.4;
            metric.StandardDeviation = 0.5;
            metric.Properties.Add("Property1", "Value1");

            MetricTelemetry other = (MetricTelemetry)metric.DeepClone();

            CompareLogic deepComparator   = new CompareLogic();
            var          comparisonResult = deepComparator.Compare(metric, other);
            Assert.IsTrue(comparisonResult.AreEqual, comparisonResult.DifferencesString);
        }
Example #11
0
        //~ func TestCopy_auth(t *testing.T) {
        public void TestCopy_auth()
        {
            // Make a non-pointer one so that it can't be modified directly
            //~ expected := logical.Auth{
            //~     LeaseOptions: logical.LeaseOptions{
            //~         TTL:       1 * time.Hour,
            //~         IssueTime: time.Now(),
            //~     },
            //~
            //~     ClientToken: "foo",
            //~ }
            //~ auth := expected
            var expected = new Logical.Auth
            {
                TTL         = TimeSpan.FromHours(1),
                IssueTime   = DateTime.Now,
                ClientToken = "foo",
            };
            var auth = expected;

            // Copy it
            //~ dup, err := copystructure.Copy(&auth)
            //~ if err != nil {
            //~     t.Fatalf("err: %s", err)
            //~ }
            var dup = auth.DeepCopy();

            // Check equality
            //~ auth2 := dup.(*logical.Auth)
            //~ if !reflect.DeepEqual(*auth2, expected) {
            //~     t.Fatalf("bad:\n\n%#v\n\n%#v", *auth2, expected)
            //~ }
            var auth2   = dup as Logical.Auth;
            var compare = new KellermanSoftware.CompareNetObjects.CompareLogic();

            Assert.IsTrue(compare.Compare(auth2, expected).AreEqual);
        }