public void Ctor_WithProviderState_SetsProviderStateDescription() { const string provideStateDescription = "my provider state"; var providerState = new ProviderState(provideStateDescription); Assert.Equal(provideStateDescription, providerState.ProviderStateDescription); }
public void Ctor_WithTearDownAction_SetsTearDownAction() { Action tearDown = () => { }; var providerState = new ProviderState("my provider state", tearDown: tearDown); Assert.Equal(tearDown, providerState.TearDown); }
public void Ctor_WithSetUpAction_SetsSetUpAction() { Action setUp = () => { }; var providerState = new ProviderState("my provider state", setUp: setUp); Assert.Equal(setUp, providerState.SetUp); }
public void Add_WithAndAlreadyAddedProviderState_ThrowsArgumentException() { const string providerStateDescription = "my provider state"; var providerState1 = new ProviderState(providerStateDescription); var providerState2 = new ProviderState(providerStateDescription); var providerStates = new ProviderStates(); providerStates.Add(providerState1); Assert.Throws<ArgumentException>(() => providerStates.Add(providerState2)); }
public void Add_WithProviderState_AddsProviderState() { const string providerStateDescription = "my provider state"; var providerState = new ProviderState(providerStateDescription); var providerStates = new ProviderStates(); providerStates.Add(providerState); Assert.Equal(providerState, providerStates.Find(providerStateDescription)); }
public void Add(ProviderState providerState) { _providerStates = _providerStates ?? new List <ProviderState>(); if (_providerStates.Any(x => x.ProviderStateDescription == providerState.ProviderStateDescription)) { throw new ArgumentException(String.Format("providerState '{0}' has already been added", providerState.ProviderStateDescription)); } _providerStates.Add(providerState); }
public void Add(ProviderState providerState) { _providerStates = _providerStates ?? new List<ProviderState>(); if (_providerStates.Any(x => x.ProviderStateDescription == providerState.ProviderStateDescription)) { throw new ArgumentException(String.Format("providerState \"{0}\" has already been added", providerState.ProviderStateDescription)); } _providerStates.Add(providerState); }
public void Find_WithProviderStateThatHasBeenAdded_ReturnsProviderState() { const string providerStateDescription = "my provider state 2"; var providerState1 = new ProviderState("my provider state"); var providerState2 = new ProviderState(providerStateDescription); var providerStates = new ProviderStates(); providerStates.Add(providerState1); providerStates.Add(providerState2); var actualProviderState = providerStates.Find(providerStateDescription); Assert.Equal(providerState2, actualProviderState); }
public void Find_WithProviderStateThatDoesNotMatchProviderStates_ReturnsNull() { const string providerStateDescription = "my provider state 2"; var providerState1 = new ProviderState("my provider state"); var providerState2 = new ProviderState(providerStateDescription); var providerStates = new ProviderStates(); providerStates.Add(providerState1); providerStates.Add(providerState2); var actualProviderState = providerStates.Find("something else"); Assert.Null(actualProviderState); }
public IProviderStates ProviderState(string providerState, Action setUp = null, Action tearDown = null) { if (ProviderStates == null) { throw new InvalidOperationException("Please intitialise the provider states by first calling the ProviderStatesFor method"); } if (String.IsNullOrEmpty(providerState)) { throw new ArgumentException("Please supply a non null or empty providerState"); } var providerStateItem = new ProviderState(providerState, setUp, tearDown); ProviderStates.Add(providerStateItem); return this; }
private void InvokeProviderStateTearDownIfApplicable(ProviderState providerState) { if (providerState != null && providerState.TearDown != null) { providerState.TearDown(); } }
private void InvokeProviderStateSetUpIfApplicable(ProviderState providerState) { if (providerState != null && providerState.SetUp != null) { providerState.SetUp(); } }
/// <summary> /// Define a set up and/or tear down action for a specific state specified by the consumer. /// This is where you should set up test data, so that you can fulfil the contract outlined by a consumer. /// </summary> /// <param name="providerState">The name of the provider state as defined by the consumer interaction, which lives in the Pact file.</param> /// <param name="setUp">A set up action that will be run before the interaction verify, if the provider has specified it in the interaction. If no action is required please use an empty lambda () => {}.</param> /// <param name="tearDown">A tear down action that will be run after the interaction verify, if the provider has specified it in the interaction. If no action is required please use an empty lambda () => {}.</param> public IPactVerifier ProviderState(string providerState, Action setUp = null, Action tearDown = null) { if (String.IsNullOrEmpty(providerState)) { throw new ArgumentException("Please supply a non null or empty providerState"); } var providerStateItem = new ProviderState(providerState, setUp, tearDown); ProviderStates.Add(providerStateItem); return this; }