public virtual bool SerializeHeader(ResourceSerializer serializer) { return serializer.SerializeWORD(ref wLength) && serializer.SerializeWORD(ref wValueLength) && serializer.SerializeWORD(ref wType) && serializer.SerializeWCHAR(ref szKey) && serializer.PadDWORD(); }
public override bool Serialize(ResourceSerializer serializer) { return serializer.SerializeDWORD(ref dwSignature) && serializer.SerializeDWORD(ref dwStrucVersion) && serializer.SerializeDWORD(ref dwFileVersionMS) && serializer.SerializeDWORD(ref dwFileVersionLS) && serializer.SerializeDWORD(ref dwProductVersionMS) && serializer.SerializeDWORD(ref dwProductVersionLS) && serializer.SerializeDWORD(ref dwFileFlagsMask) && serializer.SerializeDWORD(ref dwFileFlags) && serializer.SerializeDWORD(ref dwFileOS) && serializer.SerializeDWORD(ref dwFileType) && serializer.SerializeDWORD(ref dwFileSubtype) && serializer.SerializeDWORD(ref dwFileDateMS) && serializer.SerializeDWORD(ref dwFileDateLS); }
public void IncludesRelationshipData() { var target = new ResourceSerializer(DefaultObject, DefaultResource, GetUri(id: "123"), DefaultPathBuilder, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var included = result["included"] as JArray; var job = included?[0]; Assert.Equal(2, included?.Count); Assert.Equal("http://example.com/api/corporations/456/", included?[0]?["links"].Value <Uri>("self").ToString()); Assert.Equal(DefaultObject.Job.Id, job?["id"]); Assert.NotNull(job?["attributes"]); }
public void SerializesRelationshipData() { var person = new PersonWithNoJob(); var target = new ResourceSerializer(person, new PersonWithDefaultIdResource(), GetUri(id: "123"), DefaultPathBuilder, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var job = relationships["job"]; var friends = relationships["friends"]; Assert.Null(job["data"]); Assert.NotNull(friends); }
public void OmitRelationshipIdentifierObjectsWithoutProperty() { var includes = new IncludeContext(); includes.DisableDefaultIncluded = true; var target = new ResourceSerializer(DefaultObject, DefaultResource, GetUri(id: "123"), DefaultPathBuilder, null, includes); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var secretFriends = relationships["secret-friends"]; Assert.Null(secretFriends["data"]); }
public void IncludedRelationshipIdentifierObjects() { var includes = new IncludeContext(); includes.DisableDefaultIncluded = true; var target = new ResourceSerializer(DefaultObject, DefaultResource, GetUri(id: "123"), DefaultPathBuilder, null, includes); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var job = relationships["job"]; Assert.NotNull(job["data"]); }
public void IncludedResourceRelationshipURLsAreCorrect() { var person = new Person(true) { Job = new CompanyWithCustomers(true) }; var target = new ResourceSerializer(person, new PersonWithCompanyWithCustomersResource(), GetUri(id: "123"), DefaultPathBuilder, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var included = result["included"] as JArray; Assert.Equal("http://example.com/api/corporations/456/relationships/customers/", included?[0]?["relationships"]?["customers"]?["links"]?.Value <Uri>("self")?.ToString()); }
public void UsesTitle() { var company = Get.Company(); var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = new CompanyResource(), Result = company }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri("/corporations", "456").ToString())); _output.WriteLine(result.ToString()); Assert.Equal("corporation", result["data"]["type"]); }
public void SerializeTest() { using (var s = GetType().Assembly.GetManifestResourceStream(GetType(), "version")) { var m = new MemoryStream(); s.CopyTo(m); m.Seek(0, SeekOrigin.Begin); var i = ResourceSerializer.Deserialize <VS_VERSIONINFO>(m); var m2 = new MemoryStream(); ResourceSerializer.Serialize(i, m2); var b = m.ToArray(); var b2 = m2.ToArray(); Assert.IsTrue(b.SequenceEqual(b2)); } }
public void HandlesQueryParamsCollection() { var target = new ResourceSerializer(Get.People(1), new PersonResource(), GetUri(null, "a=b&c=d"), DefaultPathBuilder, null, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var jobLinks = result["data"][0]?["relationships"]?["job"]?["links"]; var selfLink = result["links"].Value <string>("self"); var jobSelfLink = jobLinks?.Value <Uri>("self")?.PathAndQuery; var jobRelationLink = jobLinks?.Value <Uri>("related")?.PathAndQuery; Assert.EndsWith("/api/people?a=b&c=d", selfLink); Assert.Equal("/api/people/0/relationships/employer/", jobSelfLink); Assert.Equal("/api/people/0/employer/", jobRelationLink); }
public void UsesSpecifiedPropertyId() { var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = DefaultResource, Result = DefaultObject }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri(id: "abc").ToString())); _output.WriteLine(result.ToString()); var id = result["data"].Value <string>("id"); Assert.Equal(DefaultObject.Identifier, id); }
public void SerializesRelationshipLinks() { var target = new ResourceSerializer(Get.Person(), new PersonResource(), GetUri("123"), DefaultPathBuilder, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var job = relationships["job"]; var friends = relationships["friends"]; Assert.Equal("/api/people/123/employer/", job["links"].Value <Uri>("related").AbsolutePath); Assert.Equal("/api/people/123/relationships/employer/", job["links"].Value <Uri>("self").AbsolutePath); Assert.Equal("/api/people/123/friends/", friends["links"].Value <Uri>("related").AbsolutePath); Assert.Equal("/api/people/123/relationships/friends/", friends["links"].Value <Uri>("self").AbsolutePath); }
public void SerializeDifferentBuilder() { var target = new ResourceSerializer(Get.Person(), new PersonResource(), GetUri("123"), new CanonicalUrlPathBuilder(), null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var job = relationships["job"]; var friends = relationships["friends"]; Assert.Equal("/corporations/456/", job["links"].Value <Uri>("related").AbsolutePath); Assert.Equal("/people/123/relationships/employer/", job["links"].Value <Uri>("self").AbsolutePath); Assert.Equal("/people/123/relationships/friends/", friends["links"].Value <Uri>("self").AbsolutePath); Assert.Null(friends["links"]["relationships"]); }
public void DocumentMustNotContainIncludedForEmptySet() { var people = new Person[0]; var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = DefaultResource, Result = people }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri().ToString())); _output.WriteLine(result.ToString()); Assert.Null(result["included"]); }
public void DocumentMustContainAtLeastOneDataOrErrorOrMeta() { var people = new Person[] { }; var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = DefaultResource, Result = people }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri().ToString())); _output.WriteLine(result.ToString()); Assert.NotNull(result["data"]); }
public void HandlesRecursiveProperties() { var firstModel = new Recursion.FirstModel(); var secondModel = new Recursion.SecondModel(); var thirdModel = new Recursion.ThirdModel(); var fourthModel = new Recursion.FourthModel(); firstModel.Child = secondModel; secondModel.Parent = firstModel; secondModel.Child = thirdModel; thirdModel.Parent = secondModel; thirdModel.Child = fourthModel; fourthModel.Parent = thirdModel; var target = new ResourceSerializer(firstModel, new Recursion.FirstModelResource(), GetUri(id: firstModel.Id), DefaultPathBuilder, null, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var included = result["included"] as JArray; Assert.NotNull(included); var secondOutput = included .Where(t => t["type"].Value <string>() == "second-model").FirstOrDefault(); Assert.NotNull(secondOutput); var parentReference = secondOutput["relationships"]?["parent"]?["data"]?["type"]; Assert.NotNull(parentReference); Assert.Equal(parentReference.Value <string>(), "first-model"); var childReference = secondOutput["relationships"]?["child"]?["data"]?["type"]; Assert.NotNull(childReference); Assert.Equal(childReference.Value <string>(), "third-model"); }
private static IEnumerable <VS_VERSIONINFO> LoadVersions(ModuleDefMD moduleDef) { var resourceDirectory = moduleDef.MetaData.PEImage.Win32Resources.Root.FindDirectory(new ResourceName(16)); if (resourceDirectory == null) { yield break; } foreach (var resourceEntry in resourceDirectory.Directories) { foreach (var versionEntry in resourceEntry.Data) { var vi = ResourceSerializer.Deserialize <VS_VERSIONINFO>(versionEntry.ToDataStream()); vi.DirectoryName = resourceEntry.Name; vi.DataName = versionEntry.Name; yield return(vi); } } }
public void HandlesNullValues() { var person = new Person(id: "45"); var target = new ResourceSerializer(person, DefaultResource, GetUri(id: "45"), DefaultPathBuilder, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var attributes = result["data"]["attributes"]; Assert.NotNull(attributes["first-name"]); Assert.NotNull(attributes["last-name"]); Assert.NotNull(attributes["age"]); Assert.Null(relationships["job"]["data"]); Assert.Null(relationships["friends"]["data"]); }
public void HandlesRecursiveProperties() { var firstModel = new Recursion.FirstModel(); var secondModel = new Recursion.SecondModel(); firstModel.Model = secondModel; secondModel.Model = firstModel; var target = new ResourceSerializer(firstModel, new Recursion.Resource(), GetUri(id: "123"), DefaultPathBuilder, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var id = result["data"].Value <string>("id"); Assert.Equal(firstModel.Id, id); }
public void OnlySerializesAttributesInTheResource() { var personMock = new Mock <LazyPerson>(); personMock.SetupGet(p => p.Identifier).Returns("123"); var target = new ResourceSerializer(personMock.Object, DefaultResource, GetUri(id: "1"), DefaultPathBuilder, null, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); personMock.VerifyGet(p => p.Identifier); Assert.Throws <MockException>(() => { personMock.VerifyGet(p => p.NumberOfLegs); }); }
public void UsesDefaultPropertyId() { var data = new PersonWithNoJob(); var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = new PersonWithDefaultIdResource(), Result = data }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri(id: "123").ToString())); _output.WriteLine(result.ToString()); var id = result["data"].Value <string>("id"); Assert.Equal(data.Id, id); }
public void SupportsGuidIds() { var guid = new GuidAsId(); var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = new PersonWithDefaultIdResource(), Result = guid }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri(id: "123").ToString())); _output.WriteLine(result.ToString()); Assert.NotNull(result["data"]["id"]); Assert.Equal(guid.Id, Guid.Parse(result["data"]["id"].ToString())); }
public void SerializesRelationshipDataAsNull() { var person = Get.Person(id: "123"); person.Job = null; var target = new ResourceSerializer(person, DefaultResource, GetUri(id: "123"), DefaultPathBuilder, null, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var relationships = result["data"]["relationships"]; var job = relationships["job"]; var friends = relationships["friends"]; Assert.Equal(JTokenType.Null, job["data"].Type); Assert.NotNull(friends); }
public void AttributesSufficient() { var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = DefaultResource, Result = DefaultObject }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri(id: "123").ToString())); _output.WriteLine(result.ToString()); var attributes = result["data"]["attributes"]; Assert.True(attributes["numberOfLegs"] == null); Assert.Equal(3, attributes.Count()); }
public void EmptyForNull() { var company = Get.Company(); var target = new ResourceSerializer( company, new CompanyResource(), new Uri("http://localhost/people/123"), new DefaultUrlPathBuilder(), null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); JToken meta; Assert.False(result.TryGetValue("meta", out meta), "Meta hash is null"); }
public void SerializeOnlyWhatYouHave() { var company = new GuidAsId(); var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = new CompanyResource(), Result = company }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri(id: "123").ToString())); _output.WriteLine(result.ToString()); Assert.Null(result["data"]["attributes"]["name"]); Assert.Null(result["data"]["attributes"]["location"]); Assert.Null(result["data"]["attributes"]["number-of-employees"]); }
public void AttributesComplete() { var target = new ResourceSerializer(urlBuilder: new DefaultUrlPathBuilder("/api")); var resourceResult = new ResourceResult { Resource = DefaultResource, Result = DefaultObject }; var result = JToken.Parse(target.Serialize(resourceResult, GetUri(id: "123").ToString())); _output.WriteLine(result.ToString()); var attributes = result["data"]["attributes"]; Assert.Equal(DefaultObject.FirstName, attributes.Value <string>("first-name")); Assert.Equal(DefaultObject.LastName, attributes.Value <string>("last-name")); Assert.Equal(DefaultObject.Age, attributes.Value <int>("age")); }
void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); return; } if (!Directory.Exists(Application.persistentDataPath + "/Resources")) { Directory.CreateDirectory(Application.persistentDataPath + "/Resources"); } if (!File.Exists(Application.persistentDataPath + path)) { initializeXml(); } }
public void SelfLinksInCollectionCustomRoute() { var people = Get.People(5); var target = new ResourceSerializer(people, new PersonResource(), new Uri("http://localhost:80/api/location/123/people"), CustomPathBuilder, null, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); var selfLink = result["links"].Value <string>("self"); foreach (var elem in result["data"]) { var links = elem["links"]; Assert.NotNull(links); Assert.Equal("/api/location/123/people/" + elem.Value <string>("id") + "/", links.Value <Uri>("self").AbsolutePath); } Assert.EndsWith("/api/location/123/people", selfLink); }
private void Update() { //print(rectTransform.rect); if (totalScore == 0) { scoreText.text = "Score: 000"; } else { scoreText.text = "Score: " + totalScore; } chainText.text = "Best Chain: " + highestChain; if (timerIsRunning) { if (timeRemaining > 0) { timeRemaining -= Time.deltaTime; DisplayTimeMS(timeRemaining); } else { Debug.Log("Time's up!"); timeRemaining = 0; // lock the timer so it doesn't turn negative timerIsRunning = false; IsActive = false; moneyText.text = "" + moneyVal + "M"; scienceText.text = "" + scienceVal; globalCoopText.text = "" + globalCoopVal; educationText.text = "" + educationVal; int[] resourceValues = getResourceValues(); updatedMoneyVal = resourceValues[0] + moneyVal; updatedScienceVal = resourceValues[1] + scienceVal; updatedGlobalCoopVal = resourceValues[2] + globalCoopVal; updatedEducationVal = resourceValues[3] + educationVal; ResourceSerializer.updateXml(updatedMoneyVal, updatedScienceVal, updatedGlobalCoopVal, updatedEducationVal); } } }
public void PreviousLinkWithShiftedFirstPage() { var people = Get.People(5); var target = new ResourceSerializer(people, new PersonResource(), GetUri(), DefaultPathBuilder, new PaginationContext(GetQuery(Constants.QueryNames.PageNumber, "1"), pageSizeDefault: 10, pageSizeLimit: null, firstPageNumber: 1), null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); Assert.Equal(null, result["links"]["prev"]); target = new ResourceSerializer(people, new PersonResource(), GetUri(), DefaultPathBuilder, new PaginationContext(GetQuery(Constants.QueryNames.PageNumber, "2"), pageSizeDefault: 10, pageSizeLimit: null, firstPageNumber: 1), null, null); result = target.Serialize(); var nextLink = Uri.UnescapeDataString(result["links"].Value <Uri>("prev").Query); Assert.Equal("?page[number]=1", nextLink); }
public void SerializesDynamics() { dynamic person = new ExpandoObject(); person.Identifier = 1; person.FirstName = "John"; person.LastName = "Smith"; person.Age = 34; person.NumberOfLegs = 4; var target = new ResourceSerializer(person, DefaultResource, GetUri(id: "1"), DefaultPathBuilder, null, null, null); var result = target.Serialize(); _output.WriteLine(result.ToString()); Assert.Equal(result["data"]["id"], "1"); Assert.Equal(result["data"]["attributes"]["first-name"], "John"); Assert.Equal(result["data"]["attributes"]["age"], 34); }
public override bool Serialize(ResourceSerializer serializer) { return serializer.SerializeLength(s => SerializeHeader(s) && SerializeValue(s) && SerializeChildren(s), ref wLength); }
public virtual bool SerializeValue(ResourceSerializer serializer) => true;
public override bool SerializeValue(ResourceSerializer serializer) { return serializer.SerializeWCHAR(ref Value, ref wValueLength) && serializer.PadDWORD(); }
public virtual bool SerializeChildren(ResourceSerializer serializer) => true;
public override bool SerializeChildren(ResourceSerializer serializer) { return serializer.Serialize(this, ref Children, ref wLength, typeof(StringTable)); }
public override bool SerializeChildren(ResourceSerializer serializer) => serializer.Serialize(this, ref Children, ref wLength, typeof(VarFileInfo), typeof(StringFileInfo));