示例#1
0
 public GetStateParser()
 {
     _positionalSerializer = PositionalSerializer.CreateFor <MigoStateModel>(';')
                             .FixedString("state")
                             .Field(x => x.HeadX)
                             .Field(x => x.HeadY)
                             .Field(x => x.BedTemp)
                             .Field(x => x.NozzleTemp);
 }
        public void Should_set_iserror_on_deserialization_accordingly(string marker, bool expected)
        {
            var serializer = PositionalSerializer
                             .CreateFor <MigoStateModel>(';')
                             .FixedString(marker);

            _ = serializer.Parse(StateInput);

            serializer.IsError.Should().Be(expected);
        }
        public void Should_deserialize_state_input()
        {
            var serializer = PositionalSerializer
                             .CreateFor <MigoStateModel>(';')
                             .FixedString("state")
                             .Skip(2)
                             .Field(x => x.NozzleTemp)
                             .Field(x => x.BedTemp);

            var migoState = serializer.Parse(StateInput);

            migoState.BedTemp.Should().Be(25);
            migoState.NozzleTemp.Should().Be(23);
        }
        public void Should_deserialize_simple_type_with_several_delimiter_changes()
        {
            var serializer = PositionalSerializer
                             .CreateFor <SerializerTestModel>(':')
                             .FixedString(SerializerTestModel.FixedString)
                             .NextDelimiter(';')
                             .Field(x => x.FieldA)
                             .Field(x => x.FieldB)
                             .NextDelimiter(',')
                             .Field(x => x.FieldC)
                             .Field(x => x.FieldD)
                             .Field(x => x.FieldE);

            var expected = SerializerTestModel.Expected;
            var result   = serializer.Parse(expected.GetStringRepresentation());

            serializer.IsError.Should().BeFalse();
            result.Should().BeEquivalentTo(expected);
        }