public void ShouldReturnJsonObject() { //arrange string raceJson = "\"race\":\"Human\""; string classJson = "\"class\":\"Wizard\""; string attributeSetJson = "\"characterAttributes\":[" + "{\"characterAttribute\":\"STR\",\"value\":0}," + "{\"characterAttribute\":\"CON\",\"value\":0}," + "{\"characterAttribute\":\"INT\",\"value\":0}," + "{\"characterAttribute\":\"WIS\",\"value\":0}," + "{\"characterAttribute\":\"CHR\",\"value\":0}," + "{\"characterAttribute\":\"DEX\",\"value\":10}," + "]"; IAttributeSet attributeSet = new EmptyAttributeSet(); _characterSheet = new CharacterSheet(new Wizard(), new Human(), attributeSet); string proficienciesJson = $"\"Proficiencies\":[{string.Join(",", _characterSheet.Proficiencies().Select(x => $"\"{x}\""))}],"; string expectedJson = $"{{characterSheet:{{{raceJson},{classJson},{ attributeSetJson},{proficienciesJson}}}}}"; attributeSet.SetAttribute(CharacterAttributeName.Dexterity, new AttributeScore(10)); StringBuilder sb = new StringBuilder(); //act _characterSheet.AddJsonToStringbuilder(sb); //assert sb.ToString().Should().Be(expectedJson); }
public void ShouldSerializeObject() { IJsonInterpreter wrapper = new JsonWrapper(); EmptyAttributeSet attributeSet = new EmptyAttributeSet(); string expectedJson = "{\"characterAttributes\":[{\"characterAttribute\":\"STR\",\"value\":0},{\"characterAttribute\":\"DEX\",\"value\":0},{\"characterAttribute\":\"CON\",\"value\":0},{\"characterAttribute\":\"INT\",\"value\":0},{\"characterAttribute\":\"WIS\",\"value\":0},{\"characterAttribute\":\"CHR\",\"value\":0},]}"; string actualJson = wrapper.Serialize(attributeSet); actualJson.Should().Be("{}"); }