Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using Moq;
using NUnit.Framework;
using System.Collections.Generic;

namespace CADBooster.SolidDna.Test;

[TestFixture]
internal class CommandContextGroupTest
{
[Test]
public void Create_WithNullInfo_ThrowsException()
{
var group = new CommandContextGroup
{
Name = "TestGroup",
Items = new List<ICommandCreatable>
{
new CommandContextItem { Name = "Item1" }
}
};

Assert.Throws<SolidDnaException>(() => group.Create(null));
}

[Test]
public void Create_WithNullOrEmptyName_ThrowsException()
{
var group = new CommandContextGroup
{
Name = null,
Items = new List<ICommandCreatable>
{
new CommandContextItem { Name = "Item1" }
}
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => group.Create(info.Object));
}

[Test]
public void Create_WithWhitespaceName_ThrowsException()
{
var group = new CommandContextGroup
{
Name = " ",
Items = new List<ICommandCreatable>
{
new CommandContextItem { Name = "Item1" }
}
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => group.Create(info.Object));
}

[Test]
public void Create_WithNullItems_ThrowsException()
{
var group = new CommandContextGroup
{
Name = "TestGroup",
Items = null
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => group.Create(info.Object));
}

[Test]
public void Create_WithEmptyItems_ThrowsException()
{
var group = new CommandContextGroup
{
Name = "TestGroup",
Items = []
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => group.Create(info.Object));
}

[Test]
public void ToString_ReturnsCorrectFormat()
{
var group = new CommandContextGroup
{
Name = "TestGroup",
Items = new List<ICommandCreatable>
{
new CommandContextItem { Name = "Item1" },
new CommandContextItem { Name = "Item2" }
}
};

var result = group.ToString();

Assert.That(result, Does.Contain("TestGroup"));
Assert.That(result, Does.Contain("2"));
}

[Test]
public void ToString_WithNullItems_DoesNotThrow()
{
var group = new CommandContextGroup
{
Name = "TestGroup",
Items = null
};

var result = group.ToString();

Assert.That(result, Is.Not.Null);
Assert.That(result, Does.Contain("TestGroup"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using Moq;
using NUnit.Framework;

namespace CADBooster.SolidDna.Test;

[TestFixture]
internal class CommandContextIconTest
{
[Test]
public void Create_WithNullInfo_ThrowsException()
{
var icon = new CommandContextIcon
{
Hint = "TestIcon",
IconPathFormat = @"C:\Icons\icon{0}.png"
};

Assert.Throws<SolidDnaException>(() => icon.Create(null));
}

[Test]
public void Create_WithNullOrEmptyHint_ThrowsException()
{
var icon = new CommandContextIcon
{
Hint = null,
IconPathFormat = @"C:\Icons\icon{0}.png"
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => icon.Create(info.Object));
}

[Test]
public void Create_WithWhitespaceHint_ThrowsException()
{
var icon = new CommandContextIcon
{
Hint = " ",
IconPathFormat = @"C:\Icons\icon{0}.png"
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => icon.Create(info.Object));
}

[Test]
public void Create_WithNullOrEmptyIconPathFormat_ThrowsException()
{
var icon = new CommandContextIcon
{
Hint = "TestIcon",
IconPathFormat = null
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => icon.Create(info.Object));
}

[Test]
public void Create_WithWhitespaceIconPathFormat_ThrowsException()
{
var icon = new CommandContextIcon
{
Hint = "TestIcon",
IconPathFormat = " "
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => icon.Create(info.Object));
}

[Test]
public void VisibleForAssemblies_DefaultValue_IsTrue()
{
var icon = new CommandContextIcon();

Assert.That(icon.VisibleForAssemblies, Is.True);
}

[Test]
public void VisibleForDrawings_DefaultValue_IsTrue()
{
var icon = new CommandContextIcon();

Assert.That(icon.VisibleForDrawings, Is.True);
}

[Test]
public void VisibleForParts_DefaultValue_IsTrue()
{
var icon = new CommandContextIcon();

Assert.That(icon.VisibleForParts, Is.True);
}

[Test]
public void SelectionType_DefaultValue_IsEverything()
{
var icon = new CommandContextIcon();

Assert.That(icon.SelectionType, Is.EqualTo(SelectionType.Everything));
}

[Test]
public void Name_ReturnsHintValue()
{
var icon = new CommandContextIcon
{
Hint = "TestHint"
};

ICommandCreatable creatable = icon;
Assert.That(creatable.Name, Is.EqualTo("TestHint"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Moq;
using NUnit.Framework;

namespace CADBooster.SolidDna.Test;

[TestFixture]
internal class CommandContextItemTest
{
[Test]
public void Create_WithNullInfo_ThrowsException()
{
var item = new CommandContextItem
{
Name = "TestItem",
Hint = "Test hint"
};

Assert.Throws<SolidDnaException>(() => item.Create(null));
}

[Test]
public void Create_WithNullOrEmptyName_ThrowsException()
{
var item = new CommandContextItem
{
Name = null,
Hint = "Test hint"
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => item.Create(info.Object));
}

[Test]
public void Create_WithWhitespaceName_ThrowsException()
{
var item = new CommandContextItem
{
Name = " ",
Hint = "Test hint"
};
var info = new Mock<ICommandContextCreateInfo>();
info.Setup(x => x.SolidWorksCookie).Returns(1);

Assert.Throws<SolidDnaException>(() => item.Create(info.Object));
}

[Test]
public void VisibleForAssemblies_DefaultValue_IsTrue()
{
var item = new CommandContextItem();

Assert.That(item.VisibleForAssemblies, Is.True);
}

[Test]
public void VisibleForDrawings_DefaultValue_IsTrue()
{
var item = new CommandContextItem();

Assert.That(item.VisibleForDrawings, Is.True);
}

[Test]
public void VisibleForParts_DefaultValue_IsTrue()
{
var item = new CommandContextItem();

Assert.That(item.VisibleForParts, Is.True);
}

[Test]
public void SelectionType_DefaultValue_IsEverything()
{
var item = new CommandContextItem();

Assert.That(item.SelectionType, Is.EqualTo(SelectionType.Everything));
}
}
17 changes: 16 additions & 1 deletion SolidDna/CADBooster.SolidDna/Errors/SolidDnaErrorCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CADBooster.SolidDna;
namespace CADBooster.SolidDna;

/// <summary>
/// A list of all known types of error codes in SolidDNA
Expand Down Expand Up @@ -238,6 +238,21 @@ public enum SolidDnaErrorCode
/// </summary>
SolidWorksCommandItemPositionError = 12010,

/// <summary>
/// There was an error while trying to activate a Context Menu Item that was already activated
/// </summary>
SolidWorksCommandContextMenuItemReActivateError = 12011,

/// <summary>
/// There was an unknown error while trying to add a context menu icon.
/// </summary>
SolidWorksCommandCreateContextIconError = 12012,

/// <summary>
/// There was an unknown error while trying to add a context menu item.
/// </summary>
SolidWorksCommandCreateContextItemError = 12013,

#endregion

#region Export Data (13,000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public SolidWorksApplication(SldWorks solidWorks, int cookie) : base(solidWorks)
// If we have a cookie...
if (cookie > 0)
// Get command manager
CommandManager = new CommandManager(UnsafeObject.GetCommandManager(mSwCookie));
CommandManager = new CommandManager(UnsafeObject.GetCommandManager(mSwCookie), mSwCookie);

// Get whatever the current model is on load
ReloadActiveModelInformation();
Expand Down
Loading