Git Product home page Git Product logo

Comments (8)

thomaslevesque avatar thomaslevesque commented on May 31, 2024 1

I just hit this as well. This code works fine:

var conditions = blocks[2].Questions[1].Conditions;
conditions.Should().HaveCount(1);

This code triggers the exception:

blocks[2].Questions[1].Conditions.Should().HaveCount(1)

from fluentassertions.analyzers.

thomaslevesque avatar thomaslevesque commented on May 31, 2024 1

If I'm not mistaken, #100 just swallows exception. So maybe the exception is no longer visible to the user, but it doesn't mean the underlying problem (whatever it is) is solved.

from fluentassertions.analyzers.

Gokulaprakash avatar Gokulaprakash commented on May 31, 2024

I encountered the same issue in one of our projects today and was able to narrow down the issue and created a small example to reproduce the problem.

        public void Test1()
        {
            var sut = new List<Dictionary<string, string>>();
            sut.Add(new Dictionary<string, string> { {"testKey", "testValue"}});
            sut[0]["testKey"].Should().Be("testValue");
        }

from fluentassertions.analyzers.

bonesoul avatar bonesoul commented on May 31, 2024

same issue here

getting

>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.

from fluentassertions.analyzers.

bonesoul avatar bonesoul commented on May 31, 2024

any updates on this?

from fluentassertions.analyzers.

Meir017 avatar Meir017 commented on May 31, 2024

Could you share a code sample for that triggers this?

from fluentassertions.analyzers.

bonesoul avatar bonesoul commented on May 31, 2024

my best guess is;

using NodaTime;
using NodaTime.Extensions;
using System.Collections;
using System.Collections.Generic;

public class ProcessorTestsFixtureCollection : IEnumerable<object[]>
    {
        public IEnumerator<object[]> GetEnumerator()
        {
            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() // current hour.
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromHours(1) // a hour ago.
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromHours(1), // a hour ago
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() // current hour
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromHours(1), // two hour ago
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromHours(2) // a hour ago
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromDays(1) // a day ago
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromDays(1), // a day ago
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() // current day
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromDays(2), // two days ago.
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromDays(1) // a day ago.
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromMonths(1) // a month ago
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromMonths(1), // a month ago
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() // current month
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromMonths(2), // two months ago
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromMonths(1) // a month ago.
                }
            };

            yield return new object[]
            {
                new List<LocalDateTime>
                {
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromMonths(2) - Period.FromDays(2) - Period.FromHours(2), // 2 months, 2 days, 2 hours ago
                    SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentLocalDateTime() - Period.FromMonths(1) - Period.FromDays(1) - Period.FromHours(1) // a month, a day and a hour ago.
                }
            };
        }

        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
    }

output;

3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldContainItemAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveElementAtAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.
3>CSC : warning AD0001: Analyzer 'FluentAssertions.Analyzers.CollectionShouldHaveCountAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'This operation does not apply to an empty instance.'.

from fluentassertions.analyzers.

Meir017 avatar Meir017 commented on May 31, 2024

I'm not able to reproduce this anymore, I think was fixed in #100

from fluentassertions.analyzers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.