diff --git a/doc/LibrarySplit/MigrationGuideForSplit.md b/doc/LibrarySplit/MigrationGuideForSplit.md index 827c7fe2b625..e83e8c0bbb08 100644 --- a/doc/LibrarySplit/MigrationGuideForSplit.md +++ b/doc/LibrarySplit/MigrationGuideForSplit.md @@ -94,4 +94,51 @@ using BarResource1 = BarPackage::Namespace.Resource1; var resourceFromFoo = new Resource1(); // From Foo v1.0.0 var resourceFromBar = new BarResource1(); // From Bar v1.0.0 -``` \ No newline at end of file +``` + +## Changes Required in Mocking + +When migrating to the split libraries, only the mocking of **extension methods** that have moved to the new package is impacted. Mocking of instance methods and extension methods that remain in the original package will continue to work without changes. + +If you are mocking an extension method that has moved, you will notice that the corresponding method on the original mockable resource (e.g. `MockableFooSubscriptionResource`) is now marked as `Obsolete`. The compiler warning will provide a message pointing to the new method location in the new package. + +For example, if you were previously mocking an extension method on `SubscriptionResource` that was part of `Foo`, you might have had code like this: + +```csharp +using Foo.Mocking; + +// ... + +var subscriptionMock = new Mock(); +var mockableSubscription = new Mock(); +// GetResource1s is now Obsolete and will generate a warning +mockableSubscription.Setup(x => x.GetResource1s(It.IsAny())) + .Returns(resource1CollectionMock.Object); + +subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny>())) + .Returns(mockableSubscription.Object); +``` + +You might see a warning like this: +> This method is obsolete. Call Bar.Mocking.MockableBarSubscriptionResource.GetResource1s instead. + +To fix this, you need to update your mocking code to use the mockable resource from the new package (e.g. `MockableBarSubscriptionResource`). Apart from updating the type name and the namespace, the method signatures remain the same, so no other logic changes are required. + +Here is an example of how to update your test code: + +```diff +- using Foo.Mocking; ++ using Bar.Mocking; + + // ... + + var subscriptionMock = new Mock(); +- var mockableSubscription = new Mock(); ++ var mockableSubscription = new Mock(); + mockableSubscription.Setup(x => x.GetResource1s(It.IsAny())) + .Returns(resource1CollectionMock.Object); + +- subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny>())) ++ subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny>())) + .Returns(mockableSubscription.Object); +```