Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        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));
        }
Exemple #5
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);
        }
Exemple #6
0
 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));
 }
Exemple #7
0
        public static WorkflowPacket UseHeader(this WorkflowPacket wp, Dictionary <string, string> headers)
        {
            wp.Headers = headers;

            return(wp);
        }
Exemple #8
0
        public static WorkflowPacket Log(this WorkflowPacket wp, string msg)
        {
            Debug.WriteLine(msg);

            return(wp);
        }
Exemple #9
0
 public static WorkflowPacket IGet <T>(this WorkflowPacket wp, Action <T> getter) where T : class
 {
     return(wp.IGet(typeof(T).Name, getter));
 }
Exemple #10
0
 public static WorkflowPacket Patch <T>(this WorkflowPacket wp, string route, object data) where T : new()
 {
     return(wp.Patch <T>(typeof(T).Name, route, data));
 }
Exemple #11
0
 public static WorkflowPacket Get <T>(this WorkflowPacket wp, string route) where T : new()
 {
     return(wp.Get <T>(typeof(T).Name, route));
 }