Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions mock-api-test-sdk-net60/WorkspaceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Smartsheet.Api;
using Smartsheet.Api.Models;

namespace mock_api_test_sdk_net60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rzaracota following applies to multiple namespaces and directories in this PR: current supported dotnet version is 8.0, not 6.0.

{
[TestClass]
public class WorkspaceTests
{
private Workspace createWorkspace(SmartsheetClient client, string workspaceName) {
Workspace workspace = new Workspace();

workspace.Name = workspaceName;

return client.WorkspaceResources.CreateWorkspace(workspace);
}


[TestMethod]
public void CreateWorkspace_Success()
{
SmartsheetClient client = HelperFunctions.SetupClient("Create Workspace - Valid");

Workspace newWorkspace = new Workspace();

newWorkspace.Name = "New workspace";

Workspace workspace = client.WorkspaceResources.CreateWorkspace(newWorkspace);

Assert.IsNotNull(workspace);
Assert.IsNotNull(workspace.Id);
Assert.IsNotNull(workspace.Name);
Assert.IsNotNull(workspace.AccessLevel);
Assert.IsNotNull(workspace.Permalink);
}

[TestMethod]
public void CreateFolder_Success()
{
SmartsheetClient client = HelperFunctions.SetupClient("Create Folder in Workspace - Valid");

Folder newFolder = new Folder();

newFolder.Name = "New Folder";

Folder folder = client.WorkspaceFolderResources.CreateFolder(12345, newFolder);

Assert.IsNotNull(folder);
Assert.IsNotNull(folder.Name);
Assert.AreEqual("New Folder", folder.Name);
}

[TestMethod]
public void CreateSheet_NoColumns()
{
SmartsheetClient ss = HelperFunctions.SetupClient("Create Sheet - Invalid - No Columns");

Sheet sheetA = new Sheet
{
Name = "New Sheet",
Columns = new List<Column>()
};

HelperFunctions.AssertRaisesException<SmartsheetException>(() =>
ss.SheetResources.CreateSheet(sheetA),
"The new sheet requires either a fromId or columns.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public class SmartsheetImpl : SmartsheetClient
/// </summary>
private WorkspaceResources workspaces;

/// <summary>
/// Represents the AtomicReference to WorkspaceResources.
///
/// It will be initialized in the constructor and will not change afterwards. The underlying value will be initially set
/// as null, and will be initialized to non-null the first time it is accessed via corresponding getter, therefore
/// effectively the underlying value is lazily created in a thread safe manner.
/// </summary>
private WorkspaceFolderResources workspaceFolders;


/// <summary>
/// Represents the AtomicReference to FolderResources.
///
Expand All @@ -116,6 +126,8 @@ public class SmartsheetImpl : SmartsheetClient
/// </summary>
private FolderResources folders;

private FolderSheetResources folderSheets;

/// <summary>
/// Represents the AtomicReference to TemplateResources.
///
Expand Down Expand Up @@ -143,6 +155,8 @@ public class SmartsheetImpl : SmartsheetClient
/// </summary>
private SheetResources sheets;

private SheetRowResources sheetRows;

/// <summary>
/// Represents the AtomicReference to SightResources.
///
Expand Down Expand Up @@ -416,6 +430,19 @@ public virtual WorkspaceResources WorkspaceResources
}
}

/// <summary>
/// Returns the WorkspaceFolderResources instance that provides access to the workspace folders resources.
/// </summary>
/// <returns> the workspace folder resources</returns>
public virtual WorkspaceFolderResources WorkspaceFolderResources
{
get
{
Interlocked.CompareExchange<WorkspaceFolderResources>(ref workspaceFolders, new WorkspaceFolderResourcesImpl(this), null);
return workspaceFolders;
}
}

/// <summary>
/// Returns the FolderResources instance that provides access to folder resources.
/// </summary>
Expand All @@ -429,6 +456,19 @@ public virtual FolderResources FolderResources
}
}

/// <summary>
/// Returns the FolderSheetResources instance that provides access to folder's sheet resources.
/// </summary>
/// <returns> the folder sheet resources </returns>
public virtual FolderSheetResources FolderSheetResources
{
get
{
Interlocked.CompareExchange<FolderSheetResources>(ref folderSheets, new FolderSheetResourcesImpl(this), null);
return folderSheets;
}
}

/// <summary>
/// Returns the TemplateResources instance that provides access to template resources.
/// </summary>
Expand Down Expand Up @@ -468,6 +508,15 @@ public virtual SheetResources SheetResources
}
}

public virtual SheetRowResources SheetRowResources
{
get
{
Interlocked.CompareExchange<SheetRowResources>(ref sheetRows, new SheetRowResourcesImpl(this), null);
return sheetRows;
}
}

/// <summary>
/// Returns the SightResources instance that provides access to Sight resources.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions smartsheet-csharp-sdk/main/Smartsheet/Api/SmartsheetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,24 @@ public interface SmartsheetClient
/// <returns> the workspace resources instance </returns>
WorkspaceResources WorkspaceResources { get; }

/// <summary>
/// <para>Returns the WorkspaceFolderResources instance that provides access to Folder resources within the workspace.</para>
/// </summary>
/// <returns>The workspace's folders resource</returns>
WorkspaceFolderResources WorkspaceFolderResources { get; }

/// <summary>
/// <para>Returns the FolderResources instance that provides access to Folder resources.</para>
/// </summary>
/// <returns> the folder resources instance </returns>
FolderResources FolderResources { get; }

/// <summary>
/// <para>Returns the FolderSheetResources instance that provides access to a folder's Sheet resources.</para>
/// </summary>
/// <returns> the folderSheet resources instance </returns>
FolderSheetResources FolderSheetResources { get; }

/// <summary>
/// <para>Returns the TemplateResources instance that provides access to Template resources.</para>
/// </summary>
Expand All @@ -88,6 +100,8 @@ public interface SmartsheetClient
/// <returns> the sheet resources instance </returns>
SheetResources SheetResources { get; }

SheetRowResources SheetRowResources { get; }

/// <summary>
/// <para>Returns the SightResources instance that provides access to Sight resources.</para>
/// </summary>
Expand Down
Loading