Comments (8)
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.
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.
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.
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.
any updates on this?
from fluentassertions.analyzers.
Could you share a code sample for that triggers this?
from fluentassertions.analyzers.
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.
I'm not able to reproduce this anymore, I think was fixed in #100
from fluentassertions.analyzers.
Related Issues (20)
- Various bugs running on large codebase
- Collection analyzers are not running on arrays
- Collection analyzers are not running on dictionaries
- Collection analyzers are not running on properties of types
- `NullReferenceException` in `CollectionAnalyzer.ShouldAnalyzeVariableType` HOT 4
- Misleading diagnostic and wrong fix for array.Length.Should().Be() HOT 2
- xunit: define codefixes for StringAsserts with StringComparison
- Add DateTime tips analyzers
- feature-request: Support for FixAllProvider HOT 4
- Use single DiagnosticId for fluentassertions tips
- Checklist of all tips and whether they have analyzers HOT 4
- Auto-fixes stopped working on 0.28.0 release (when having conditional expressions) HOT 5
- Add analyzers and code fixers for Shouldly
- Saying `.Select(x => x.Name).Should().Equal` should not be a code smell HOT 1
- False positive for "Use `.Should().OnlyHaveUniqueItems()`" HOT 1
- False positive for "Use `.Should().HaveSameCount()`" HOT 1
- Wrong description for `.Should().Contain()` and `.Should().NotContain()` HOT 1
- Request: Give diagnosis when ThrowAsync etc. is not awaited
- Rewrite order when handling `Assert.AreEqual` HOT 1
- False warning of FAA0001 when using 2D array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluentassertions.analyzers.