XML : Creating a test method to test WriteXML

I have a method WriteXml.

  public void WriteXml(XmlWriter writer)          {              if (this.value == null)              {                  writer.WriteValue(this.value?.ToString() ?? string.Empty);                  return;              }              var type = this.value.GetType();                var memInfo = type.GetMember(this.value.ToString());                if (memInfo.Length > 0)              {                  var attrs = memInfo[0].GetCustomAttributes<XmlEnumAttribute>();                    if (attrs != null && attrs.IsNotEmpty())                  {                      writer.WriteValue(attrs);                        return;                  }              }              writer.WriteValue(this.value.ToString());          }    

When I am testing it with the unit test. i.e.,

  [Theory]          [InlineData(null, "")]          [InlineData(exposureSValue.NA, "N/A")]          [InlineData(exposureSValue.Last15Days, "Last 15 Days")]          public void WriteXmlTest([CanBeNull] exposureSValue? policyCustomEnumValue, [CanBeNull] string writtenValue)          {              // Arrange              var mockXmlWriter = this.Mock.Create<XmlWriter>(Moq.MockBehavior.Loose);              mockXmlWriter.Setup(x => x.WriteValue(writtenValue));                var policyCustomerEnum = new PolicyCustomEnum<exposureSValue>(policyCustomEnumValue);                // Act and Assert              policyCustomerEnum.WriteXml(mockXmlWriter.Object);          }    

While I run this unit test I get an error saying

  The following setups were not matched:  XmlWriter x=>x.WriteValue("N/A");    

Please help me out with this. I also tried changing the parameter in the test method which is string type to exposureSValue type but it still the same.

How to get rid of that error message?

No comments:

Post a Comment