Пример #1
0
        public void StartTenantCollection()
        {
            var id      = Guid.NewGuid();
            var id2     = Guid.NewGuid();
            var tenant1 = new TenantDefault(id, "Tenant 1");
            var tenant2 = new TenantDefault(id, "Tenant 2");
            var tenant3 = new TenantDefault(id2, "Tenant 3");

            var secrets2 = new Dictionary <string, string>()
            {
                { "Secret2", "Value 1" }
            };
            var tenantSecret2 = new TenantSecret <Guid, dynamic>(id2, secrets: secrets2);

            var claims = new Dictionary <string, string>()
            {
                { "Claims1", "Value 1" }
            };
            var tenantClaims = new TenantClaims <Guid, dynamic>(id, claims: claims);

            var collection = new TenantCollection(new[] { tenant1, tenant2, tenant3 });

            Assert.AreEqual(2, collection.Count);
            var itens       = new ITenant <Guid>[] { tenant1, tenant2, tenant3, tenantClaims, _secretFirstTenant, tenantSecret2, null };
            var collection2 = new TenantCollection();

            collection2.Add(itens);
            Assert.AreEqual(3, collection2.Count);

            Assert.ThrowsException <ArgumentNullException>(() => collection2.Add((IEnumerable <ITenant <Guid> >)null));
        }
Пример #2
0
    public static List <Tenant> ReadTenantsWithPreferences(string file, VoxelGrid grid)
    {
        //THE LIST OF TENANTS SHOULD BE RELATED TO THE LIST OF REQUESTS
        //This is set up to read only area preferences so far. Updates must check for references
        //Only Work and Leisure space functions implemented
        List <Tenant>    tenants    = new List <Tenant>();
        string           jsonString = Resources.Load <TextAsset>(file).text;
        TenantCollection tenantList = JsonUtility.FromJson <TenantCollection>(jsonString);

        foreach (var tenant in tenantList.Tenants)
        {
            tenant.AssociateGrid(grid);
            //Tenant Area Preferences
            tenant.AreaPreferences = new Dictionary <SpaceFunction, int[]>();
            var areaWorkPref    = tenant.AreaPrefWork_S.Split('_').Select(p => int.Parse(p)).ToArray();
            var areaLeisurePref = tenant.AreaPrefLeisure_S.Split('_').Select(p => int.Parse(p)).ToArray();
            tenant.AreaPreferences.Add(SpaceFunction.Work, areaWorkPref);
            tenant.AreaPreferences.Add(SpaceFunction.Leisure, areaLeisurePref);

            //Tenant Connectivity Preferences
            tenant.ConnectivityPreferences = new Dictionary <SpaceFunction, float[]>();
            var connecWorkPref    = tenant.ConnectivityPrefWork_S.Split('_').Select(p => float.Parse(p) / 100.00f).ToArray();
            var connecLeisurePref = tenant.ConnectivityPrefLeisure_S.Split('_').Select(p => float.Parse(p) / 100.00f).ToArray();
            Debug.Log($"{tenant.Name} min work con {connecLeisurePref[0]}");
            tenant.ConnectivityPreferences.Add(SpaceFunction.Work, connecWorkPref);
            tenant.ConnectivityPreferences.Add(SpaceFunction.Leisure, connecLeisurePref);
            tenant.CreateUserIcon();
            tenants.Add(tenant);
        }

        return(tenants);
    }
Пример #3
0
        public async Task <AddTenantOutput> AddTenant(Tenant tenant)
        {
            try
            {
                await TenantCollection.InsertOneAsync(tenant);

                return(new AddTenantOutput
                {
                    Success = true
                });
            }

            catch (MongoWriteException ex)
            {
                Logger.LogInformation($"TenantDa - AddTenant: Duplicate Tenant {ex.Message}", ex);
                return(new AddTenantOutput
                {
                    Success = false,
                    Error = ErrorKeys.DuplicateTenantIdentifier
                });
            }

            catch (Exception ex)
            {
                Logger.LogError($"TenantDa - AddTenant: {ex.Message}", ex);
                return(new AddTenantOutput
                {
                    Success = false,
                    Error = ErrorKeys.InternalError
                });
            }
        }
