public static WorkflowPacket Post <T>(this WorkflowPacket wp, string name, string route, object data) where T : new() { wp.Log($"POST: {typeof(T).Name} {route}"); var resp = RestService.Post <T>($"{wp.BaseUrl}/{route}", data, wp.Headers); wp.LastResponse = resp.status; wp.LastContent = resp.content; wp.SetObject(name, resp.item); return(wp); }
public static WorkflowPacket Login(this WorkflowPacket wp, string username = "******", string password = "******") { string token = null; wp .Post <LoginResponse>("account/login", new { username, password }) .AndOk() .Then(wp => token = wp.GetObject <LoginResponse>().AccessToken) .UseHeader("Authorization", $"Bearer {token}"); return(wp); }
public void UserCannotCreateEntityTest() { ClearAllTables(); var wp = new WorkflowPacket(URL) .CreateUserAndEntityRole("Test", "Marc", "fizbin", "CreateEntityRole", new Permissions() { CanRead = true }) .Login("Marc", "fizbin") .Post <Test>("entity/test", testData) .AndForbidden(); }
public void UserCanCreateEntityTest() { ClearAllTables(); var wp = new WorkflowPacket(URL) .CreateUserAndEntityRole("Test", "Marc", "fizbin", "CreateEntityRole", new Permissions() { CanCreate = true }) .Login("Marc", "fizbin") .Post <Test>("entity/test", testData) .AndOk() .IShouldSee <Test>(t => t.ID.Should().NotBe(0)); }
public static WorkflowPacket CreateUserAndEntityRole(this WorkflowPacket wp, string entity, string username, string password, string roleName, Permissions permissions) { int roleId = -1; int entityId = -1; int userId = -1; wp .Login() .Post <User>("account", new { username, password }) .AndOk() .IShouldSee <User>(u => u.Id.Should().NotBe(0)) .IGet <User>(u => userId = u.Id) .Log($"User ID = {userId}") .Post <Role>("entity/role", new { Name = roleName, CanCreate = permissions.CanCreate, CanRead = permissions.CanRead, CanUpdate = permissions.CanUpdate, CanDelete = permissions.CanDelete, }) .AndOk() .IShouldSee <Role>(r => r.Id.Should().NotBe(0)) .IGet <Role>(r => roleId = r.Id) .Post <Entity>("entity/entity", new { TableName = entity }) .AndOk() .IShouldSee <Entity>(e => e.Id.Should().NotBe(0)) .IGet <Entity>(e => entityId = e.Id) // Map EntityRole and UserRole. .Post <UserRole>("entity/userrole", new { RoleId = roleId, UserId = userId }) .AndOk() .IShouldSee <UserRole>(ur => ur.Id.Should().NotBe(0)) .Post <EntityRole>("entity/entityrole", new { RoleId = roleId, EntityId = entityId }) .AndOk() .IShouldSee <EntityRole>(er => er.Id.Should().NotBe(0)); return(wp); }
public static WorkflowPacket IShouldSee <T>(this WorkflowPacket wp, Action <T> test) where T : class { wp.Log($"IShouldSee {typeof(T).Name}"); return(wp.IShouldSee(typeof(T).Name, test)); }
public static WorkflowPacket UseHeader(this WorkflowPacket wp, Dictionary <string, string> headers) { wp.Headers = headers; return(wp); }
public static WorkflowPacket Log(this WorkflowPacket wp, string msg) { Debug.WriteLine(msg); return(wp); }
public static WorkflowPacket IGet <T>(this WorkflowPacket wp, Action <T> getter) where T : class { return(wp.IGet(typeof(T).Name, getter)); }
public static WorkflowPacket Patch <T>(this WorkflowPacket wp, string route, object data) where T : new() { return(wp.Patch <T>(typeof(T).Name, route, data)); }
public static WorkflowPacket Get <T>(this WorkflowPacket wp, string route) where T : new() { return(wp.Get <T>(typeof(T).Name, route)); }