Inheritance: IResource, IDeepCompare
        public override void SetUp()
        {
            XmlHelper.Instance.ValidateXml = true;
            XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("gnip.log4net.xml"));

            Log.Debug("========== Test setUp() start");
            Log.Debug("Attempting to connect to Gnip at " +  testConfig.Host + " using username " + testConfig.Username);

            config = new Config(testConfig.Username,
                testConfig.Password,
                new System.Uri(testConfig.Host),
                testConfig.RequestTimeout,
                testConfig.ReadWriteTimeout);

            gnipConnection = new GnipConnection(config);
            // Auto sync to the servers time.
            gnipConnection.TimeCorrection = gnipConnection.GetServerTimeDelta();

            string localPublisherId = testConfig.Publisher;
            localPublisher = gnipConnection.GetPublisher(testConfig.PublisherType, localPublisherId);
            if (localPublisher == null)
            {
                throw new AssertionException("No Publisher of type " + testConfig.PublisherType + " found with name " + localPublisherId + ".  Be sure " + "to provide the name of a publisher you own in the test.properties file.");
            }

            activities = new Activities();
            activity1 = new Activity(new Actor("joe"), "update1");
            activities.Items.Add(activity1);
            activity2 = new Activity(new Actor("tom"), "update2");
            activities.Items.Add(activity2);
            activity3 = new Activity(new Actor("jane"), "update3");
            activities.Items.Add(activity3);

            filterToCreate = new Filter("tomFilter");
            filterToCreate.Rules.Add(new Rule(RuleType.Actor, "tom"));

            notificationFilterToCreate = new Filter("janeFilter");
            notificationFilterToCreate.IsFullData = false;
            notificationFilterToCreate.Rules.Add(new Rule(RuleType.Actor, "jane"));

            Log.Debug("Test setUp() end\n");
        }
        public static Activity GetActivity1(int val, DateTime at)
        {
            Activity activity = new Activity();

            activity.At = at;
            activity.Action = "action " + val;
            activity.ActivityId = "activityID " + val;
            activity.Url = "url " + val;
            activity.Sources.Add("sources " + val);
            activity.Keywords.Add("keywords " + val);
            activity.Places.Add(new Place(new double[] { 1.2, 3.4 }));
            activity.Actors.Add(new Actor("Actors.value " + val, "Actors.uid " + val, "Actors.metaUrl " + val));
            activity.DestinationUrls.Add(new GnipUrl("DestinationUrls.value " + val, "DestinationUrls.metaUrl " + val));
            activity.Tags.Add(new GnipValue("Tags.value " + val, "Tags.metaUrl " + val));
            activity.Tos.Add(new GnipValue("Tos.value " + val, "Tos.metaUrl " + val));
            activity.RegardingUrls.Add(new GnipUrl("RegardingUrls.value " + val, "RegardingUrls.metaUrl " + val));
            activity.Payload = new Payload("Payload.title 1", "Payload.body 1", "Payload.raw 1", false);

            return activity;
        }
        public static Activity GetActivity2(int val, DateTime at)
        {
            Activity activity = new Activity();

            activity.At = at;
            activity.Action = "action " + (val + 0);
            activity.ActivityId = "activityID " + (val + 0);
            activity.Url = "url " + (val + 0);
            activity.Sources = new List<string> { "sources " + (val + 0), "sources " + (val + 1) };
            activity.Keywords = new List<string> { "keywords " + (val + 0), "keywords " + (val + 1) };
            activity.Places = new List<Place> { new Place(new double[] { 1.2, 3.4 }), new Place(new double[] { 2.2, 4.4 }) };
            activity.Actors = new List<Actor> {
                new Actor("Actors.value " + (val + 0), "Actors.uid " + (val + 0), "Actors.metaUrl " + (val + 0)),
                new Actor("Actors.value " + (val + 1), "Actors.uid " + (val + 1), "Actors.metaUrl " + (val + 1))
            };
            activity.DestinationUrls = new List<GnipUrl> {
                new GnipUrl("DestinationUrls.value " + (val + 0), "DestinationUrls.metaUrl " + (val + 0)),
                new GnipUrl("DestinationUrls.value " + (val + 1), "DestinationUrls.metaUrl " + (val + 1))
            };
            activity.Tags = new List<GnipValue> {
                new GnipValue("Tags.value " + (val + 0), "Tags.metaUrl " + (val + 0)),
                new GnipValue("Tags.value " + (val + 1), "Tags.metaUrl " + (val + 1))
            };
            activity.Tos = new List<GnipValue> {
                new GnipValue("Tos.value " + (val + 0), "Tos.metaUrl " + (val + 0)),
                new GnipValue("Tos.value " + (val + 1), "Tos.metaUrl " + (val + 1))
            };
            activity.RegardingUrls = new List<GnipUrl> {
                new GnipUrl("RegardingUrls.value " + (val + 0), "RegardingUrls.metaUrl " + (val + 0)),
                new GnipUrl("RegardingUrls.value " + (val + 1), "RegardingUrls.metaUrl " + (val + 1))
            };
            activity.Payload = new Payload(
                "Payload.title " + (val + 0),
                "Payload.body " + (val + 0),
                new List<MediaUrl>() { new MediaUrl("url " + (val + 0), "width " + (val + 0), "height " + (val + 0), "duration " + (val + 0), "mimeType " + (val + 0), "type " + (val + 0)) },
                "Payload.raw " + (val + 0),
                false);

            return activity;
        }
        private void TestDeepEquals(Activity objectA, Activity objectB, bool expect, bool expectDeep)
        {
            objectA.At = objectB.At;

            Assert.AreEqual(expectDeep, objectA.DeepEquals(objectB));
            Assert.AreEqual(expectDeep, objectB.DeepEquals(objectA));
            Assert.AreEqual(expect, objectA.Equals(objectB));
            Assert.AreEqual(expect, objectB.Equals(objectA));
        }
        public void TestActivitySerialize_03()
        {
            DateTime date = new DateTime(2002, 1, 1);

            Activity activity = new Activity(date, "action 1");
            string str = XmlHelper.Instance.ToXmlString<Activity>(activity);
            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<activity xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
                    "<at>2002-01-01T00:00:00</at>" +
                    "<action>action 1</action>" +
                "</activity>"
                , str);
        }
        public void TestActivityDeserialize_02()
        {
            DateTime date = new DateTime(2002, 1, 1);

            Activity activity = new Activity(date, "action 1");

            string str = XmlHelper.Instance.ToXmlString<Activity>(activity);
            Activity des = XmlHelper.Instance.FromXmlString<Activity>(str);
            Assert.IsTrue(activity.DeepEquals(des));
        }
