Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "carelearning"

Hey Volosoft,

Do you have a recommended method of using a test double for ISettingManger or SettingManger in a unit test?

I know I have to avoid the generic extension methods as they are not mockable.

So my production code looks like this (see unabridged as DateRangeInvalidAsync.png):

var setting = await _settingManager.GetSettingValueForApplicationAsync("DateRangeMaximum");
  Int32.TryParse(setting, out int yearLimit);

My unit test method has this code (see unabridged as EnrollmentAppServiceTests.png):

_settingManager.Setup(x => x.GetSettingValueForApplicationAsync("DateRangeMaximum"))
                .Returns(Task.FromResult("100"));

My test configuration consists of XUnit, Moq and Autofixture. The error I get is [https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Configuration/SettingDefinition.cs]) requires a parameterless constructor.

Regards,

Hi @ismcagdas,

This is from our packages.config file: <package id="Abp" version="2.1.3" targetFramework="net461" /> ... <package id="EntityFramework.DynamicFilters" version="2.7.0" targetFramework="net461" />

Thank you for your help and effort.

Thank you for the response. Have you discovered any new information?

Dear @ismcagdas,

We used the premise of your suggestion to simplify our configuration options by creating a static class and hard coding the return values. The class lives in the Application project and is used by both Abpz projects as well as our custom ones so we wanted global one-time configuration, but don't need to store in the database. We are using this conjunction with a third-party Rest client.

This issue has been resolved.

Thank you for your time and expertise.

Dear @ismcagdas,

We are using the ASP.NET MVC 5.x the version.

Regards

Hello,

We have a need to load configuration settings from a config.ini file (it is in the bin folder of the project) at start-up. In a winform project we have MyCompanyName.AbpZeroTemplate.WinformApp. AbpZeroTemplateProviderModule:

public override void Initialize()
        {
                   IocManager.IocContainer.Register(Component.For<ConfigurationManager>()
                                   .DependsOn(new { fileName = "restapi.ini"}));
}

This works and everything is happy.

When we try to do the same in the web project, it fails to load the file. Is there something we are forgetting to check or is there a better way to load program configuration settings which we don't want the user to see?

Thank you

Thank you

await CurrentUnitOfWork.SaveChangesAsync();

flushes the changes to the database and now my queries are working appropriately without errors.

This issue has been resolved!

Hello,

We have a host and a tenant database. When we run update-database for the Tenant, it will add the settings: update-database -verbose -projectname MyCompanyName.AbpZeroTemplate.EntityFramework -startupprojectname MyCompanyName.AbpZeroTemplate.Web -configuration MyCompanyName.AbpZeroTemplate.AbpZeroTemplateTenant.Configuration We now have settings and that is great. When we run this again, the settings are duplicated. We have traced this to DefaultSettingsCreator.cs > AddSettingIfNotExists. It looks like this:

