Exemplo n.º 1
0
        public void TestTheThing()
        {
            var getRequest = new GetRequestBuilder()
                             .WithResultsPerPage(10);

            var client = new CatClient();
            var images = client.GetImages(getRequest);
        }
Exemplo n.º 2
0
        internal Context GetContext()
        {
            if (CatClient.IsInitialized())
            {
                Context ctx = _mContext.Value;

                if (ctx != null)
                {
                    return(ctx);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public ITransaction AddChild(IMessage message)
        {
            if (_mChildren == null)
            {
                _mChildren = new List <IMessage>();
            }

            if (message != null)
            {
                _mChildren.Add(message);
            }
            else
            {
                CatClient.LogError(new Exception("null child message"));
            }
            return(this);
        }
Exemplo n.º 4
0
        public DefaultForkedTransaction(string type, string name, IMessageManager messageManager)
            : base(type, name, messageManager)
        {
            Standalone = false;

            IMessageTree tree = messageManager.ThreadLocalMessageTree;

            if (tree != null)
            {
                _rootMessageId   = tree.RootMessageId;
                _parentMessageId = tree.MessageId;

                // Detach parent transaction and this forked transaction, by calling linkAsRunAway(), at this earliest moment,
                // so that thread synchronization is not needed at all between them in the future.
                _forkedMessageId = CatClient.CreateMessageId();
            }
        }
        public void WhenVoteResponseIsReturned_Then_ItIsDeserialisedCorrectly()
        {
            // Arrange
            var httpResponseMessage = new HttpResponseMessage
            {
                Content = new StringContent(ExampleXmlResponses.VoteResponse)
            };

            // Act
            var response = CatClient.ReadResult <VoteResponse.Response>(httpResponseMessage);
            var votes    = response.Data.Votes;
            var vote     = votes[0];

            // Assert
            Assert.AreEqual(1, votes.Length);
            Assert.AreEqual("update", vote.Action);
            Assert.AreEqual("bC24", vote.ImageId);
            Assert.AreEqual(10, vote.Score);
            Assert.AreEqual("12345", vote.SubId);
        }
        public void WhenGetResponseIsReturned_Then_ItIsDeserialisedCorrectly()
        {
            // Arrange
            var httpResponseMessage = new HttpResponseMessage
            {
                Content = new StringContent(ExampleXmlResponses.GetResponse)
            };

            // Act
            var response = CatClient.ReadResult <GetResponse.Response>(httpResponseMessage);
            var images   = response.Data.Images;

            // Assert
            var urls = new[]
            {
                "http://24.media.tumblr.com/tumblr_m0mkozpcIf1r6b7kmo1_500.jpg",
                "http://24.media.tumblr.com/tumblr_lvlidr8oHo1qzkl9go1_1280.jpg"
            };

            var ids = new[]
            {
                "78b",
                "d2h"
            };

            var sourceUrls = new[]
            {
                "http://thecatapi.com/?id=78b",
                "http://thecatapi.com/?id=d2h"
            };


            Assert.AreEqual(2, images.Length);

            for (var imageIndex = 0; imageIndex < 2; imageIndex++)
            {
                Assert.AreEqual(urls[imageIndex], images[imageIndex].Url);
                Assert.AreEqual(ids[imageIndex], images[imageIndex].Id);
                Assert.AreEqual(sourceUrls[imageIndex], images[imageIndex].SourceUrl);
            }
        }
        public void WhenGetVotesResponseIsReturned_Then_ItIsDeserialisedCorrectly()
        {
            // Arrange
            var httpResponseMessage = new HttpResponseMessage()
            {
                Content = new StringContent(ExampleXmlResponses.GetVotesResponse)
            };

            // Act
            var response = CatClient.ReadResult <GetVotesResponse.Response>(httpResponseMessage);
            var images   = response.Data.Images;

            // Assert
            var subIds = new[]
            {
                "12345",
                "12346"
            };

            var created = new[]
            {
                "2017-05-27 08:23:11",
                "2017-05-27 08:23:18",
            };

            var scores = new[]
            {
                10,
                8
            };

            for (var imageIndex = 0; imageIndex < 2; imageIndex++)
            {
                var actualImage = images[imageIndex];
                Assert.AreEqual(subIds[imageIndex], actualImage.SubId);
                Assert.AreEqual(created[imageIndex], actualImage.Created);
                Assert.AreEqual(scores[imageIndex], images[imageIndex].Score);
            }
        }
Exemplo n.º 8
0
        public void Run(object o)
        {
            while (true)
            {
                if (_nodeInfo == null || !_nodeInfo.HaveAcessRight)
                {
                    Thread.Sleep(60000);
                    break;
                }
                _nodeInfo.Refresh();
                ITransaction t   = CatClient.GetProducer().NewTransaction("System", "Status");
                var          xml = XmlHelper.XmlSerialize(_nodeInfo, Encoding.UTF8);

                //Logger.Info(xml);

                CatClient.GetProducer().LogHeartbeat("Heartbeat", AppEnv.IP, PureCatConstants.SUCCESS, xml);
                t.Complete();

                CatClient.GetProducer().LogEvent("System", "Version", PureCatConstants.SUCCESS, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());

                Thread.Sleep(60000);
            }
        }