67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using GerstITS.Examples.WebClients.Examples.Api;
|
|
using GerstITS.IoC.DotNetCore;
|
|
using GerstITS.Web.WebClients;
|
|
|
|
namespace GerstITS.Examples.WebClient.Console.Tests;
|
|
|
|
internal sealed class TestRunner : IApplicationStart
|
|
{
|
|
#region Fields
|
|
|
|
private readonly IWebClient _webClient;
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public TestRunner(IWebClient webClient)
|
|
{
|
|
_webClient = webClient;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IApplicationStart
|
|
|
|
public void Run()
|
|
{
|
|
var created = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.Create(new Customer
|
|
{ FirstName = "Erika", LastName = $"Mustermann-{Guid.NewGuid():N}", EMail = "erika.mustermann@example.com" }));
|
|
|
|
var loaded = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.Get(created.Value.Id));
|
|
|
|
var searched = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.Search(new CustomerSearchCriteria
|
|
{ Name = "Mustermann", SortBy = nameof(Customer.LastName), SortDirection = SortingDirections.Descending, Skip = 0, Take = 5 }));
|
|
|
|
loaded.Value.FirstName = "Max";
|
|
|
|
var updated = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.Update(loaded.Value));
|
|
|
|
var note = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.AddNote(updated.Value.Id, new CustomerNote { Text = "Created by the example web client." }));
|
|
|
|
var notes = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.GetNotes(updated.Value.Id));
|
|
|
|
var deleted = _webClient.Request<ICustomer>()
|
|
.Execute(c => c.Delete(updated.Value.Id));
|
|
|
|
Print($"---> {nameof(TestRunner)}: Found {searched.Value.TotalCount} customer(s), added {notes.Value.Count()} note(s), deleted: {deleted.Value}");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private static void Print(string message)
|
|
{
|
|
global::System.Console.WriteLine(message);
|
|
}
|
|
|
|
#endregion
|
|
}
|