public void RequestData() { TestCollection collection = CreateCollection(); var queryStringBuilder = new RequestDataBuilder(); collection.AddQuery(HalSelfActionLinkAttribute.SelfRelName, queryStringBuilder); var serializer = mockup.Get <JsonSerializer>(); using (var stream = new MemoryStream()) { using (var writer = new JsonTextWriter(new StreamWriter(stream, Encoding.Default, 4096, true))) { serializer.Serialize(writer, queryStringBuilder.Data); } stream.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(stream)) { var json = reader.ReadToEnd(); var filename = $"{nameof(RequestData)}.json"; FileUtils.WriteTestFile(this.GetType(), filename, json); var expected = FileUtils.ReadTestFile(this.GetType(), filename); Assert.Equal(expected, json); } } }
public void RequestDataWithCollection() { var queryStringBuilder = new RequestDataBuilder(); queryStringBuilder.AppendItem("ArrayOfThings", 1); queryStringBuilder.AppendItem("ArrayOfThings", 2); queryStringBuilder.AppendItem("ArrayOfThings", 3); queryStringBuilder.AppendItem("SingleThing", "hi"); var serializer = mockup.Get <JsonSerializer>(); using (var stream = new MemoryStream()) { using (var writer = new JsonTextWriter(new StreamWriter(stream, Encoding.Default, 4096, true))) { serializer.Serialize(writer, queryStringBuilder.Data); } stream.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(stream)) { var json = reader.ReadToEnd(); var filename = $"{nameof(RequestDataWithCollection)}.json"; FileUtils.WriteTestFile(this.GetType(), filename, json); var expected = FileUtils.ReadTestFile(this.GetType(), filename); Assert.Equal(expected, json); } } }
public void Default_ctor_sets_no_values() { var sut = new RequestDataBuilder <Person>() .Create(); Assert.True(sut.Count == 0); }
public void AddQuery(string rel, RequestDataBuilder queryString) { if (File != null && rel == HalSelfActionLinkAttribute.SelfRelName) { queryString.AppendItem("file", File); } }
public void Omit_removes_properties(Person template) { var sut = new RequestDataBuilder <Person>(template) .Omit(p => p.Age) .Create(); Assert.False(sut.ContainsKey("Age")); }
public void Set_overwrites_property_values_from_template(Person template) { var sut = new RequestDataBuilder <Person>() .Set(p => p.Name, "Eric") .Create(); Assert.NotEqual(sut["Name"], template.Name); }
public void Template_ctor_maps_property_values_from_template(Person template) { var sut = new RequestDataBuilder <Person>(template) .Create(); Assert.Equal(sut["Name"], template.Name); Assert.Equal(sut["Age"], template.Age); }
protected override void AddCustomQuery(string rel, RequestDataBuilder queryString) { if (query.File != null) { queryString.AppendItem("file", query.File.TrimStartingPathChars()); } base.AddCustomQuery(rel, queryString); }
public void Set_sets_property_value() { var sut = new RequestDataBuilder <Person>() .Set(p => p.Name, "Eric") .Set(p => p.Age, 12) .Create(); Assert.True(sut.ContainsKey("Name")); Assert.True(sut.ContainsKey("Age")); }
protected override void AddCustomQuery(string rel, RequestDataBuilder queryString) { if (query.File != null) { queryString.AppendItem("file", query.File); } if (ShowChangedOnly) { queryString.AppendItem("showChangedOnly", query.ShowChangedOnly.ToString()); } base.AddCustomQuery(rel, queryString); }