Thursday, January 28, 2016

Compare objects with JSON

using System;
using System.Net;
using HA.Web.Analytics.Providers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sitecore.Analytics.Lookups;
using Sitecore.Diagnostics;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using System.Web.Script.Serialization; (from System.Web.Extension dll)

[TestClass]
    public class GeoIpLookupProviderTests

    {

[TestMethod]
        public void GetInformationByIp_ReturnsTrue()
        {
            try
            {
                var p = new GeoIp2LookupProvider();
                WhoIsInformation blank = new WhoIsInformation();
                var result = p.GetInformationByIp(null);

                var serializer = new JavaScriptSerializer();
                var blankJson = serializer.Serialize(blank);
                var resultJson = serializer.Serialize(result);

                Assert.AreEqual(blankJson, resultJson);
            }
            catch (Exception ex)
            {
                Log.Error("Could not get GeoIP information", ex, this);
                throw;
            }

        }

No comments:

Post a Comment