El Grande Padre
El Grande Padre
CC#
Created by El Grande Padre on 9/27/2023 in #help
❔ Looking for an AutoFixture struct customization workaround
Hello, Autofixture's .Do() customization doesn't work with value types which makes sense because nothing gets returned. I'm trying to have autofixture create a start time that is guaranteed to be before an end time within a value type. The following is what I have that works for reference types but not value types. If anyone has any work arounds to make autofixture generate start times before end time I would greatly appreciate it.
struct TimeRange
{
public Instant startTime;
public Instant endTime;
}
[Theory, AutoData]
public void StartEndTime([Range(1, 100)] int cardinality)
{
var fixture = new Fixture();
var timeRanges = fixture.Build<TimeRange>()
.Without(e => e.startTime)
.Without(e => e.endTime)
.Do(e =>
{
e.startTime = fixture.Create<Instant>();
e.endTime = e.startTime + fixture.Create<Duration>();
})
.CreateMany(cardinality)
.ToList();

timeRanges.Should().AllSatisfy(e =>
{
e.startTime.Should().BeLessThan(e.endTime);
});
}
struct TimeRange
{
public Instant startTime;
public Instant endTime;
}
[Theory, AutoData]
public void StartEndTime([Range(1, 100)] int cardinality)
{
var fixture = new Fixture();
var timeRanges = fixture.Build<TimeRange>()
.Without(e => e.startTime)
.Without(e => e.endTime)
.Do(e =>
{
e.startTime = fixture.Create<Instant>();
e.endTime = e.startTime + fixture.Create<Duration>();
})
.CreateMany(cardinality)
.ToList();

timeRanges.Should().AllSatisfy(e =>
{
e.startTime.Should().BeLessThan(e.endTime);
});
}
2 replies
CC#
Created by El Grande Padre on 1/16/2023 in #help
✅ Not able to locate web api controllers in a class library
Hello, I'm having some issues with trying to load web api controllers from a class library. I did try explicitly adding the assembly with AddControllers().AddApplicationPart, but no luck there. I'm thinking it has to do with the pattern I'm using for registering services in separate assemblies.
81 replies