format icon indicating copy to clipboard operation
format copied to clipboard

dotnet format inserts invalid cast to delegate in moq code

Open timmydo opened this issue 3 years ago • 0 comments

Given the following code

        private static Mock<IAugmentationBuilderWorkflows> CreateAugmentationBuilderWorkflow(string workflow, IList<string> builders)
        {
            var augmentationBuilderWorkflowsMock = new Mock<IAugmentationBuilderWorkflows>();
            var workflows = new Dictionary<string, IAugmentationBuilderConfiguration>();
            var workflowMock = new Mock<IAugmentationBuilderConfiguration>();
            workflowMock.Setup(x => x.Name).Returns(workflow);
            workflowMock.Setup(x => x.Builders).Returns(builders);
            workflows.Add(workflow, workflowMock.Object);
            augmentationBuilderWorkflowsMock.Setup(x => x.Workflows).Returns(workflows);
            return augmentationBuilderWorkflowsMock;
        }

dotnet format inserts the following cast from Dictionary<K,V> to Delegate:

workflowMock.Setup(x => x.Builders).Returns((Delegate)builders);

I encountered this while ordering the using statements on > 6k files. This happened on about 8 files, which I found through git diff -G Delegate after unit tests on my build failed.

timmydo avatar Oct 21 '22 22:10 timmydo