Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
using Grand.Domain.Customers;
using Grand.Domain.Shipping;
using Grand.Infrastructure;
using Grand.Web.AdminShared.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Grand.Web.Admin.Tests.Controllers;
[TestClass]
public class StoreShippingMethodDataScopeTests
{
private static StoreShippingMethodDataScope Build(string staffStoreId)
{
var customer = new Customer { StaffStoreId = staffStoreId };
var workContextMock = new Mock<IWorkContext>();
workContextMock.Setup(w => w.CurrentCustomer).Returns(customer);
var contextAccessorMock = new Mock<IContextAccessor>();
contextAccessorMock.Setup(c => c.WorkContext).Returns(workContextMock.Object);
return new StoreShippingMethodDataScope(contextAccessorMock.Object);
}
[TestMethod]
public async Task HasAccess_MatchingStoreId_True()
{
var scope = Build("store-1");
Assert.IsTrue(await scope.HasAccess(new ShippingMethod { StoreId = "store-1" }));
}
[TestMethod]
public async Task HasAccess_MismatchedStoreId_False()
{
var scope = Build("store-1");
Assert.IsFalse(await scope.HasAccess(new ShippingMethod { StoreId = "store-2" }));
}
[TestMethod]
public async Task HasAccess_GlobalShippingMethod_False()
{
// Strict own-store-only for mutation, even though GetAllShippingMethods(storeId) itself
// returns own-store-OR-global for the List grid — a deliberate, pre-existing asymmetry.
var scope = Build("store-1");
Assert.IsFalse(await scope.HasAccess(new ShippingMethod { StoreId = "" }));
}
[TestMethod]
public async Task HasAccess_NullEntity_False()
{
var scope = Build("store-1");
Assert.IsFalse(await scope.HasAccess(null));
}
[TestMethod]
public void DefaultStoreId_ReturnsStaffStoreId()
{
var scope = Build("store-1");
Assert.AreEqual("store-1", scope.DefaultStoreId);
}
}