Exemple #7
0
        /// <summary>
        /// Determins if this equals that by performing a deep equals 
        /// looking at all elements of all member listsand objects.
        /// </summary>
        /// <param name="that">The object to compare for equality.</param>
        /// <returns>True if this is equal to that, false otherwise.</returns>
        public bool DeepEquals(Activity that)
        {
            if (this == that)
                return true;
            else if (that == null)
                return false;

            return (this.At == that.At &&
                string.Equals(this.Action, that.Action) &&
                string.Equals(this.ActivityId, that.ActivityId) &&
                string.Equals(this.Url, that.Url) &&
                ListUtils.AreEqual<string>(this.Sources, that.Sources) &&
                ListUtils.AreEqual<string>(this.Keywords, that.Keywords) &&
                ListUtils.AreDeepEqual<Place>(this.Places, that.Places) &&
                ListUtils.AreDeepEqual<Actor>(this.Actors, that.Actors) &&
                ListUtils.AreDeepEqual<GnipUrl>(this.DestinationUrls, that.DestinationUrls) &&
                ListUtils.AreDeepEqual<GnipValue>(this.Tags, that.Tags) &&
                ListUtils.AreDeepEqual<GnipValue>(this.Tos, that.Tos) &&
                ListUtils.AreDeepEqual<GnipUrl>(this.RegardingUrls, that.RegardingUrls) &&
                ObjectUtils.AreDeepEqual(this.Payload, that.Payload));
        }