private void AddSettingIfNotExists(string name, string value, int? tenantId = null)
        {
            if (_context.Settings.Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }

In debugging this, it appears that _context.settings always has a count of 0. I thought this might be the wrong context, but the Add method works. Does anybody know what could cause this situation?

Dear alirizaadiyahsi, thank you for the reply.

Below are the fluent mappings for the two classes.

UserImportConfiguration

namespace MyCompanyName.AbpZeroTemplate.Configuration
{
    using System.Data.Entity.ModelConfiguration;
    using UserImport;

    public class UserImportConfiguration : EntityTypeConfiguration<UserImport>
    {
        public UserImportConfiguration()
            : this("dbo")
        {
        }

        public UserImportConfiguration(string schema)
        {
            ToTable(schema + ".UserImports");
            HasKey(x => x.Id);

            Property(x => x.Id).HasColumnName("Id").IsRequired().HasColumnType("int").HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
            Property(x => x.Position).HasColumnName("Position").IsRequired().HasColumnType("int");
            Property(x => x.Last).HasColumnName("LastName").IsRequired().HasColumnType("nvarchar").HasMaxLength(50);
            Property(x => x.First).HasColumnName("FirstName").IsRequired().HasColumnType("nvarchar").HasMaxLength(50);
            Property(x => x.DepartmentId).HasColumnName("DepartmentId").IsRequired().HasColumnType("nvarchar").HasMaxLength(50);
            Property(x => x.Date).HasColumnName("Date").IsOptional().HasColumnType("datetime");
            Property(x => x.IdBadge).HasColumnName("IdBadge").IsOptional().HasColumnType("nvarchar").HasMaxLength(15);
            Property(x => x.JobCodeId).HasColumnName("JobCodeId").IsOptional().HasColumnType("nvarchar").HasMaxLength(50);
            Property(x => x.EmailAddress).HasColumnName("EmailAddress").IsOptional().HasColumnType("nvarchar").HasMaxLength(254);
        }
    }
}

UserImportPresentation

namespace MyCompanyName.AbpZeroTemplate.Configuration
{
    using System.Data.Entity.ModelConfiguration;
    using UserImport;

    public class UserImportPresentationConfiguration : EntityTypeConfiguration<UserImportPresentation>
    {
        public UserImportPresentationConfiguration()
            : this("dbo")
        {
        }

        public UserImportPresentationConfiguration(string schema)
        {
            ToTable(schema + ".UserImportPresentations");

            HasKey(x => new { x.UserImportId });

            Property(x => x.Name).HasColumnName("Name").IsRequired().HasColumnType("nvarchar").HasMaxLength(66);
            Property(x => x.Department).HasColumnName("Department").IsRequired().HasColumnType("nvarchar").HasMaxLength(103);
            Property(x => x.JobCode).HasColumnName("JobCode").IsRequired().HasColumnType("nvarchar").HasMaxLength(103);

            Ignore(x => x.Id);

            HasRequired(x => x.UserImport);
        }
    }
}

Attached is the schema for both tables (see included image below).

I can comment out the UserImportPresentation insert statement and run the application the data will be added.

foreach (var import in imports)
            {
                await userImportRepository.InsertAsync(import);

                // var presentationUser = BuildUserImportPresentationResult(import, departments, jobCodes);
                // await userImportPresentationRepository.InsertAsync(presentationUser);
            }

Next stop the application and fetch the UserImport records and I can then comment out the UserImport insert statement and run the application a second time and the data will be added.

var import = await userImportRepository.GetAllListAsync();
foreach (var import in imports)
            {
                // await userImportRepository.InsertAsync(import);

                var presentationUser = BuildUserImportPresentationResult(import, departments, jobCodes);
                await userImportPresentationRepository.InsertAsync(presentationUser);
            }

The problem appears to be trying to insert the data on the same run, the second insert fails because the first is not in the table yet.

Thank you for your time and effort.

We have two entities defined as:

public class UserImport : AuditedEntity
    {
        public int Position { get; set; } = -1;
        public string Last { get; set; }
        public string First { get; set; }
        public string DepartmentId { get; set; }
        public DateTime? Date { get; set; }
        public string IdBadge { get; set; }
        public string JobCodeId { get; set; }
        public string EmailAddress { get; set; }

        public virtual UserImportPresentation Presentation { get; set; }

        public override string ToString()
        {
            return $"{Last}, {First}";
        }
    }

and

public class UserImportPresentation : Entity
    {
        public int UserImportId { get; set; }
        public string Name { get; set; }
        public string Department { get; set; }
        public string JobCode { get; set; }

        public virtual UserImport UserImport { get; set; }
    }

We save a record like this from our EnrollmentAppService : AbpZeroTemplateAppServiceBase, IApplicationService:

foreach (var import in imports)
            {
                await userImportRepository.InsertAsync(import);
                var presentationUser = BuildUserImportPresentationResult(import, departments, jobCodes);

                await userImportPresentationRepository.InsertAsync(presentationUser);
            }

Note that userImportPresentation has a foreign key to userImport. When we try to save a new record to these tables we get "Validation failed for one or more entities."(image attached)

It appears that the first save has not written yet and is expected for the second save. Is there a way to force the save to importUser before the insert to userImportPresentation?

Thank you for your time and effort.

Showing 61 to 70 of 108 entries