public void serialize_for_SentenceFixture() { var library = TestingContext.Library; Debug.WriteLine(JsonSerialization.ToIndentedJson(library.Models["Sentence"])); }
public void SetUp() { settings = JsonSerialization.GetDefaultSerializerSettings(); settings.Formatting = Formatting.None; }
public static void DeserializeNullableCollection(BufferedTextReader sr, int nextToken, ICollection <SecureString> res) { JsonSerialization.DeserializeNullableCollection(sr, nextToken, next => Deserialize(sr, next), res); }
private void CreateStreamAnalyticsJob(string nameSuffix, string query, string resourceGroupName, AzurePrepInputs azurePrepIn, EventHubDescription ehInput, EventHubDescription ehOutput) { const string inputName = "DevicesInput"; const string outputName = "output"; string jobName = azurePrepIn.NamePrefix + nameSuffix; string transformationName = jobName + "-tr"; var computeClient = new StreamAnalyticsManagementClient(azurePrepIn.Credentials); var serialization = new JsonSerialization { Type = "JSON", Properties = new JsonSerializationProperties { Encoding = "UTF8" } }; List <Input> jobInputs = new List <Input> { new Input { Name = inputName, Properties = new StreamInputProperties { DataSource = new EventHubStreamInputDataSource { Properties = new EventHubStreamInputDataSourceProperties { EventHubName = ehInput.Path, ServiceBusNamespace = azurePrepIn.SBNamespace, SharedAccessPolicyName = "StreamingAnalytics", SharedAccessPolicyKey = (ehInput.Authorization.First((d) => String.Equals(d.KeyName, "StreamingAnalytics", StringComparison.InvariantCultureIgnoreCase)) as SharedAccessAuthorizationRule).PrimaryKey, } }, Serialization = serialization } } }; List <Output> jobOutputs = new List <Output> { new Output { Name = outputName, Properties = new OutputProperties { DataSource = new EventHubOutputDataSource { Properties = new EventHubOutputDataSourceProperties { EventHubName = ehOutput.Path, ServiceBusNamespace = azurePrepIn.SBNamespace, SharedAccessPolicyName = "StreamingAnalytics", SharedAccessPolicyKey = (ehOutput.Authorization.First((d) => String.Equals(d.KeyName, "StreamingAnalytics", StringComparison.InvariantCultureIgnoreCase)) as SharedAccessAuthorizationRule).PrimaryKey, } }, Serialization = serialization } } }; bool created = true; try { var jobCreateResponse = computeClient.StreamingJobs.CreateOrUpdateAsync( resourceGroupName, new JobCreateOrUpdateParameters { Job = new Job { Name = jobName, Location = azurePrepIn.Location, Properties = new JobProperties { Sku = new Sku { //should be "standart" according to https://msdn.microsoft.com/en-us/library/azure/dn834994.aspx Name = "standard" }, EventsOutOfOrderPolicy = "drop", EventsOutOfOrderMaxDelayInSeconds = 10, Inputs = jobInputs, Outputs = jobOutputs, Transformation = new Transformation { Name = transformationName, Properties = new TransformationProperties { Query = query, StreamingUnits = 1 } } } } } ).Result; } catch (Exception ex) { _ConsoleBuffer.Add("Exception on creation Stream Analytics Job " + jobName + ": " + ex.Message); created = false; } if (created) { _ConsoleBuffer.Add("Stream Analytics job " + jobName + " created."); } }
public static string Deserialize(StreamReader sr, char[] buffer, int nextToken) { if (nextToken != '"') { throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken); } int i = 0; nextToken = sr.Read(); for (; nextToken != '"' && i < buffer.Length; i++, nextToken = sr.Read()) { if (nextToken == '\\') { nextToken = sr.Read(); switch (nextToken) { case (int)'\\': break; case (int)'"': break; case (int)'b': nextToken = '\b'; break; case (int)'t': nextToken = '\t'; break; case (int)'r': nextToken = '\r'; break; case (int)'n': nextToken = '\n'; break; case (int)'u': if (i < buffer.Length - 4) { buffer[i] = (char)sr.Read(); buffer[i + 1] = (char)sr.Read(); buffer[i + 2] = (char)sr.Read(); buffer[i + 3] = (char)sr.Read(); nextToken = Convert.ToInt32(new string(buffer, i, 4), 16); } else { var tmp = new char[4]; tmp[0] = (char)sr.Read(); tmp[1] = (char)sr.Read(); tmp[2] = (char)sr.Read(); tmp[3] = (char)sr.Read(); nextToken = Convert.ToInt32(new string(tmp, 0, 4), 16); } break; default: throw new SerializationException("Invalid char found: " + (char)nextToken); } } buffer[i] = (char)nextToken; } if (i < buffer.Length) { return(new string(buffer, 0, i)); } var sb = new StringBuilder(128); sb.Append(buffer); while (nextToken != '"' && nextToken != -1) { if (nextToken == '\\') { nextToken = sr.Read(); switch (nextToken) { case (int)'\\': break; case (int)'"': break; case (int)'b': nextToken = '\b'; break; case (int)'t': nextToken = '\t'; break; case (int)'r': nextToken = '\r'; break; case (int)'n': nextToken = '\n'; break; case (int)'u': buffer[0] = (char)sr.Read(); buffer[1] = (char)sr.Read(); buffer[2] = (char)sr.Read(); buffer[3] = (char)sr.Read(); nextToken = Convert.ToInt32(new string(buffer, 0, 4), 16); break; default: throw new SerializationException("Invalid char found: " + (char)nextToken); } } sb.Append((char)nextToken); nextToken = sr.Read(); } //if (nextToken == -1) throw new SerializationException("Invalid end of string found."); return(sb.ToString()); }
protected override PropertyData DeserializeFromJson(string data) { return(JsonSerialization.DeserializeJson <FileProperty>(data)); }
public override Test2Source FromEntry(TextEntry entry) => JsonSerialization.Deserialized <Test2Source>(entry.EntryData);
public static IRedditAccessToken Create(Stream stream) { return(JsonSerialization.FromStream <RedditAccessToken>(stream)); }
public Task <List <XboxUserProfile> > GetUserProfilesAsync(List <string> xboxUserIds) { if (xboxUserIds == null) { throw new ArgumentNullException("xboxUserIds"); } if (xboxUserIds.Count == 0) { throw new ArgumentOutOfRangeException("xboxUserIds", "Empty list of user ids"); } if (XboxLiveContext.UseMockServices) { Random rand = new Random(); List <XboxUserProfile> outputUsers = new List <XboxUserProfile>(xboxUserIds.Count); foreach (string xuid in xboxUserIds) { // generate a fake dev gamertag string gamertag = "2 dev " + rand.Next(10000); XboxUserProfile profile = new XboxUserProfile() { XboxUserId = xuid, ApplicationDisplayName = gamertag, ApplicationDisplayPictureResizeUri = new Uri("http://images-eds.xboxlive.com/image?url=z951ykn43p4FqWbbFvR2Ec.8vbDhj8G2Xe7JngaTToBrrCmIEEXHC9UNrdJ6P7KI4AAOijCgOA3.jozKovAH98vieJP1ResWJCw2dp82QtambLRqzQbSIiqrCug0AvP4&format=png"), GameDisplayName = gamertag, GameDisplayPictureResizeUri = new Uri("http://images-eds.xboxlive.com/image?url=z951ykn43p4FqWbbFvR2Ec.8vbDhj8G2Xe7JngaTToBrrCmIEEXHC9UNrdJ6P7KI4AAOijCgOA3.jozKovAH98vieJP1ResWJCw2dp82QtambLRqzQbSIiqrCug0AvP4&format=png"), Gamerscore = rand.Next(250000).ToString(), Gamertag = gamertag }; outputUsers.Add(profile); } return(Task.FromResult(outputUsers)); } else { string endpoint = XboxLiveEndpoint.GetEndpointForService("profile", this.config); XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(this.settings, "POST", endpoint, "/users/batch/profile/settings"); req.ContractVersion = "2"; req.ContentType = "application/json; charset=utf-8"; Models.ProfileSettingsRequest reqBodyObject = new Models.ProfileSettingsRequest(xboxUserIds, true); req.RequestBody = JsonSerialization.ToJson(reqBodyObject); return(req.GetResponseWithAuth(this.context.User, HttpCallResponseBodyType.JsonBody).ContinueWith(task => { XboxLiveHttpResponse response = task.Result; Models.ProfileSettingsResponse responseBody = new Models.ProfileSettingsResponse(); responseBody = JsonSerialization.FromJson <Models.ProfileSettingsResponse>(response.ResponseBodyString); List <XboxUserProfile> outputUsers = new List <XboxUserProfile>(); foreach (Models.ProfileUser entry in responseBody.profileUsers) { XboxUserProfile profile = new XboxUserProfile() { XboxUserId = entry.id, Gamertag = entry.Gamertag(), GameDisplayName = entry.GameDisplayName(), GameDisplayPictureResizeUri = new Uri(entry.GameDisplayPic()), ApplicationDisplayName = entry.AppDisplayName(), ApplicationDisplayPictureResizeUri = new Uri(entry.AppDisplayPic()), Gamerscore = entry.Gamerscore() }; outputUsers.Add(profile); } return outputUsers; })); } }
public string ToBase64() { return(JsonSerialization.ToBase64(this)); }
public static IRedditAccessToken Create(string base64) { return(JsonSerialization.FromBase64 <RedditAccessToken>(base64)); }
public void DeleteIncumbent_ValidTBASRequest_DeletesTBASIncumbentSuccesfully() { IRequestParameters addIncumbentRequestParams = this.AddIncumbentRequestParamsForTBASDeviceType(); this.whitespacesDataClient.AddIncumbent(addIncumbentRequestParams); IRequestParameters getIncumbentRequestParams = this.GetIncumbentRequestParams("TBAS"); var getIncumbentsResponse = this.whitespacesDataClient.GetIncumbents(getIncumbentRequestParams); var tempBasCollection = getIncumbentsResponse.IncumbentList.Select(obj => JsonSerialization.DeserializeString <TempBASRegistration>(obj.ToString())).ToList(); ////Delete MVPD Incumbents ////Get RegistrationId of the added incumbent var requiredTempBas = tempBasCollection.Where(x => x.TxLatitude == addIncumbentRequestParams.Params.TransmitLocation.Latitude && x.TxLongitude == addIncumbentRequestParams.Params.TransmitLocation.Longitude).FirstOrDefault(); IRequestParameters deleteIncumbentRequestParams = this.GetRequestParams( req => { req.RegionName = "United States"; req.Params = new Parameters { IncumbentType = "TBAS", RegistrationDisposition = new RegistrationDisposition { RegId = requiredTempBas.Disposition.RegId } }; }); var actualResponse = this.whitespacesDataClient.DeleteIncumbent(deleteIncumbentRequestParams); Assert.AreEqual("Incumbent deleted successfully.", actualResponse.Message); }
public void DeleteIncumbent_ValidUnlicensedLPAuxRequest_DeletesUnlicensedLPAuxIncumbentSuccesfully() { IRequestParameters addIncumbentRequestParams = this.AddIncumbentRequestParamsForUnlicensedLPAuxDeviceType(); this.whitespacesDataClient.AddIncumbent(addIncumbentRequestParams); IRequestParameters getIncumbentRequestParams = this.GetIncumbentRequestParams("UnlicensedLPAux"); var getIncumbentsResponse = this.whitespacesDataClient.GetIncumbents(getIncumbentRequestParams); var unlicensedLowPowerAuxs = getIncumbentsResponse.IncumbentList.Select(obj => JsonSerialization.DeserializeString <LPAuxRegistration>(obj.ToString())).ToList(); ////Delete MVPD Incumbents ////Get RegistrationId of the added incumbent var requiredUunlicensedLpAux = unlicensedLowPowerAuxs.Where(x => x.PointsArea[0].Latitude.ToString() == addIncumbentRequestParams.Params.PointsArea[0].Latitude && x.PointsArea[0].Longitude.ToString() == addIncumbentRequestParams.Params.PointsArea[0].Longitude).FirstOrDefault(); IRequestParameters deleteIncumbentRequestParams = this.GetRequestParams( req => { req.RegionName = "United States"; req.Params = new Parameters { IncumbentType = "UnlicensedLPAux", RegistrationDisposition = new RegistrationDisposition { RegId = requiredUunlicensedLpAux.Disposition.RegId } }; }); var actualResponse = this.whitespacesDataClient.DeleteIncumbent(deleteIncumbentRequestParams); Assert.AreEqual("Incumbent deleted successfully.", actualResponse.Message); }
protected static T Clone(T resource) { if (ReferenceEquals(resource, null)) { return(default(T)); } return(JsonConvert.DeserializeObject <T>(JsonConvert.SerializeObject(resource), JsonSerialization.GetDefaultSerializerSettings())); }
internal override string Serialize() { return(JsonSerialization.SerializeTypedJson(this)); }
public static void AddCopyValue <TValue>(this GenericMenu menu, TValue value) { menu.AddItem(new GUIContent($"{k_CopyPrefix}All"), false, () => { EditorGUIUtility.systemCopyBuffer = JsonSerialization.ToJson(value); }); menu.AddSeparator(k_CopyPrefix); var visitor = new GenericMenuCopyVisitor(menu); PropertyContainer.Visit(value, visitor); }
public override TextEntry ToEntry(TState source, string id, Metadata metadata) { var serialization = JsonSerialization.Serialized(source); return(new TextEntry(id, source.GetType(), 1, serialization, metadata)); }
public static void AddCopyValue <TValue>(this DropdownMenu menu, TValue value) { menu.AppendAction($"{k_CopyPrefix}All", action => { EditorGUIUtility.systemCopyBuffer = JsonSerialization.ToJson(value); }); menu.AppendSeparator(k_CopyPrefix); var visitor = new DropdownMenuCopyVisitor(menu); PropertyContainer.Visit(value, visitor); }
public void SendRemotely <T>(T message) { string json = JsonSerialization.ToJson(message); _proxy.SendJson(json); }
public void ToStringTest() { var data = JsonSerialization.ToString(DataGenerator.GetPrice()); Assert.IsTrue(!string.IsNullOrEmpty(data)); }
public override TextEntry ToEntry(Test2Source source, string id, Metadata metadata) { var serialization = JsonSerialization.Serialized(source); return(new TextEntry(id, typeof(Test2Source), 1, serialization, metadata)); }
public static DateTime DeserializeTimestamp(BufferedTextReader sr, int nextToken) { if (nextToken != '"') { throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken); } int i = 0; var buffer = sr.SmallBuffer; nextToken = sr.Read(); for (; i < buffer.Length && nextToken != '"'; i++, nextToken = sr.Read()) { buffer[i] = (char)nextToken; } try { if (i > 0 && buffer[i - 1] == 'Z') { if (i > 18 && i < 29 && buffer[4] == '-' && buffer[7] == '-' && (buffer[10] == 'T' || buffer[10] == 't' || buffer[10] == ' ') && buffer[13] == ':' && buffer[16] == ':' && AllDigits(buffer, 20, i - 1)) { var year = 1000 * (buffer[0] - '0') + 100 * (buffer[1] - '0') + 10 * (buffer[2] - '0') + buffer[3] - '0'; var month = 10 * (buffer[5] - '0') + buffer[6] - '0'; var day = 10 * (buffer[8] - '0') + buffer[9] - '0'; var hour = 10 * (buffer[11] - '0') + buffer[12] - '0'; var min = 10 * (buffer[14] - '0') + buffer[15] - '0'; var sec = 10 * (buffer[17] - '0') + buffer[18] - '0'; if (buffer[19] == '.') { int nanos; switch (i) { case 22: nanos = 1000000 * (buffer[20] - 48); break; case 23: nanos = 1000000 * (buffer[20] - 48) + 100000 * (buffer[21] - 48); break; case 24: nanos = 1000000 * (buffer[20] - 48) + 100000 * (buffer[21] - 48) + 10000 * (buffer[22] - 48); break; case 25: nanos = 1000000 * (buffer[20] - 48) + 100000 * (buffer[21] - 48) + 10000 * (buffer[22] - 48) + 1000 * (buffer[23] - 48); break; case 26: nanos = 1000000 * (buffer[20] - 48) + 100000 * (buffer[21] - 48) + 10000 * (buffer[22] - 48) + 1000 * (buffer[23] - 48) + 100 * (buffer[24] - 48); break; case 27: nanos = 1000000 * (buffer[20] - 48) + 100000 * (buffer[21] - 48) + 10000 * (buffer[22] - 48) + 1000 * (buffer[23] - 48) + 100 * (buffer[24] - 48) + 10 * (buffer[25] - 48); break; default: nanos = 1000000 * (buffer[20] - 48) + 100000 * (buffer[21] - 48) + 10000 * (buffer[22] - 48) + 1000 * (buffer[23] - 48) + 100 * (buffer[24] - 48) + 10 * (buffer[25] - 48) + buffer[26] - 48; break; } return(new DateTime(year, month, day, hour, min, sec, DateTimeKind.Utc).AddTicks(nanos)); } return(new DateTime(year, month, day, hour, min, sec, DateTimeKind.Utc)); } return(DateTime.Parse(new string(buffer, 0, i), Invariant, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)); } return(DateTime.Parse(new string(buffer, 0, i), Invariant)); } catch (Exception ex) { throw new SerializationException("Error parsing timestamp at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex); } }
/// <summary> /// Initializes a new instance of the <see cref="JsonNetSerializer"/> class. /// </summary> public JsonNetSerializer() { this.serializer = JsonSerializer.CreateDefault(JsonSerialization.GetDefaultSerializerSettings()); }
public static void DeserializeOffsetNullableCollection(BufferedTextReader sr, int nextToken, ICollection <DateTimeOffset?> res) { if (nextToken == 'n') { if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l') { res.Add(null); } else { throw new SerializationException("Invalid value found at position " + JsonSerialization.PositionInStream(sr) + " for DateTime value. Expecting timestamp or null"); } } else { res.Add(DeserializeOffset(sr, nextToken)); } while ((nextToken = JsonSerialization.GetNextToken(sr)) == ',') { nextToken = JsonSerialization.GetNextToken(sr); if (nextToken == 'n') { if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l') { res.Add(null); } else { throw new SerializationException("Invalid value found at position " + JsonSerialization.PositionInStream(sr) + " for DateTime value. Expecting timestamp or null"); } } else { res.Add(DeserializeOffset(sr, nextToken)); } } if (nextToken != ']') { if (nextToken == -1) { throw new SerializationException("Unexpected end of json in collection."); } else { throw new SerializationException("Expecting ']' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken); } } }
public static List <string> DeserializeCollection(StreamReader sr, char[] buffer, int nextToken) { var res = new List <string>(); if (nextToken == 'n') { if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l') { res.Add(null); } else { throw new SerializationException("Invalid value found at position " + JsonSerialization.PositionInStream(sr) + " for string value. Expecting '\"' or null"); } } else { res.Add(Deserialize(sr, buffer, nextToken)); } while ((nextToken = JsonSerialization.GetNextToken(sr)) == ',') { nextToken = JsonSerialization.GetNextToken(sr); if (nextToken == 'n') { if (sr.Read() == 'u' && sr.Read() == 'l' && sr.Read() == 'l') { res.Add(null); } else { throw new SerializationException("Invalid value found at position " + JsonSerialization.PositionInStream(sr) + " for string value. Expecting '\"' or null"); } } else { res.Add(Deserialize(sr, buffer, nextToken)); } } if (nextToken != ']') { if (nextToken == -1) { throw new SerializationException("Unexpected end of json in collection."); } else { throw new SerializationException("Expecting ']' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken); } } return(res); }
/// <summary> /// Upload blob data to title storage. /// </summary> /// <param name="user">The Xbox User of the title storage to enumerate. Ignored when enumerating GlobalStorage.</param> /// <param name="blobMetadata">The blob metadata for the title storage blob to upload.</param> /// <param name="blobBuffer">The Blob content to be uploaded.</param> /// <param name="blobQueryProperties">An instance of the <see cref="BlobQueryProperties"/> class with properties of the upload query.</param> /// <returns>An instance of the <see cref="TitleStorageBlobMetadata"/> class with updated ETag and Length Properties.</returns> public Task <TitleStorageBlobMetadata> UploadBlobAsync(XboxLiveUser user, TitleStorageBlobMetadata blobMetadata, List <byte> blobBuffer, BlobQueryProperties blobQueryProperties) { if (blobBuffer == null) { throw new Exception("Blob buffer is null"); } if (blobBuffer.Count == 0) { throw new Exception("Blob Buffer is empty"); } var preferredUploadBlockSize = blobQueryProperties.PreferredBlockSize < MinUploadBlockSize ? MinUploadBlockSize : blobQueryProperties.PreferredBlockSize; preferredUploadBlockSize = blobQueryProperties.PreferredBlockSize > MaxUploadBlockSize ? MaxUploadBlockSize : preferredUploadBlockSize; var resultBlocBlobMetadata = new TitleStorageBlobMetadata(blobMetadata.StorageType, blobMetadata.BlobPath, blobMetadata.BlobType, blobMetadata.DisplayName, blobMetadata.ETag); var isBinaryData = (blobMetadata.BlobType == TitleStorageBlobType.Binary); var dataChunk = new List <byte>(); uint start = 0; var continuationToken = string.Empty; while (start < blobBuffer.Count) { dataChunk.Clear(); bool isFinalBlock; if (isBinaryData) { var count = (uint)(blobBuffer.Count) - start; if (count > preferredUploadBlockSize) { count = preferredUploadBlockSize; } for (var index = 0; index < count; index++) { dataChunk.Add(blobBuffer[(int)(index + start)]); } start += count; isFinalBlock = start == blobBuffer.Count; } else { dataChunk = blobBuffer; start = (uint)(dataChunk.Count); isFinalBlock = true; } var subpathAndQueryResult = this.GetTitleStorageBlobMetadataUploadSubpath(user, blobMetadata, continuationToken, isFinalBlock); var httpRequest = XboxLiveHttpRequest.Create(HttpMethod.Put, TitleStorageBaseUri.ToString(), subpathAndQueryResult); httpRequest.ContractVersion = TitleStorageApiContract; httpRequest.ContentType = ContentTypeHeaderValue; httpRequest.longHttpCall = true; SetEtagHeader(httpRequest, blobMetadata.ETag, blobQueryProperties.ETagMatchCondition); var encoding = Encoding.UTF8; httpRequest.RequestBody = encoding.GetString(dataChunk.ToArray()); var localIsFinalBlock = isFinalBlock; httpRequest.GetResponseWithAuth(user).ContinueWith(responseTask => { var json = responseTask.Result.ResponseBodyString; continuationToken = string.Empty; if (responseTask.Result.ErrorCode == 0 && !string.IsNullOrEmpty(json)) { var pagingInfo = JsonSerialization.FromJson <PagingInfo>(json); continuationToken = pagingInfo.ContinuationToken; } if (responseTask.Result.ErrorCode == 0 && localIsFinalBlock) { resultBlocBlobMetadata.SetBlobMetadataProperties((uint)(blobBuffer.Count), responseTask.Result.ETag); } }).Wait(); } return(Task.FromResult(resultBlocBlobMetadata)); }
public static List <SecureString> DeserializeNullableCollection(BufferedTextReader sr, int nextToken) { return(JsonSerialization.DeserializeNullableCollection(sr, nextToken, next => Deserialize(sr, next))); }
public void ExecuteWithRequestAndMappedParameters() { var request = Request.Has(Method.Get) .And("/posts/my-post/comments/my-comment/users/my-user".ToMatchableUri()) .And(Version.Http1_1); var mappedParameters = new Action.MappedParameters(1, Method.Get, "ignored", new List <Action.MappedParameter> { new Action.MappedParameter("string", "my-post"), new Action.MappedParameter("string", "my-comment"), new Action.MappedParameter("string", "my-user"), }); var handler = CreateRequestHandler( Method.Get, "/posts/{postId}/comment/{commentId}/user/{userId}", ParameterResolver.Path <string>(0), ParameterResolver.Path <string>(1), ParameterResolver.Path <string>(2), ParameterResolver.Query("page", 10), ParameterResolver.Query("pageSize", 10)) .Handle((postId, commentId, userId, page, pageSize) => Completes.WithSuccess(Response.Of(Response.ResponseStatus.Ok, JsonSerialization.Serialized( $"{postId} {commentId} {userId}")))); var response = handler.Execute(request, mappedParameters, Logger).Outcome; AssertResponsesAreEquals(Response.Of(Response.ResponseStatus.Ok, JsonSerialization.Serialized("my-post my-comment my-user")), response); }
public void HandlerWithOneParam() { var handler = CreateRequestHandler( Method.Get, "/posts/{postId}/comment/{commentId}/user/{userId}", ParameterResolver.Path <string>(0), ParameterResolver.Path <string>(1), ParameterResolver.Path <string>(2), ParameterResolver.Query("page", 10), ParameterResolver.Query("pageSize", 10)) .Handle((postId, commentId, userId, page, pageSize) => Completes.WithSuccess(Response.Of(ResponseStatus.Ok, JsonSerialization.Serialized( $"{postId} {commentId}")))); var response = handler .Execute(Request.WithMethod(Method.Get), "my-post", "my-comment", "admin", 10, 10, Logger).Outcome; Assert.NotNull(handler); Assert.Equal(Method.Get, handler.Method); Assert.Equal("/posts/{postId}/comment/{commentId}/user/{userId}", handler.Path); Assert.Equal(typeof(string), handler.ResolverParam1.ParamClass); Assert.Equal(typeof(string), handler.ResolverParam2.ParamClass); Assert.Equal(typeof(string), handler.ResolverParam3.ParamClass); AssertResponsesAreEquals(Response.Of(ResponseStatus.Ok, JsonSerialization.Serialized("my-post my-comment")), response); }
public void serialize_for_CompositeFixture() { var library = TestingContext.Library; Debug.WriteLine(JsonSerialization.ToIndentedJson(library.Models["Composite"].FindGrammar("AddAndMultiply"))); }