public void PerformFunction_SingleActiveGate_ShouldPerformScopedFunctionForActiveGate() { IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext()); int result = gateContext.PerformFunction(Gates.GetGate("ActiveGate1"), () => { return(1); }); Assert.Equal(result, 1); Assert.True(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")), "Expected one gate to be activated"); }
public void PerformFunction_SingleInactiveGate_ShouldNotPerformScopedFunctionForInactiveGate() { IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext()); int result = gateContext.PerformFunction(Gates.GetGate("InactiveGate1"), () => { return(1); }); Assert.Equal(result, 0); Assert.Equal(gateContext.ActivatedGates.Count(), 0); }
public void PerformFunction_WithOnlyInactiveGates_ShouldReturnDefaultOfType() { IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext()); int count = gateContext.PerformFunction <int>( new GatedFunc <int>(Gates.GetGate("InactiveGate1"), () => { Assert.False(true, "Should not perform function for inactive gate."); return(1); }), new GatedFunc <int>(Gates.GetGate("InactiveGate2"), () => { Assert.False(true, "Should not perform function for inactive gate."); return(4); })); Assert.Equal(count, default(int)); }
public void PerformFunction_WithUnscopedModeAndMultipleActiveAndInactiveGates_ShouldPerformUnscopedFunctionForFirstActiveGate() { IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext()); int count = gateContext.PerformFunction <int>(GatedCode.Modes.None, new GatedFunc <int>(Gates.GetGate("InactiveGate1"), () => { Assert.False(true, "Should not perform function for inactive gate."); return(1); }), new GatedFunc <int>(Gates.GetGate("ActiveGate1"), () => { return(2); }), new GatedFunc <int>(Gates.GetGate("ActiveGate2"), () => { Assert.False(true, "Should not perform function for second active gate."); return(3); }), new GatedFunc <int>(Gates.GetGate("InactiveGate2"), () => { Assert.False(true, "Should not perform function for inactive gate."); return(4); }), new GatedFunc <int>( () => { Assert.False(true, "Should not perform function for base line."); return(5); })); Assert.Equal(count, 2); Assert.False(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")), "Expected no Gates reported as activated"); }
public void PerformAsyncFunction_WithMultipleActiveAndInactiveGates_ShouldPerformScopedFunctionForFirstActiveGate() { VerifyAsync(async() => { IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext()); int count = await gateContext.PerformFunction <int>( new GatedAsyncFunc <int>(Gates.GetGate("InactiveGate1"), () => { Assert.False(true, "Should not perform function for inactive gate."); return(Task.FromResult(1)); }), new GatedAsyncFunc <int>(Gates.GetGate("ActiveGate1"), () => Task.FromResult(2)), new GatedAsyncFunc <int>(Gates.GetGate("ActiveGate2"), () => { Assert.False(true, "Should not perform function for second active gate."); return(Task.FromResult(3)); }), new GatedAsyncFunc <int>(Gates.GetGate("InactiveGate2"), () => { Assert.False(true, "Should not perform function for inactive gate."); return(Task.FromResult(4)); }), new GatedAsyncFunc <int>( () => { Assert.False(true, "Should not perform function for base line."); return(Task.FromResult(5)); })); Assert.Equal(count, 2); Assert.True(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")), "Expected one gate to be activated"); }); }