Last active
February 13, 2020 17:44
-
-
Save spettifer/51ba4f7a3ccd80069e3fb7a0502374b3 to your computer and use it in GitHub Desktop.
A very contrived example of using a test double for CloudTable using NSubstitute in a unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is not runnable as is, but shows the basic principle. Note that the cloud table test double is being used as a stub, | |
// not a spy or a mock, although it could fulfill either of those roles with additional setup if required. | |
[Fact] | |
public async Task ExampleUnitTestWithCloudTableTestDouble() | |
{ | |
var testResult = new TableResult | |
{ | |
Result = new MyEntity() | |
{ | |
ETag = "*", | |
PartitionKey = "PartitionKey", | |
RowKey = "RowKey", | |
MyProperty = "SomeValue" | |
}, | |
HttpStatusCode = 200 | |
}; | |
var subCloudTable = Substitute.For<CloudTable>(new Uri("tempuir.org")); | |
subCloudTable.ExecuteAsync(Arg.Any<TableOperation>()).Returns(testResult); | |
var actual = await sut.DoSomething(subCloudTable); | |
actual.Should().Be(expected); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment