Ends in:
4 DAYS
4 HRS
1 MIN
44 SEC
Ends in:
4 D
4 H
1 M
44 S

Activities of "enisn"

Hi,

Can you check *****ApplicationTestModule class in your test project for if there is a missing configuration or dependency.

Hi Yaduraj,

ABP Framework provides NSubstitute for mocking in testing.

See an example below:

public class BookStoreTest : BookStoreApplicationTestBase
{
    private ICurrentUser currentUser;

    protected override void AfterAddApplication(IServiceCollection services)
    {
        // Create a Substitute and replace original one in Service Collection
        currentUser = Substitute.For<ICurrentUser>();
        services.AddSingleton(currentUser);
    }

    [Fact]
    public async Task ShouldCurrentUserBeOwnerOfBook()
    {
        var userId = Guid.NewGuid();
        var username = "john.doe";
        
        // You can configure return values of Properties or Methods
        currentUser.Id.Returns(userId);
        currentUser.UserName.Returns(username);

        // Just a check if the id same. Also all services in the same IoC container will use that configuration.
        var id = currentUser.Id;
        id.ShouldBe(userId);
    }
}

I've just showed how to mock ICurrentUser, but you can mock any of your custom services that makes http call to a 3rd party API.

@learnabp let me introduce for your situation:

  • As a best-practice, BusinessException should be thrown from Domain layer. So You have to create your Exception in your Domain layer:
public class UserFriendlyException : BusinessException
{
    public UserFriendlyException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context)
    {
    }

    public UserFriendlyException(string tenantName)
    {
        // As an example, place your awesome unique code here
        Code = "Acme.BookStore:0001"; 

        WithData(nameof(TenantName), tenantName);
    }
    public string TenantName { get; set; }
}
  • You can throw like that:
    if (tenant != null)
    {
        throw new UserFriendlyException(Tenant.Name);
    }
  • You can localize what user sees in your localization files: en.json
    {
      "culture": "en",
      "texts": {
        "Acme.BookStore:0001": "Tenant Name {TenantName} already exists please choose another",
        //...
      }
    }
    
    You can display different messages for each language with that.

If you create a Business Exception like that, you won't see "internal error occured".

Let me know if that helps or not. @learnabp

If exception is inherited from Business exception and it has errorcode, exception detail text will be displayed from resources, exception message won't be displayed in UI automatically. You have to add a resource for errorcode of your exception

Hi @learnabp, I can't see UserFriendlyException but I'll suggest something below. If you already construct your exception same, please share your exception class too.


Make sure your exception is a DomainException and it has an error code and your localization json files have a resource with that error code as key.

You can examine 'AuthorAlreadyExistsException' in this sample

Hi @Leonardo.Willrich

As I understand, You don't want to change entire menu for tenant or host, just show/hide some menu items for host/tenant.

At this line I can show you a workaround:

  //if (_currentTenant.IsAvailable) // How to do it? Or what is the best way to do that?**
 if(_currentTenant.Id != null)
 {
   // tenant side
 }
 else
 {
  // host side
 }

Host doesn't have Id and it'll be null for host. Honestly, It's not best way or recommended to check host tenant but might help for you.

Showing 491 to 496 of 496 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35