Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using dynamic data source method fails to work #1588

Closed
ThomasMader opened this issue Feb 9, 2023 · 2 comments
Closed

Using dynamic data source method fails to work #1588

ThomasMader opened this issue Feb 9, 2023 · 2 comments

Comments

@ThomasMader
Copy link

Describe the bug

Using the dynamic data source method as in the code below in the 'Additional context' area fails with the message in the comment.
If the line fooValues = new SortedSet<int>(); is commented out it starts to work.

Happened to me with version 2.2.10.

Additional context

using System.Collections.Generic;

 

using Microsoft.VisualStudio.TestTools.UnitTesting;

 

namespace Testing

{

      [TestClass]

      public class Test

      {

            // This test fails with the following.

            //

            //Message: 

            //Collection interface type 'System.Collections.Generic.IEnumerable`1[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' is being used as a get-only property and does not have an Add method.Consider adding a setter to the property or using a collection data contract that does have an Add method - for example IList or ICollection<T>.

            //

            //Stack Trace: 

            //JsonCollectionDataContract.get_JsonFormatGetOnlyReaderDelegate()

            //JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)

            //JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)

            //XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)

            //XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)

            //ReadTest_FooFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString[] )

            //JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)

            //JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)

            //XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)

            //XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)

            //XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)

            //DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)

            //XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)

            //XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)

            //DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)

            //DataContractJsonSerializer.ReadObject(Stream stream)

            [TestMethod]

            [DynamicData(nameof(GetTestData), DynamicDataSourceType.Method)]

            public void TestMethod(string someString, Foo foo)

            {

            }

 

            private static IEnumerable<object[]> GetTestData()

            {

                  yield return new object[]

                  {

                        "", new Foo()

                  };

            }

 

            public class Foo

            {

                  private readonly SortedSet<int> fooValues;

 

                  public IEnumerable<int> FooValues => fooValues;

 

                  public Foo()

                  {

                        // Make the test work by commenting out following line.

                        fooValues = new SortedSet<int>();

                  }

            }

      }

}


@Evangelink
Copy link
Member

Hi @ThomasMader,

This is yet another example of #1462. We are reviewing the options we can put in place to overcome these serialization/deserialization issues with parameterized tests.

Thanks for the report!

@Evangelink
Copy link
Member

Closing this ticket, please follow #1462 to get updates about the state and fix ETA.

@Evangelink Evangelink closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants