public void HashSet_and_Array_can_read_each_other()
        {
            // Implementation uses this fact: an array is a IList.
            typeof(int[]).Should().BeAssignableTo <IList <int> >();

            var c = TestHelper.CreateStObjCollector(typeof(PocoJsonSerializer), typeof(IWithArray), typeof(IWithSet));

            using var services = TestHelper.CreateAutomaticServices(c).Services;

            var fSet   = services.GetRequiredService <IPocoFactory <IWithSet> >();
            var fArray = services.GetRequiredService <IPocoFactory <IWithArray> >();
            var oS     = fSet.Create(o =>
            {
                o.Numbers.AddRangeArray(12, 87, 12, 54, 12);
            });
            var oA = fArray.Create(o =>
            {
                o.Numbers = new int[] { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 };
            });
            var oSb     = oS.JsonSerialize(false);
            var oAb     = oA.JsonSerialize(false);
            var oAFromS = JsonTestHelper.Deserialize <IWithArray>(services, oSb.Span);
            var oSFromA = JsonTestHelper.Deserialize <IWithSet>(services, oAb.Span);

            Debug.Assert(oAFromS != null && oSFromA != null);

            oAFromS.Numbers.Should().BeEquivalentTo(new[] { 12, 87, 54 });
            oSFromA.Numbers.Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5 });
        }
        public void HashSet_and_List_can_read_each_other()
        {
            var c = TestHelper.CreateStObjCollector(typeof(PocoJsonSerializer), typeof(IWithSet), typeof(IWithList));

            using var services = TestHelper.CreateAutomaticServices(c).Services;

            var fSet  = services.GetRequiredService <IPocoFactory <IWithSet> >();
            var fList = services.GetRequiredService <IPocoFactory <IWithList> >();
            var oS    = fSet.Create(o =>
            {
                o.Numbers.AddRangeArray(12, 87, 12, 54, 12);
            });
            var oL = fList.Create(o =>
            {
                o.Numbers.AddRangeArray(1, 2, 3, 4, 5, 1, 2, 3, 4, 5);
            });
            var oSb     = oS.JsonSerialize(false);
            var oLb     = oL.JsonSerialize(false);
            var oLFromS = JsonTestHelper.Deserialize <IWithList>(services, oSb.Span);
            var oSFromL = JsonTestHelper.Deserialize <IWithSet>(services, oLb.Span);

            Debug.Assert(oLFromS != null && oSFromL != null);

            oLFromS.Numbers.Should().BeEquivalentTo(new[] { 12, 87, 54 });
            oSFromL.Numbers.Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5 });
        }
        public void missing_and_extra_properties_in_Json_are_ignored_Missing_have_their_DefaultValue_Extra_are_skipped()
        {
            var c = TestHelper.CreateStObjCollector(typeof(PocoJsonSerializer), typeof(ITest));;

            using var s = TestHelper.CreateAutomaticServices(c).Services;

            string missingValue = @"{""Hip"": ""Hop"", ""Stranger"": [0,1,[]]}";
            var    noValue      = JsonTestHelper.Deserialize <ITest>(s, missingValue);

            Debug.Assert(noValue != null);
            noValue.Hip.Should().Be("Hop");
            noValue.Power.Should().Be(0);

            string missingHip = @"{""Power"": 871871, ""Another"": {""Nimp"": [87,54]}, ""Stranger"": []}";
            var    noHip      = JsonTestHelper.Deserialize <ITest>(s, missingHip);

            Debug.Assert(noHip != null);
            noHip.Hip.Should().Be("Hello...", "This is the default Hip value.");
            noHip.Power.Should().Be(871871);
        }