Skip to content
Merged
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
Expand Up @@ -6,4 +6,6 @@ namespace Masa.BuildingBlocks.StackSdks.Sapp;
public interface ISappClient
{
public IGlobalNavService GlobalNavService { get; init; }

public IModuleService ModuleService { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Masa.BuildingBlocks.StackSdks.Sapp.Model;

public class MaintainceDto
{
public string Reason { get; set; } = default!;

public DateTime StartTime { get; set; }

public DateTime EndTime { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Masa.BuildingBlocks.StackSdks.Sapp.Model;

public class ModuleDetailDto
{
public string Code { get; set; } = default!;

public string Name { get; set; } = default!;

public string? Icon { get; set; }

public string PmIdentity { get; set; } = default!;

public bool Enable { get; set; } = default!;

public bool Show { get; set; } = default!;

public StatusTypes Status { get; set; }

public MaintainceDto? Maintaince { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Masa.BuildingBlocks.StackSdks.Sapp.Service;

public interface IModuleService
{
Task<ModuleDetailDto?> GetByPmIdentityAsync(string pmIdentity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class SappClient : ISappClient
public SappClient(ICaller caller)
{
GlobalNavService = new GlobalNavService(caller);
ModuleService = new ModuleService(caller);
}

public IGlobalNavService GlobalNavService { get; init; }

public IModuleService ModuleService { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.StackSdks.Sapp.Service;

public class ModuleService : IModuleService
{
private const string MODULE_ROUTE_PREFIX = "api/module";

private readonly ICaller _caller;

public ModuleService(ICaller caller)
{
_caller = caller;
}

public Task<ModuleDetailDto?> GetByPmIdentityAsync(string pmIdentity)
{
var requestUri = $"{MODULE_ROUTE_PREFIX}/byPmIdentity";
return _caller.GetAsync<ModuleDetailDto?>(requestUri, new { pmIdentity });
}
}
3 changes: 3 additions & 0 deletions src/Contrib/Masa.Contrib.StackSdks.Sapp/SappClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class SappClient : ISappClient
public SappClient(ICaller caller)
{
GlobalNavService = new GlobalNavService(caller);
ModuleService = new ModuleService(caller);
}

public IGlobalNavService GlobalNavService { get; init; }

public IModuleService ModuleService { get; init; }
}
19 changes: 19 additions & 0 deletions src/Contrib/Masa.Contrib.StackSdks.Sapp/Service/ModuleService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Masa.Contrib.StackSdks.Sapp.Service;

public class ModuleService : IModuleService
{
private const string MODULE_ROUTE_PREFIX = "api/module";

private readonly ICaller _caller;

public ModuleService(ICaller caller)
{
_caller = caller;
}

public Task<ModuleDetailDto?> GetByPmIdentityAsync(string pmIdentity)
{
var requestUri = $"{MODULE_ROUTE_PREFIX}/byPmIdentity";
return _caller.GetAsync<ModuleDetailDto?>(requestUri, new { pmIdentity });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.Contrib.StackSdks.Sapp.Tests;

[TestClass]
public class ModuleServiceTest
{
[TestMethod]
[DataRow("pm.identity")]
public async Task TestGetByPmIdentityAsync(string pmIdentity)
{
var data = new ModuleDetailDto { PmIdentity = pmIdentity };

var requestUri = $"api/module/byPmIdentity/{pmIdentity}";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.GetAsync<ModuleDetailDto?>(requestUri, default)).ReturnsAsync(data).Verifiable();
var sappClient = new SappClient(caller.Object);

var result = await sappClient.ModuleService.GetByPmIdentityAsync(pmIdentity);
caller.Verify(provider => provider.GetAsync<ModuleDetailDto?>(requestUri, default), Times.Once);

Assert.IsNotNull(result);
Assert.AreEqual(pmIdentity, result.PmIdentity);
}

[TestMethod]
[DataRow("pm.identity")]
public async Task TestGetByPmIdentityWhenNullAsync(string pmIdentity)
{
ModuleDetailDto? data = null;

var requestUri = $"api/module/byPmIdentity/{pmIdentity}";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.GetAsync<ModuleDetailDto?>(It.IsAny<string>(), default)).ReturnsAsync(data).Verifiable();
var sappClient = new SappClient(caller.Object);

var result = await sappClient.ModuleService.GetByPmIdentityAsync(pmIdentity);
caller.Verify(provider => provider.GetAsync<ModuleDetailDto?>(requestUri, default), Times.Once);

Assert.IsNull(result);
}
}
Loading