Beispiel #1
0
        public TenantStoreTests()
        {
            // Configure connection strings per tenant
            var connStr = new List <KeyValuePair <string, string> >();

            _tenantNames.ForEach(t => connStr.Add(new KeyValuePair <string, string>($"{ConnectionStrings}:{ConnKeyPrefix}{t}", $"{ConnValuePrefix}{t}")));
            // Build configuration
            var cb = new ConfigurationBuilder();

            cb.AddInMemoryCollection(connStr);
            var config = cb.Build();

            // Create the mocked store with only 1 method setup for moq
            var tenantStoreMock = new Mock <TenantStore>(config, new NullLogger <TenantStore>());

            tenantStoreMock.CallBase = true; // IMPORTANT if original methods shall be used
            // Just override one method:
            tenantStoreMock.Setup(s => s.ReadTenantConfigFile(It.IsAny <string>())).Returns((string tenantName) =>
            {
                var tenant = new TenantContext
                {
                    Identifier          = tenantName,
                    IsDefault           = tenantName.Equals("DefaultTenant"),
                    Guid                = Guid.NewGuid(),
                    Filename            = tenantName,
                    SiteContext         = { UrlSegmentValue = tenantName },
                    DbContext           = { ConnectionKey = ConnKeyPrefix + tenantName },
                    OrganizationContext = { Name = "Long: " + tenantName, ShortName = "Short: " + tenantName }
                };
                return(tenant.Serialize());
            });
            tenantStoreMock.Setup(s => s.LoadTenants());
            _store = tenantStoreMock.Object;
            _store.GetTenantConfigurationFiles = () => _tenantNames.ToArray();
        }