Skip to content

Commit 9edcd2a

Browse files
update the migration guide (#54185)
1 parent b06f430 commit 9edcd2a

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

doc/LibrarySplit/MigrationGuideForSplit.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,51 @@ using BarResource1 = BarPackage::Namespace.Resource1;
9494

9595
var resourceFromFoo = new Resource1(); // From Foo v1.0.0
9696
var resourceFromBar = new BarResource1(); // From Bar v1.0.0
97-
```
97+
```
98+
99+
## Changes Required in Mocking
100+
101+
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.
102+
103+
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.
104+
105+
For example, if you were previously mocking an extension method on `SubscriptionResource` that was part of `Foo`, you might have had code like this:
106+
107+
```csharp
108+
using Foo.Mocking;
109+
110+
// ...
111+
112+
var subscriptionMock = new Mock<SubscriptionResource>();
113+
var mockableSubscription = new Mock<MockableFooSubscriptionResource>();
114+
// GetResource1s is now Obsolete and will generate a warning
115+
mockableSubscription.Setup(x => x.GetResource1s(It.IsAny<CancellationToken>()))
116+
.Returns(resource1CollectionMock.Object);
117+
118+
subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny<Func<ArmClient, MockableFooSubscriptionResource>>()))
119+
.Returns(mockableSubscription.Object);
120+
```
121+
122+
You might see a warning like this:
123+
> This method is obsolete. Call Bar.Mocking.MockableBarSubscriptionResource.GetResource1s instead.
124+
125+
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.
126+
127+
Here is an example of how to update your test code:
128+
129+
```diff
130+
- using Foo.Mocking;
131+
+ using Bar.Mocking;
132+
133+
// ...
134+
135+
var subscriptionMock = new Mock<SubscriptionResource>();
136+
- var mockableSubscription = new Mock<MockableFooSubscriptionResource>();
137+
+ var mockableSubscription = new Mock<MockableBarSubscriptionResource>();
138+
mockableSubscription.Setup(x => x.GetResource1s(It.IsAny<CancellationToken>()))
139+
.Returns(resource1CollectionMock.Object);
140+
141+
- subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny<Func<ArmClient, MockableFooSubscriptionResource>>()))
142+
+ subscriptionMock.Setup(x => x.GetCachedClient(It.IsAny<Func<ArmClient, MockableBarSubscriptionResource>>()))
143+
.Returns(mockableSubscription.Object);
144+
```

0 commit comments

Comments
 (0)