Skip to content

Commit

Permalink
#188 adding casts looks like it fixed things, so I can finally put th…
Browse files Browse the repository at this point in the history
…is issue to rest.
  • Loading branch information
JasonBock committed Oct 10, 2022
1 parent fb4f28b commit 8fff9cd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [7.0.0-alpha.2] - Not Yet Released

### Fixed
- Generated shim types to handle DIM invocations have been updated to remove a couple of errors (issue [#188](https://github.com/JasonBock/Rocks/issues/188))
- If Rocks encounters the `AsyncIteratorStateMachineAttribute`, it will not generate its description in the mock (issue [#185](https://github.com/JasonBock/Rocks/issues/185))
- Async iterators are now handled correctly (issue [#191](https://github.com/JasonBock/Rocks/issues/191))
- Members that use obsolete types will flag the type to mock as unmockable (issue [#182](https://github.com/JasonBock/Rocks/issues/182))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public static class Test
}
```

Rocks will make a shim that will not implement `IAmADim()` as expected, but it needs to implement `IAmNotADim()`. Otherwise I get `CS0535`. So, I need to look at all the non-DIM members of an interface, and provide "make" implementations of them that do nothing. They will **never** be called by Rocks because will either try to match an handler to the invocation, or throw an exception, so they can essentially do nothing like what happens in a make, but they still need to show up in the shim type.
Rocks will make a shim that will not implement `IAmADim()` as expected, but it needs to implement `IAmNotADim()`. Otherwise I get `CS0535`. So, I need to look at all the non-DIM members of an interface, and provide "make" implementations of them that do nothing. They will **never** be called by Rocks because will either try to match an handler to the invocation, or throw an exception, so they can essentially do nothing like what happens in a make, but they still need to show up in the shim type.

OK, forget that idea :). That didn't work. All the tests pass, and the one case in EF that isn't working is due to some really weird resolution error between calling a property and calling an extension method. I **could** add a cast to what the thing should be anyway, and that would get rid of it...ok, maybe try that.

FINALLY! Putting the cast in gets rid of the EF error I was seeing, and all tests still pass. I'm done with this for now.
6 changes: 3 additions & 3 deletions src/Rocks.Tests/Generators/ShimBuilderGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ public ShimIHaveDims531557381186657891604647139828315705947108387206(RockIHaveDi
this.mock = @mock;

public int IAmNotADim() =>
this.mock.IAmNotADim();
((global::IHaveDims)this.mock).IAmNotADim();

public int NotDim
{
get => this.mock.NotDim;
get => ((global::IHaveDims)this.mock).NotDim;
}

public int this[string @notDimKey]
{
get => this.mock[@notDimKey];
get => ((global::IHaveDims)this.mock)[@notDimKey];
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rocks/Builders/Shim/ShimIndexerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ internal static void Build(IndentedTextWriter writer, Compilation compilation, M
accessors == PropertyAccessor.GetAndSet)
{
var refReturn = indexer.ReturnsByRef || indexer.ReturnsByRefReadonly ? "ref " : string.Empty;
writer.WriteLine($"get => {refReturn}this.mock[{parameters}];");
writer.WriteLine($"get => {refReturn}(({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock)[{parameters}];");
}

if (accessors == PropertyAccessor.Set || accessors == PropertyAccessor.GetAndSet)
{
writer.WriteLine($"set => this.mock[{parameters}] = value;");
writer.WriteLine($"set => (({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock)[{parameters}] = value;");
}

if (accessors == PropertyAccessor.Init || accessors == PropertyAccessor.GetAndInit)
{
writer.WriteLine($"init => this.mock[{parameters}] = value;");
writer.WriteLine($"init => (({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock)[{parameters}] = value;");
}

writer.Indent--;
Expand Down
2 changes: 1 addition & 1 deletion src/Rocks/Builders/Shim/ShimMethodBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal static void Build(IndentedTextWriter writer, Compilation compilation, M
};
return $"{direction}@{_.Name}";
}));
writer.WriteLine($"this.mock.{shimMethod.GetName()}({passedParameters});");
writer.WriteLine($"(({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock).{shimMethod.GetName()}({passedParameters});");
writer.Indent--;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rocks/Builders/Shim/ShimPropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ internal static void Build(IndentedTextWriter writer, Compilation compilation, M
accessors == PropertyAccessor.GetAndSet)
{
var refReturn = property.ReturnsByRef || property.ReturnsByRefReadonly ? "ref " : string.Empty;
writer.WriteLine($"get => {refReturn}this.mock.{property.Name};");
writer.WriteLine($"get => {refReturn}(({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock).{property.Name};");
}

if (accessors == PropertyAccessor.Set || accessors == PropertyAccessor.GetAndSet)
{
writer.WriteLine($"set => this.mock.{property.Name} = value;");
writer.WriteLine($"set => (({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock).{property.Name} = value;");
}

if (accessors == PropertyAccessor.Init || accessors == PropertyAccessor.GetAndInit)
{
writer.WriteLine($"init => this.mock.{property.Name} = value;");
writer.WriteLine($"init => (({shimInformation.TypeToMock!.Type.GetReferenceableName()})this.mock).{property.Name} = value;");
}

writer.Indent--;
Expand Down

0 comments on commit 8fff9cd

Please sign in to comment.