public void TestFootballJson() { //Tests that serializing a typed fixture works //Arrange var fixture = new FootballFixture { Sport = Fixture.SportFootball, Description = "Football 01", Variables = new FootballVariables { MatchLength = 90, ExtraTime = true } }; //Act var fixtureJson = fixture.ToJson(); //Assert Assert.AreEqual("{\"Variables\":{\"MatchLength\":90,\"ExtraTime\":true},\"Sport\":\"Football\",\"Description\":\"Football 01\"}", fixtureJson); }
public void TestExternalServiceFootballJson() { //Test that passing a typed fixture to a service that deals with the base class only still keps all the typed information intact (integration test) //Arrange var fixture = new FootballFixture { Sport = Fixture.SportFootball, Description = "Football 01", Variables = new FootballVariables { MatchLength = 90, ExtraTime = true } }; const string fixtureCreateUrl = ExternalServiceUrl + "fixture"; var fixtureJson = fixture.ToJson(); //Act var jsonResponse = RestHelper.GetJsonResponse(new Uri(fixtureCreateUrl), fixtureJson, "POST", Fixture.ContentTypeFootball); //Assert Assert.AreEqual("{\"Variables\":{\"MatchLength\":90,\"ExtraTime\":true},\"Sport\":\"Football\",\"Description\":\"Football 01\"}", fixtureJson); Assert.AreEqual("{\"Variables\":{\"MatchLength\":90,\"ExtraTime\":true},\"Sport\":\"Football\",\"Description\":\"Football 01\"}", jsonResponse); }
public void TestContentTypeDeserializationFootball() { //Test that deserializing a sub class into a base class type works when you specify a content type //Arrange var fixture = new FootballFixture { Sport = Fixture.SportFootball, Description = "Football 01", Variables = new FootballVariables { MatchLength = 90, ExtraTime = true } }; //Act var fixtureJson = fixture.ToJson(); var deserializedFixture = fixtureJson.FromJson<Fixture>(Fixture.ContentTypeFootball); //Assert Assert.AreEqual("{\"Variables\":{\"MatchLength\":90,\"ExtraTime\":true},\"Sport\":\"Football\",\"Description\":\"Football 01\"}", fixtureJson); Assert.AreEqual(typeof(FootballFixture), deserializedFixture.GetType()); Assert.AreEqual(typeof(FootballVariables), ((FootballFixture)deserializedFixture).Variables.GetType()); Assert.AreEqual(Fixture.SportFootball, deserializedFixture.Sport); Assert.AreEqual("Football 01", deserializedFixture.Description); Assert.AreEqual(90, ((FootballFixture)deserializedFixture).Variables.MatchLength); Assert.IsTrue(((FootballFixture)deserializedFixture).Variables.ExtraTime); }