![]() ![]() In the following test the Callback method is used to set the ref value. In the preceding code, the return value is being set, but nowhere is the ref int output “return value” being configured. Var result = sut.ConvertStringIntToHex("255") Īssert.Equal("FF", result) // Fails, actual result = 0 MockParser.Setup(x => x.TryParse(It.IsAny(), ref It.Ref.IsAny)) Public void ReturnHex_Fail_NoRefValueSetup() The following modified test attempts to fix this: The preceding test will fail however because the mocked TryParse has not been configured correctly, for example specifying that the method should return true. Var result = sut.ConvertStringIntToHex("255") // fails with ArgumentException ![]() In a test, a mocked version of an IParser can be created by Moq as the following initial test demonstrates: ![]() The Thing class requires an IParser to be able to work. Throw new ArgumentException("The value supplied cannot be parsed into an int.", nameof(number)) ![]() Public string ConvertStringIntToHex(string number) NET Core Unit Tests with Moq: Getting Started Pluralsight course asking how to set the values of ref parameters.Īs a (somewhat contrived) example, consider the following code: public interface IParserīool TryParse(string value, ref int output) I recently received a message related to my Mocking in. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |