|
| 1 | +/* |
| 2 | + * -------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose" file="timephased_data_test.go"> |
| 4 | + * Copyright (c) 2021 Aspose.Tasks Cloud |
| 5 | + * </copyright> |
| 6 | + * <summary> |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * </summary> |
| 25 | + * -------------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +// Example of how to work with timephased data. |
| 29 | +package api_test |
| 30 | + |
| 31 | +import ( |
| 32 | + "github.com/antihax/optional" |
| 33 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/models" |
| 34 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/requests" |
| 35 | + "github.com/stretchr/testify/assert" |
| 36 | + "testing" |
| 37 | +) |
| 38 | + |
| 39 | +// Test for get task timephased data. |
| 40 | +func Test_TimephasedData_GetTaskTimephasedData(t *testing.T) { |
| 41 | + localFileName := "NewProductDev.mpp" |
| 42 | + remoteFileName := CreateRandomGuid() + localFileName |
| 43 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 44 | + |
| 45 | + opts := &requests.GetTaskTimephasedDataOpts{ |
| 46 | + TaskUid: 27, |
| 47 | + Type_: optional.NewString(string(models.TASK_WORK_TimephasedDataType)), |
| 48 | + Name: remoteFileName, |
| 49 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 50 | + } |
| 51 | + result, _, err := client.TasksApi.GetTaskTimephasedData(ctx, opts) |
| 52 | + if err != nil { |
| 53 | + t.Error(err) |
| 54 | + } |
| 55 | + assert.Equal(t, int32(200), result.Code) |
| 56 | + assert.NotNil(t, result.Items) |
| 57 | + assert.LessOrEqual(t, 1, len(result.Items)) |
| 58 | + for _, timephasedData := range result.Items { |
| 59 | + assert.Equal(t, models.TASK_WORK_TimephasedDataType, *timephasedData.TimephasedDataType) |
| 60 | + assert.Equal(t, int32(27), timephasedData.Uid) |
| 61 | + } |
| 62 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 63 | +} |
| 64 | + |
| 65 | +// Test for get resource timephased data. |
| 66 | +func Test_TimephasedData_GetResourceTimephasedData(t *testing.T) { |
| 67 | + localFileName := "NewProductDev.mpp" |
| 68 | + remoteFileName := CreateRandomGuid() + localFileName |
| 69 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 70 | + |
| 71 | + opts := &requests.GetResourceTimephasedDataOpts{ |
| 72 | + ResourceUid: 1, |
| 73 | + Type_: optional.NewString(string(models.RESOURCE_WORK_TimephasedDataType)), |
| 74 | + Name: remoteFileName, |
| 75 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 76 | + } |
| 77 | + result, _, err := client.TasksApi.GetResourceTimephasedData(ctx, opts) |
| 78 | + if err != nil { |
| 79 | + t.Error(err) |
| 80 | + } |
| 81 | + assert.Equal(t, int32(200), result.Code) |
| 82 | + assert.NotNil(t, result.Items) |
| 83 | + assert.LessOrEqual(t, 1, len(result.Items)) |
| 84 | + for _, timephasedData := range result.Items { |
| 85 | + assert.Equal(t, models.RESOURCE_WORK_TimephasedDataType, *timephasedData.TimephasedDataType) |
| 86 | + assert.Equal(t, int32(1), timephasedData.Uid) |
| 87 | + } |
| 88 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 89 | +} |
| 90 | + |
| 91 | +// Test for get assignment timephased data. |
| 92 | +func Test_TimephasedData_GetAssignmentTimephasedData(t *testing.T) { |
| 93 | + localFileName := "NewProductDev.mpp" |
| 94 | + remoteFileName := CreateRandomGuid() + localFileName |
| 95 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 96 | + |
| 97 | + opts := &requests.GetAssignmentTimephasedDataOpts{ |
| 98 | + AssignmentUid: 66, |
| 99 | + Type_: optional.NewString(string(models.ASSIGNMENT_WORK_TimephasedDataType)), |
| 100 | + Name: remoteFileName, |
| 101 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 102 | + } |
| 103 | + result, _, err := client.TasksApi.GetAssignmentTimephasedData(ctx, opts) |
| 104 | + if err != nil { |
| 105 | + t.Error(err) |
| 106 | + } |
| 107 | + assert.Equal(t, int32(200), result.Code) |
| 108 | + assert.NotNil(t, result.Items) |
| 109 | + assert.LessOrEqual(t, 1, len(result.Items)) |
| 110 | + for _, timephasedData := range result.Items { |
| 111 | + assert.Equal(t, models.ASSIGNMENT_WORK_TimephasedDataType, *timephasedData.TimephasedDataType) |
| 112 | + assert.Equal(t, int32(66), timephasedData.Uid) |
| 113 | + } |
| 114 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 115 | +} |
0 commit comments