-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
310 fallback service provider #315
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #315 +/- ##
==========================================
+ Coverage 81.40% 81.51% +0.11%
==========================================
Files 126 126
Lines 3765 3777 +12
Branches 491 493 +2
==========================================
+ Hits 3065 3079 +14
+ Misses 541 540 -1
+ Partials 159 158 -1
Continue to review full report at Codecov.
|
docs/site/docs/providing-input/inject-services-into-components.md
Outdated
Show resolved
Hide resolved
docs/site/docs/providing-input/inject-services-into-components.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. There are still a few test cases missing, as far as I can see. These are a few suggestions from the related issue:
- when no fall back is added, the base service provider is used
- when a fallback provider is added, the result from service provider is used when it is not null
- when a fallback provider is added, it is called when the service provider returns null
- if multipel fallbacks are added, only the latest is used
- adding null as fallback throws argument null exception
Your right, thanks for the feedback, ill add them tonight / this weekend. |
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Co-authored-by: Egil Hansen <egil@assimilated.dk>
…dev/bUnit into 310-FallbackServiceProvider
@egil I processed all you feedback but now one of the test fails. Is this something i should look at? |
No, that is a race condition bug i am having a hard time reproducing locally, and have so far only seen here when running with GitHub actions. It is unrelated to this. |
Then i think i got every thing done except for the changelog. Or is their anything else you would like to see improved? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we are there. I am only nitpicking at this point. Did push an update to the docs section though, there was some docs build errors that I fixed, and added a bit more prosa to it.
I will also add the Packt editor who is helping with the docs to have him give the added docs a quick read through.
Hey @ventigrande, Do you mind taking a look at the updated doc page in this PR. Here is a link with just the .md files visible in the Files Changed tab. |
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Co-authored-by: Egil Hansen <egil@assimilated.dk>
Everything looks good to me. Ill give wait with the merge until @ventigrande has had a chance to review the doc changes. Thanks for your contribution @thopdev! |
@egil Sounds good. Thanks for all the help and feedback. |
docs/site/docs/providing-input/inject-services-into-components.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Alex Powell <ap1@fastmail.com>
@ventigrande Thanks for the feedback. |
Thank you @ventigrande. One last thing @thopdev was needed. I updated the changelog file, let me know what you think. |
Sounds good! |
@egil @thopdev I am new to bUnit but not to AutoFixture and XUnit. I could you please help me understand how to use/implement a FallbackServiceProvider using AutoFixture and Moq? I can't even seem to get the code from this Discussion to work. But maybe this code isn't needed now that you have allowed for a FallbackServiceProvider. I did this but hopefully you tell me there's an easier way 🤞 private class AutoFixtureServiceProvider : IServiceProvider
{
private readonly IFixture _fixture;
private readonly Dictionary<Type, object> _mockedTypes = new();
public AutoFixtureServiceProvider(IFixture fixture)
{
_fixture = fixture;
}
private object? GetMockedService(Type serviceType)
{
if (!_mockedTypes.TryGetValue(serviceType, out var service))
{
var createMethod =
typeof(SpecimenFactory).GetMethod(nameof(SpecimenFactory.Create), new[] { typeof(ISpecimenBuilder) });
var typedGeneric = createMethod?.MakeGenericMethod(serviceType);
service = typedGeneric?.Invoke(null, new object?[] { _fixture });
_mockedTypes.Add(serviceType, service!);
}
return service;
}
/// <inheritdoc />
public object? GetService(Type serviceType)
{
return GetMockedService(serviceType);
}
} Any guidance would be greatly appreciated. Thanks!! |
Hi @mwasson74 The service provider looks correct. Could you share one test class that shows bunit. |
Thanks for getting back to me, @thopdev! Below, you'll find our test class with 1 bUnit test. It is working but I'll likely create an extension method to retrieve the Mock instead of doing Mock.Get(). But ideally, I could just have that mock instance given to me as a test method parameter like you did in your #307... public class ClientSearchTests : TestContext
{
private readonly IFixture _fixture;
public ClientSearchTests()
{
_fixture = new Fixture();
_fixture.Customize(new AutoMoqCustomization { ConfigureMembers = true });
JSInterop.Mode = JSRuntimeMode.Loose;
Services.AddMudServices();
Services.AddFallbackServiceProvider(new AutoFixtureServiceProvider(_fixture));
}
[Theory, AutoMoqData]
public void MyLittleTest(string clientCode)
{
//Actors
var cut = RenderComponent<ClientSearch>(parameters =>
parameters.Add(p => p.SearchCriteria, clientCode));
var mockClient = Mock.Get(Services.GetService<IClientManagementClient>()!);
//Acts
cut.Find("button").Click();
//Asserts
mockClient?.Verify(x => x.GetClient, Times.Once);
}
} |
Pull request description
PR meta checklist
DEV
branch.Content checklist