public async Task CalculatePriceForAmerica() { // Arrange / Given var orchContext = new SagaContext { Continent = "North America" }; var context = new Mock <IDurableOrchestrationContext>(); // mock the get input context.Setup(m => m.GetInput <SagaContext>()).Returns(orchContext); //set-up mocks for activities context.Setup(m => m.CallActivityAsync <bool>("IsContinentSupported", It.IsAny <object>())) .ReturnsAsync(true); // set-up mocks for activity context.Setup(m => m.CallActivityAsync <string>("GetSupplierOrchestratorForContinent", It.IsAny <object>())) .ReturnsAsync("CourierA"); // set-up mocks for suborchstrators context.Setup(m => m.CallSubOrchestratorAsync <decimal>("CourierAOrchestrator", It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(100); // ACT / When var price = await SagaToTestOrchestrator.RunOrchestrator(context.Object); // Assert / Then Assert.True(price.Shippable); Assert.Equal(100, price.Price); }
public async Task CalculatePriceForEurope() { // Arrange / Given var orchContext = new SagaContext { Continent = "Europe" }; var context = new Mock <IDurableOrchestrationContext>(); // mock the get input context.Setup(m => m.GetInput <SagaContext>()).Returns(orchContext); //set-up mocks for activities context.Setup(m => m.CallActivityAsync <bool>("IsContinentSupported", It.IsAny <object>())) .ReturnsAsync(true); // set-up mocks for activity context.Setup(m => m.CallActivityAsync <string>("GetSupplierOrchestratorForContinent", It.IsAny <object>())) .ReturnsAsync("CourierB"); // set-up mocks for suborchstrators context.Setup(m => m.CallSubOrchestratorAsync <decimal>("CourierAOrchestrator", It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(100); context.Setup(m => m.CallSubOrchestratorAsync <decimal>("CourierBOrchestrator", It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(120); // mock the publish activity // at the time of writing, there is no way of mocking CallActivityAsync so we need to use the generic version context.Setup(m => m.CallActivityAsync <object>("PublishCalculatedPriceActivity", It.IsAny <object>()) ); // ACT / When var price = await SagaToTestOrchestrator.RunOrchestrator(context.Object); // Assert / Then context.Verify( m => m.CallActivityAsync <bool>( "IsContinentSupported", It.IsAny <object>()), Times.Once); context.Verify( m => m.CallActivityAsync <string>( "GetSupplierOrchestratorForContinent", It.IsAny <object>()), Times.Once ); context.Verify(m => m.CallSubOrchestratorAsync <decimal>("CourierAOrchestrator", It.IsAny <string>(), It.IsAny <object>()), Times.Never); context.Verify(m => m.CallSubOrchestratorAsync <decimal>("CourierBOrchestrator", It.IsAny <string>(), It.IsAny <object>()), Times.Once); context.Verify(m => m.CallActivityAsync <object>("PublishCalculatedPriceActivity", It.IsAny <object>()), Times.Once ); }
public async Task TestUsingTheory(OrchestratorTestParams pTestParams) { // Arrange / Given var orchContext = new SagaContext { Continent = pTestParams.Continent }; var context = new Mock <IDurableOrchestrationContext>(); // mock the get input context.Setup(m => m.GetInput <SagaContext>()).Returns(orchContext); //set-up mocks for activities context.Setup(m => m.CallActivityAsync <bool>("IsContinentSupported", It.IsAny <object>())) .ReturnsAsync(pTestParams.IsContinentSupported); // set-up mocks for activity context.Setup(m => m.CallActivityAsync <string>("GetSupplierOrchestratorForContinent", It.IsAny <object>())) .ReturnsAsync(pTestParams.SupplierToBeReturnedFromContinentOrchestrator); // set-up mocks for suborchstrators context.Setup(m => m.CallSubOrchestratorAsync <decimal>("CourierAOrchestrator", It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(pTestParams.ValueForCourierA); context.Setup(m => m.CallSubOrchestratorAsync <decimal>("CourierBOrchestrator", It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(pTestParams.ValueForCourierB); // mock the publish activity // at the time of writing, there is no way of mocking CallActivityAsync so we need to use the generic version context.Setup(m => m.CallActivityAsync <object>("PublishCalculatedPriceActivity", It.IsAny <object>()) ); // ACT / When var price = await SagaToTestOrchestrator.RunOrchestrator(context.Object); // Assert / Then context.Verify( m => m.CallActivityAsync <bool>( "IsContinentSupported", It.IsAny <object>()), pTestParams.IsContinentSupportedCalledTimes); context.Verify( m => m.CallActivityAsync <string>( "GetSupplierOrchestratorForContinent", It.IsAny <object>()), pTestParams.GetSupplierOrchestratorForContinentCalledTimes ); context.Verify(m => m.CallSubOrchestratorAsync <decimal>("CourierAOrchestrator", It.IsAny <string>(), It.IsAny <object>()), pTestParams.CourierAOrchestratorCalledTimes); context.Verify(m => m.CallSubOrchestratorAsync <decimal>("CourierBOrchestrator", It.IsAny <string>(), It.IsAny <object>()), pTestParams.CourierBOrchestratorCalledTimes); context.Verify(m => m.CallActivityAsync <object>("PublishCalculatedPriceActivity", It.IsAny <object>()), pTestParams.PublishCalculatedPriceActivityCalledTimes ); }