Ejemplo n.º 1
0
        // ReSharper disable PossibleMultipleEnumeration
        public async Task RunAsync(IRestContext context)
        {
            ISystemApi systemApi = context.Factory.CreateSystemApi();

            IEnumerable <ScriptResponse> scripts = await systemApi.GetScriptsAsync(true);

            Console.WriteLine("GetScriptsAsync(): {0}", scripts.Select(x => x.script_id).ToStringList());

            if (scripts.Any(x => x.script_id == ScriptId))
            {
                await DeleteDummyScript(systemApi);
            }

            const string   scriptText = @"return Number(event.n1) + Number(event.n2);";
            ScriptResponse response   = await systemApi.WriteScriptAsync(ScriptId, scriptText);

            Console.WriteLine("WriteScriptAsync(): id={0}", response.script_id);

            Dictionary <string, object> p = new Dictionary <string, object> {
                { "n1", 3 }, { "n2", 5 }
            };
            string output = await systemApi.RunScriptAsync(ScriptId, p);

            Console.WriteLine("RunScriptAsync(): {0}", context.ContentSerializer.Serialize(output));

            await DeleteDummyScript(systemApi);
        }
Ejemplo n.º 2
0
        private static async Task DeleteRole(RoleResponse role, ISystemApi systemApi)
        {
            Debug.Assert(role.id.HasValue, "Role ID must be set");
            await systemApi.DeleteRolesAsync(role.id.Value);

            Console.WriteLine("DeleteRolesAsync():: id={0}", role.id);
        }
Ejemplo n.º 3
0
// ReSharper disable PossibleMultipleEnumeration
        public async Task RunAsync(IRestContext context)
        {
            ISystemApi systemApi = context.Factory.CreateSystemApi();

            // Read
            SqlQuery query = new SqlQuery {
                fields = "*", related = "services,roles",
            };
            IEnumerable <AppResponse> apps = await systemApi.GetAppsAsync(query);

            Console.WriteLine("Apps: {0}", apps.Select(x => x.api_name).ToStringList());

            // Cloning
            AppResponse todoApp        = apps.Single(x => x.api_name == "todoangular");
            AppRequest  todoAppRequest = todoApp.Convert <AppResponse, AppRequest>();

            todoAppRequest.name     = todoApp.name + "clone";
            todoAppRequest.api_name = todoApp.api_name + "clone";

            // Creating a clone
            apps = await systemApi.CreateAppsAsync(new SqlQuery(), todoAppRequest);

            AppResponse todoAppClone = apps.Single(x => x.api_name == "todoangularclone");

            Console.WriteLine("Created a clone app={0}", todoAppClone.api_name);

            // Deleting the clone
            Debug.Assert(todoAppClone.id.HasValue);
            await systemApi.DeleteAppsAsync(true, todoAppClone.id.Value);

            Console.WriteLine("Created clone has been deleted");
        }
Ejemplo n.º 4
0
// ReSharper disable PossibleMultipleEnumeration
        public async Task RunAsync(IRestContext context)
        {
            ISystemApi systemApi = context.Factory.CreateSystemApi();

            IEnumerable <DeviceResponse> devices = await systemApi.GetDevicesAsync(new SqlQuery());

            await DeleteAnyDevices(devices, systemApi);

            IUserApi      userApi = context.Factory.CreateUserApi();
            DeviceRequest device  = new DeviceRequest
            {
                uuid     = "1",
                model    = "model",
                platform = "windows",
                version  = "1.0"
            };

            bool ok = await userApi.SetDeviceAsync(device);

            Console.WriteLine("SetDeviceAsync(): success={0}", ok);

            SqlQuery query = new SqlQuery {
                filter = "platform=\"windows\"", fields = "*"
            };

            devices = await systemApi.GetDevicesAsync(query);

            Console.WriteLine("GetDevicesAsync(): {0}", context.ContentSerializer.Serialize(devices.Single()));

            await DeleteAnyDevices(devices, systemApi);
        }
Ejemplo n.º 5
0
        private static async Task DeleteUser(UserResponse user, ISystemApi systemApi)
        {
            Debug.Assert(user.id.HasValue, "User ID must be set");
            await systemApi.DeleteUsersAsync(user.id.Value);

            Console.WriteLine("DeleteUsersAsync():: id={0}", user.id);
        }
