public async Task BuildAsync() { if (!_messages.Any()) { throw new PactException("Cannot build pact. No messages."); } var pact = new MessageContract { Consumer = new Pacticipant { Name = _consumer }, Provider = new Pacticipant { Name = _provider }, Messages = _messages }; if (_pactDir != null) { PactWriter.Write(pact, _pactDir); } else { PactWriter.Write(pact); } if (_pactPublisher != null) { await _pactPublisher.PublishAsync(pact); } }
public void ShouldWritePactFile() { var pact = new Contract { Consumer = new Pacticipant { Name = "consumer" }, Provider = new Pacticipant { Name = "provider" }, Interactions = new List <Interaction> { new Interaction { Description = "TestInteraction", Request = new Request { Method = Method.GET, Path = "/", Headers = new Headers { { "Accept", "application/json" } } }, Response = new Response { Status = 200, Headers = new Headers { { "Content-Type", "application/json" } }, Body = new { id = Guid.NewGuid() } } } }, Metadata = new Metadata { PactSpecification = new PactSpecification { Version = "2.0.0" } } }; PactWriter.Write(pact); }
public async Task BuildAsync() { _cts.Cancel(); if (!_matchableInteractions.Any()) { throw new PactException("Cannot build pact. No interactions."); } if (!_matcher.AllHaveBeenMatched()) { throw new PactException("Cannot build pact. Not all mocked interactions have been called."); } var pact = new Contract { Consumer = new Pacticipant { Name = _consumer }, Provider = new Pacticipant { Name = _provider }, Interactions = _matchableInteractions.Select(m => m.Interaction as Interaction).ToList() }; if (_pactDir != null) { PactWriter.Write(pact, _pactDir); } else { PactWriter.Write(pact); } if (_pactPublisher != null) { await _pactPublisher.PublishAsync(pact); } }