Пример #4
0
        public void AddTenantAndMergeTenantSecret()
        {
            var tenant1 = new TenantDefault(_firstTenantId, "Tenant 1");
            var tenant  = new TenantCollection();

            tenant.Add(tenant1);

            tenant.Add(_secretFirstTenant);
            Assert.AreEqual(tenant.Count, 1);
        }
Пример #5
0
        public void AddTenantAndDistinctTenantSecret()
        {
            var tenant1 = new TenantDefault(_firstTenantId, "Tenant 1");
            var tenant  = new TenantCollection();

            tenant.Add(tenant1);

            tenant.Add(_secretSecondTenant);

            Assert.AreEqual(tenant.Count, 2);
            //tenantSecret.
        }
Пример #6
0
        public void AddTenantAndMergeTenantClaimsAndSecret()
        {
            var tenant1 = new TenantDefault(_firstTenantId, "Tenant 1");
            var tenant  = new TenantCollection();

            tenant.Add(tenant1);

            tenant.Add(_claimsFirstTenant);

            tenant.Add(new[] { _secretFirstTenant });
            Console.WriteLine(tenant.ToString());
            Assert.AreEqual(tenant.Count, 1);
        }
Пример #7
0
        public void AddDuplicatesTenants()
        {
            var id      = Guid.NewGuid();
            var tenant1 = new TenantDefault(id, "Tenant 1");
            var tenant2 = new TenantDefault(id, "Tenant 2");

            var tenant = new TenantCollection();

            tenant.Add(tenant1);
            tenant.Add(tenant2);
            tenant.Add((TenantDefault)null);
            Assert.AreEqual(tenant.Count, 1, "A clase permitiu adicionar duas instancias iguais");
        }
Пример #8
0
        public void AddTenantAndMergeTenantClaims()
        {
            var tenant1 = new TenantDefault(_firstTenantId, "Tenant 1");
            var tenant  = new TenantCollection();

            tenant.Add(tenant1);

            tenant.Add(new[] { _claimsFirstTenant });

            var tenantk = tenant.FirstOrDefault(_firstTenantId);

            Assert.IsNotNull(tenantk);
            Assert.AreEqual(tenant.Count, 1);
            Assert.IsTrue(tenantk.Claims.ContainsKey("Claims1"));
        }
Пример #9
0
        public void AddNewTenants()
        {
            var tenant1 = new TenantDefault(Guid.NewGuid(), "Tenant 1");
            var tenant2 = new TenantDefault(Guid.NewGuid(), "Tenant 2");

            var tenant  = new TenantCollection();
            int current = 0;

            Assert.AreEqual(tenant.Count, current, "Ao instanciar uma coleção ela iniciou com itens carregados");
            current++;

            tenant.Add(tenant1);
            Assert.AreEqual(tenant.Count, current, "Após adicionar um item na coleção a lista de itens não foi alterada");

            tenant.Add(tenant2);
            current++;
            Assert.AreEqual(tenant.Count, current, "Após adicionar um segundo item na coleção a lista de itens não foi alterada");
        }
Пример #10
0
        public void MergeTenantWithSecretAndCheckAllInstancies_ExpectedAllInstanceRelated()
        {
            var id      = _secretFirstTenant.Id;
            var tenant1 = new TenantDefault(id, "Tenant 1");
            var tenant2 = new TenantDefault(id, "Tenant 1 - One");
            var tenant3 = new TenantDefault(_secretSecondTenant.Id, "Tenant 3");

            var collection2 = new TenantCollection();
            var itens       =
                new ITenant <Guid>[] {
                tenant1,
                tenant2,
                tenant3,
                _secretSecondTenant,
                _secretFirstTenant
            };

            collection2.Add(itens);

            Assert.IsTrue(tenant3.Secrets?.Equals(_secretSecondTenant.Secrets) == true);

            Assert.AreEqual(2, collection2.Count);
        }
Пример #11
0
 public async Task <List <Tenant> > FindTenants()
 {
     return(await TenantCollection.Find(Builders <Tenant> .Filter.Empty).ToListAsync());
 }