Ejemplo n.º 6
0
        public void ShouldDeleteAppsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act & Assert
            systemApi.DeleteAppsAsync(true, 1, 2, 3);
        }
Ejemplo n.º 7
0
        public void ShouldUpdateUserAsync()
        {
            // Arrange
            ISystemApi  systemApi = CreateSystemApi();
            UserRequest user      = CreateUser();

            // Act & Assert
            systemApi.UpdateUsersAsync(new SqlQuery(), user).Wait();
        }
Ejemplo n.º 8
0
        public void ShouldUpdateRoleAsync()
        {
            // Arrange
            ISystemApi  systemApi = CreateSystemApi();
            RoleRequest role      = CreateRole();

            // Act & Assert
            systemApi.UpdateRolesAsync(new SqlQuery(), role).Wait();
        }
Ejemplo n.º 9
0
        public void ShouldUpdateServiceAsync()
        {
            // Arrange
            ISystemApi     systemApi = CreateSystemApi();
            ServiceRequest service   = CreateService();

            // Act & Assert
            systemApi.UpdateServicesAsync(new SqlQuery(), service).Wait();
        }
Ejemplo n.º 10
0
        public void ShouldUpdateAppAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();
            AppRequest app       = CreateApp();

            // Act & Assert
            systemApi.UpdateAppsAsync(new SqlQuery(), app).Wait();
        }
Ejemplo n.º 11
0
        public void ShouldUpdateLookupAsync()
        {
            // Arrange
            ISystemApi    systemApi = CreateSystemApi();
            LookupRequest lookup    = CreateLookup();

            // Act & Assert
            systemApi.UpdateLookupsAsync(new SqlQuery(), lookup).Wait();
        }
Ejemplo n.º 12
0
 private static async Task DeleteAnyDevices(IEnumerable<DeviceResponse> devices, ISystemApi systemApi)
 {
     if (devices.Any())
     {
         int[] ids = devices.Select(x => x.id ?? 0).ToArray();
         await systemApi.DeleteDevicesAsync(ids);
         Console.WriteLine("DeleteDevicesAsync()");
     }
 }
Ejemplo n.º 13
0
        public void ShouldDeleteLookupsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act & Assert
            systemApi.DeleteLookupsAsync(new SqlQuery(), 1, 2, 3);

            Should.Throw <ArgumentException>(() => systemApi.DeleteLookupsAsync(new SqlQuery()));
        }
Ejemplo n.º 14
0
        public void ShouldGetConfigAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            ConfigResponse config = systemApi.GetConfigAsync().Result;

            // Assert
            config.EditableProfileFields.ShouldBe("name");
        }
Ejemplo n.º 15
0
        public void ShouldGetEnvironmentAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            EnvironmentResponse environment = systemApi.GetEnvironmentAsync().Result;

            // Assert
            environment.Platform.VersionCurrent.ShouldBe("2.0");
        }
Ejemplo n.º 16
0
        public async Task RunAsync(IRestContext context)
        {
            ISystemApi systemApi = context.Factory.CreateSystemApi();
            bool       success   = await systemApi.LogoutAdminAsync();

            Console.WriteLine("Logged out, success={0}", success);

            //IUserApi userApi = context.Factory.CreateUserApi();
            //bool success = await userApi.LogoutAsync();
            //Console.WriteLine("Logged out, success={0}", success);
        }
Ejemplo n.º 17
0
        public void ShouldGetEnvironmentAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            EnvironmentResponse environment = systemApi.GetEnvironmentAsync().Result;

            // Assert
            environment.server.server_os.ShouldBe("linux");
        }
Ejemplo n.º 18
0
        public void ShouldLogoutAdminAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            bool logout = systemApi.LogoutAdminAsync().Result;

            // Assert
            logout.ShouldBe(true);
        }
Ejemplo n.º 19
0
        public void ShouldDownloadApplicationSdkAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            byte[] data = systemApi.DownloadApplicationSdkAsync(1).Result;

            // Assert
            data.Length.ShouldBeGreaterThan(0);
        }
Ejemplo n.º 20
0
        public void ShouldGetAppGroupAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <AppGroupResponse> appGroups = systemApi.GetAppGroupsAsync(new SqlQuery()).Result.ToList();

            // Assert
            appGroups.Count.ShouldBe(1);
            appGroups.First().name.ShouldBe("NewGroup");
        }
