Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion doc/LibrarySplit/MigrationGuideForSplit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```

## 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<SubscriptionResource>();
var mockableSubscription = new Mock<MockableFooSubscriptionResource>();
// GetResource1s is now Obsolete and will generate a warning
mockableSubscription.Setup(x => x.GetResource1s(It.IsAny<CancellationToken>()))
.Returns(resource1CollectionMock.Object);

subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny<Func<ArmClient, MockableFooSubscriptionResource>>()))
.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<SubscriptionResource>();
- var mockableSubscription = new Mock<MockableFooSubscriptionResource>();
+ var mockableSubscription = new Mock<MockableBarSubscriptionResource>();
mockableSubscription.Setup(x => x.GetResource1s(It.IsAny<CancellationToken>()))
.Returns(resource1CollectionMock.Object);

- subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny<Func<ArmClient, MockableFooSubscriptionResource>>()))
+ subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny<Func<ArmClient, MockableBarSubscriptionResource>>()))
.Returns(mockableSubscription.Object);
```