public async Task <Test> AuthenticatePlatformClient(Test parent) { var test = await TestLogic.CreateAsync("AuthenticatePlatformClient", parent); try { FulcrumApplication.Context.CorrelationId = test.Id; var result = await _apiRestClient.CreateToken(_platformSettings.ClientId, _platformSettings.ClientSecret); if (string.IsNullOrWhiteSpace(result?.AccessToken)) { await TestLogic.SetStateAsync(test, StateEnum.Failed, $"Could not authenticate client '{_platformSettings.ClientId}"); } else { await TestLogic.SetStateAsync(test, StateEnum.Ok, "Ok"); } } catch (Exception e) { await TestLogic.SetStateAsync(test, StateEnum.Failed, e.Message); } return(test); }
public async Task <Test> OrderCreatedEvent(Test parent) { var test = await TestLogic.CreateAsync("OrderCreatedEvent", parent); var createTest = await TestLogic.CreateAsync("Create", test); var eventTest = await TestLogic.CreateAsync("Event", test); try { FulcrumApplication.Context.CorrelationId = eventTest.Id; var order = await _restclient.CreateOrder(new MockOrder { Id = "1", Items = 3 }); if (order?.Id == null) { throw new Exception("No Order was created"); } createTest.Properties = new Dictionary <string, object> { { "Order", order } }; await TestLogic.UpdateAsync(createTest); await TestLogic.SetStateAsync(createTest, StateEnum.Ok, "Order created"); } catch (Exception e) { await TestLogic.SetStateAsync(test, StateEnum.Failed, e.Message); } // Note! We leave the state as Waiting and set to Ok once the event is intercepted in IntegrationApiController return(test); }
public async Task <Test> Test2(Test parent) { var test = await TestLogic.CreateAsync("Capability Y Test 2", parent); // TODO: Do test and update state await TestLogic.SetStateAsync(test, StateEnum.Ok, "Done"); return(test); }
public async Task <Test> EnumTranslation(Test parent) { var test = await TestLogic.CreateAsync("EnumTranslation", parent); var cap1Test = await TestLogic.CreateAsync("Capability 1", test); var cap2Test = await TestLogic.CreateAsync("Capability 2", test); try { // Create order as capability 1 client var createdOrder = await _bapiClientAsCapability1Client.CreateOrder(3, "Created"); cap1Test.Properties = new Dictionary <string, object> { { "Order", createdOrder } }; await TestLogic.UpdateAsync(cap1Test); if (createdOrder.Status != "Created") { await TestLogic.SetStateAsync(cap1Test, StateEnum.Failed, "Expected Order.Status to be 'Created'"); } else { await TestLogic.SetStateAsync(cap1Test, StateEnum.Ok, "Ok"); } // Fetch order as capability 2 client var order = await _bapiClientAsCapability2Client.GetOrder(createdOrder.Id); cap2Test.Properties = new Dictionary <string, object> { { "Order", order } }; await TestLogic.UpdateAsync(cap2Test); if (order.Status != "New") { await TestLogic.SetStateAsync(cap2Test, StateEnum.Failed, "Expected Order.Status to be 'New'"); } else { await TestLogic.SetStateAsync(cap2Test, StateEnum.Ok, "Ok"); } } catch (Exception e) { await TestLogic.SetStateAsync(test, StateEnum.Failed, e.Message); } return(test); }
public async Task <Test> CreatePerson(Test parent) { var test = await TestLogic.CreateAsync("CrudPerson", parent); try { // Create var person = await _restclient.CreatePerson(new MockPerson { Name = "Raginaharjar" }); if (person?.Id == null) { throw new Exception("No Person was created"); } var personId = person.Id; test.Properties = new Dictionary <string, object> { { "Person", person } }; await TestLogic.UpdateAsync(test); // Read person = await _restclient.GetPerson(personId); if (person?.Id == null) { throw new Exception($"Person {personId} could not be found"); } // TODO: Update // Delete await _restclient.DeletePerson(personId); person = await _restclient.GetPerson(personId); if (person != null) { throw new Exception($"Person {personId} should be deleted"); } // All ok! await TestLogic.SetStateAsync(test, StateEnum.Ok, "ok"); } catch (Exception e) { await TestLogic.SetStateAsync(test, StateEnum.Failed, e.Message); } return(test); }
private async Task <Test> RunTopLevelTestAsync(Test parent, string group) { var container = await TestLogic.CreateAsync(group, parent); try { var testables = FindTestables(group); await RunTestablesOnlyRunAllAsync(container, testables); } catch (Exception e) { await TestLogic.SetStateAsync(container, StateEnum.Failed, e.Message); } return(container); }
public async Task Test1Callback(Event1 payload) { // Get the test var testId = FulcrumApplication.Context.CorrelationId; if (string.IsNullOrWhiteSpace(testId)) { Log.LogError($"There was no correlation id. Payload was {JsonSerializer.Serialize(payload)}."); return; } var test = await TestLogic.GetAsync(testId); if (test == null) { Log.LogError($"There was no test with id {testId}. Payload was {JsonSerializer.Serialize(payload)}."); return; } // Check with the Nexus Business Events test bench var md = payload.MetaData; var result = await _businessEventsClient.TestBenchPublish(md.EntityName, md.EventName, md.MajorVersion, md.MinorVersion, md.PublisherName, JToken.FromObject(payload)); if (result.Verified) { await TestLogic.SetStateAsync(test, StateEnum.Ok, "Event verified with BE Test bench"); } else { var message = string.Join(", ", result.Errors) + $" | Contract: {JsonConvert.SerializeObject(result.Contract)}" + $" | Payload: {JsonConvert.SerializeObject(result.Payload)}"; await TestLogic.SetStateAsync(test, StateEnum.Failed, message); } // Check translation if (payload.Person?.Gender != "male") { await TestLogic.SetStateAsync(test, StateEnum.Failed, $"Expected {nameof(Event1.Person.Gender)} to be 'male', but was '{payload.Person?.Gender}'"); } else { await TestLogic.SetStateAsync(test, StateEnum.Ok, $"Event subscribed by {Startup.ApiName}"); } }