Ejemplo n.º 21
0
        public void ShouldGetServicesAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <ServiceResponse> services = systemApi.GetServicesAsync(new SqlQuery()).Result.ToList();

            // Assert
            services.Count.ShouldBe(4);
            services.First().name.ShouldBe("Database");
        }
Ejemplo n.º 22
0
        public void ShouldGetRolesAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <RoleResponse> roles = systemApi.GetRolesAsync(new SqlQuery()).Result.ToList();

            // Assert
            roles.Count.ShouldBe(1);
            roles.First().name.ShouldBe("TestRole");
        }
Ejemplo n.º 23
0
        public void ShouldGetUsersAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <UserResponse> users = systemApi.GetUsersAsync(new SqlQuery()).Result.ToList();

            // Assert
            users.Count.ShouldBe(2);
            users.First().display_name.ShouldBe("Andrei Smirnov");
        }
Ejemplo n.º 24
0
        public void ShouldGetAppsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <AppResponse> apps = systemApi.GetAppsAsync(new SqlQuery()).Result.ToList();

            // Assert
            apps.Count.ShouldBe(5);
            apps.First().api_name.ShouldBe("todojquery");
        }
Ejemplo n.º 25
0
        public void ShouldGetConstantAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            Dictionary <string, string> constant = systemApi.GetConstantAsync("content_types").Result;

            // Assert
            constant.Count.ShouldBe(14);
            constant.Keys.ShouldContain("HTML");
        }
Ejemplo n.º 26
0
        public void ShouldGetConstantsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <string> types = systemApi.GetConstantsAsync().Result.ToList();

            // Assert
            types.Count.ShouldBe(19);
            types.ShouldContain("content_types");
        }
Ejemplo n.º 27
0
        public void ShouldGetEventScriptsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <string> events = systemApi.GetEventsAsync().Result.ToList();

            // Assert
            events.Count.ShouldBe(5);
            events.First().ShouldBe("system.get.pre_process");
        }
Ejemplo n.º 28
0
        public void ShouldGetScriptTypes()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <ScriptTypeResponse> scriptTypes = systemApi.GetScriptTypesAsync(new SqlQuery()).Result.ToList();

            // Assert
            scriptTypes.Count.ShouldBe(1);
            scriptTypes.Select(x => x.Name).First().ShouldBe("v8js");
        }
Ejemplo n.º 29
0
        public void ShouldCreateAppAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();
            AppRequest app       = CreateApp();

            // Act
            AppResponse created = systemApi.CreateAppsAsync(new SqlQuery(), app).Result.First();

            // Assert
            created.name.ShouldBe("Todo List jQuery");
        }
Ejemplo n.º 30
0
        public void ShouldGetCorsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <CorsResponse> results = systemApi.GetCorsAsync(new SqlQuery()).Result.ToList();

            // Assert
            results.Count.ShouldBe(2);
            results.First().Origin.ShouldBe("http://domain.foo");
        }
Ejemplo n.º 31
0
        public void ShouldGetLookupsAsync()
        {
            // Arrange
            ISystemApi systemApi = CreateSystemApi();

            // Act
            List <LookupResponse> lookups = systemApi.GetLookupsAsync(new SqlQuery()).Result.ToList();

            // Assert
            lookups.Count.ShouldBe(1);
            lookups.First().Value.ShouldBe("text");
        }
Ejemplo n.º 32
0
 private static async Task DeleteUser(UserResponse user, ISystemApi systemApi)
 {
     Debug.Assert(user.id.HasValue, "User ID must be set");
     await systemApi.DeleteUsersAsync(user.id.Value);
     Console.WriteLine("DeleteUsersAsync():: id={0}", user.id);
 }
Ejemplo n.º 33
0
 private static async Task DeleteDummyScript(ISystemApi systemApi)
 {
     await systemApi.DeleteScriptAsync(ScriptId);
     Console.WriteLine("DeleteScriptAsync({0})", ScriptId);
 }
Ejemplo n.º 34
0
 private static async Task DeleteRole(RoleResponse role, ISystemApi systemApi)
 {
     Debug.Assert(role.id.HasValue, "Role ID must be set");
     await systemApi.DeleteRolesAsync(role.id.Value);
     Console.WriteLine("DeleteRolesAsync():: id={0}", role.id);
 }