public static BrokenEngine From(WorkingEngine engine, Reason reason) { return(engine.Status.MatchSingle( (Stopped stopped) => new BrokenEngine(reason, stopped.PreviousStatuses), () => new BrokenEngine(reason) )); }
public void Given_Instance_Of_OneOf_Case_When_Serializing_Then_Produces_Valid_Json_String() { Engine engine = new WorkingEngine(Power.Create(999)); var json = JsonConvert.SerializeObject(engine, settings); var engineJObject = JObject.FromObject(engine); json.Should().NotBeNullOrEmpty(); }
public void Given_Instance_Of_OneOf_Case_When_Serializing_Then_Produced_JObject_Contains_Correct_Discriminator_Values() { Engine engine = new WorkingEngine(Power.Create(999)); var engineJObject = JObject.FromObject(engine); var engineJObjectDiscriminator = engineJObject.Value <string>("Value"); var engineJObjectStatusDiscriminator = engineJObject["Status"].Value <string>("Value"); engineJObject.Should().NotBeNull(); engineJObjectDiscriminator.Should().NotBeNullOrEmpty(); engineJObjectDiscriminator.Should().Equals(JToken.FromObject(nameof(WorkingEngine))); engineJObjectStatusDiscriminator.Should().NotBeNullOrEmpty(); engineJObjectStatusDiscriminator.Should().Equals(JToken.FromObject(nameof(Status.Idle))); }