Example #1
0
        public string BuildRoot()
        {
            var builder = new RepresentorBuilder();

            // _link
            var rootsUri   = new Uri(_baseUri, RootPrefix);
            var requestUri = new Uri(_baseUri, RequestPrefix);

            builder.SetSelfLink(rootsUri.ToString());
            builder.AddTransition(new CrichtonTransition
            {
                Rel   = "create_request",
                Title = "Create Sumo Log Search Request",
                Uri   = requestUri.OriginalString,
                Type  = GeneralConstants.JsonContentType
            });
            builder.AddTransition(new CrichtonTransition
            {
                Rel            = "request_id",
                Uri            = requestUri + "{?request_uuid}",
                UriIsTemplated = true,
            });

            var representor = builder.ToRepresentor();
            var serializer  = new HalSerializer();

            return(serializer.Serialize(representor));
        }
Example #2
0
        private CrichtonRepresentor CreateRequestRepresentor(Request request)
        {
            var builder = new RepresentorBuilder();

            // attributes
            builder.SetAttributes(new JObject(new List <JProperty>
            {
                new JProperty("request_uuid", request.RequestUuid),
                new JProperty("query", request.Query),
                new JProperty("from", FormatDateTime(request.From)),
                new JProperty("to", FormatDateTime(request.To)),
                new JProperty("success", request.Success),
                new JProperty("status_message", request.StatusMessage),
                new JProperty("request_time", FormatDateTime(request.RequestTime)),
                new JProperty("completed_request_time", FormatDateTime(request.CompletedRequestTime)),
                new JProperty("apps", request.Apps),
                new JProperty("exceptionApps", request.ExceptionApps),
                new JProperty("callback_endpoint", request.CallbackEndpoint ?? string.Empty)
            }));

            // _link
            var requestUri = new Uri(_baseUri, RequestPrefix);

            builder.SetSelfLink(CreateLink(request.RequestUuid.ToString()));
            builder.AddTransition(new CrichtonTransition
            {
                Rel = "logs",
                Uri = CreateLink(request.RequestUuid.ToString()) + "/logs"
            });

            return(builder.ToRepresentor());
        }
        public void AddTransition_AddsCrichtonTransitionObjectOnce()
        {
            var transition = Fixture.Create <CrichtonTransition>();

            sut.AddTransition(transition);
            var result = sut.ToRepresentor();

            Assert.IsNotNull(result.Transitions.SingleOrDefault(t => t == transition));
        }