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

Tests renderer: deserialization of test failed due to System.Collections.Generic.KeyNotFoundException #199

Open
mxprshn opened this issue Dec 15, 2022 · 0 comments

Comments

@mxprshn
Copy link
Member

mxprshn commented Dec 15, 2022

Commit: 00bf945 with cherry-picked fc58e4af529a0e402d6c37d19f07e551da7ece39 (from @MchKosticyn fork)

Tested code:

namespace NetFeaturesDemo;

public enum EventType
{
    Save,
    Change
}

public record Event(int UserId, EventType Type, string Delta);

public interface ISaver<in T>
{
    bool Save(IEnumerable<T> deltas);
}

public static class AutoSaveService
{
    public static bool AutoSave(int userId, int autoSaveThreshold, ISaver<string> saver)
    {
        var events = new List<Event>
        {
            new Event(1, EventType.Change, "gcctaca"),
            new Event(1, EventType.Change, "ctccagg"),
            new Event(1, EventType.Save, ""),
            new Event(1, EventType.Change, "gatagtc"),
            new Event(2, EventType.Change, "agcggaa"),
        };

        var notSavedChanges =
            from e in events where e.UserId == userId select e;
        notSavedChanges = notSavedChanges.TakeWhile(e => e.Type == EventType.Change);

        if (notSavedChanges.Count() > autoSaveThreshold)
        {
            return saver.Save(from e in notSavedChanges select e.Delta);
        }

        return false;
    }
}

Runner config: --all-public-methods <dll path> --render-tests --single-file --output <output path>

Stack trace:

[Error] [15/12/2022 12:50:36] Tests renderer: deserialization of test failed: System.IO.InvalidDataException: Input test is incorrect
 ---> System.Collections.Generic.KeyNotFoundException: An index satisfying the predicate was not found in the collection.
   at Microsoft.FSharp.Collections.SeqModule.Find[T](FSharpFunc`2 predicate, IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 811
   at VSharp.methodRepr.Decode() in D:\VSharp\VSharp.Utils\Mocking.fs:line 21
   at [email protected](methodRepr m, Object[] c) in D:\VSharp\VSharp.Utils\Mocking.fs:line 153
   at Microsoft.FSharp.Collections.ArrayModule.Map2[T1,T2,TResult](FSharpFunc`2 mapping, T1[] array1, T2[] array2) in D:\a\_work\1\s\src\FSharp.Core\array.fs:line 393
   at VSharp.Mocking.Type..ctor(typeMockRepr repr) in D:\VSharp\VSharp.Utils\Mocking.fs:line 153
   at VSharp.UnitTest..ctor(MethodBase m, testInfo info, Boolean createCompactRepr) in D:\VSharp\VSharp.Utils\UnitTest.fs:line 57
   at VSharp.UnitTest.DeserializeFromTestInfo(testInfo ti, Boolean createCompactRepr) in D:\VSharp\VSharp.Utils\UnitTest.fs:line 215
   --- End of inner exception stack trace ---
   at VSharp.UnitTest.DeserializeFromTestInfo(testInfo ti, Boolean createCompactRepr) in D:\VSharp\VSharp.Utils\UnitTest.fs:line 218
   at VSharp.TestRenderer.Renderer.DeserializeTest(FileInfo test) in D:\VSharp\VSharp.TestRenderer\RendererTool.cs:line 539
   at VSharp.TestRenderer.Renderer.DeserializeTests(IEnumerable`1 tests) in D:\VSharp\VSharp.TestRenderer\RendererTool.cs:line 549
[Error] [15/12/2022 12:50:37] Tests renderer: rendering test failed: System.NotImplementedException: rendering constructors not supported yet
   at VSharp.TestRenderer.TestsRenderer.RenderTestsForType(IEnumerable`1 tests, ProgramRenderer testsProgram, ProgramRenderer mocksProgram, Type declaringType, Boolean wrapErrors) in D
:\VSharp\VSharp.TestRenderer\TestsRenderer.cs:line 588

NB: generation for this code works fine

public static class Linq
{
    private enum EventType
    {
        Save,
        Change
    }

    private record Event(int UserId, EventType Type, string Delta);

    public interface ISaver<in T>
    {
        bool Save(IEnumerable<T> deltas);
    }

    public static class AutoSaveService
    {
        public static bool AutoSave(int userId, int autoSaveThreshold, ISaver<string> saver)
        {
            var events = new List<Event>
            {
                new Event(1, EventType.Change, "gcctaca"),
                new Event(1, EventType.Change, "ctccagg"),
                new Event(1, EventType.Save, ""),
                new Event(1, EventType.Change, "gatagtc"),
                new Event(2, EventType.Change, "agcggaa"),
            };

            var notSavedChanges =
                from e in events where e.UserId == userId select e;
            notSavedChanges = notSavedChanges.TakeWhile(e => e.Type == EventType.Change);

            if (notSavedChanges.Count() > autoSaveThreshold)
            {
                return saver.Save(from e in notSavedChanges select e.Delta);
            }

            return false;
        }
    }
}
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

1 participant