Beispiel #1
0
        public void SaveConfiguration()
        {
            var token = new Token()
            {
                ApplicationId = Guid.NewGuid(),
                ValidationKey = StringHelper.ValidString(),
            };

            var config = new Abc.Services.Contracts.Configuration()
            {
                Key   = StringHelper.ValidString(256),
                Token = token,
                Value = StringHelper.ValidString(256),
            };

            var u = new Abc.Services.Contracts.User()
            {
                Identifier = Guid.NewGuid(),
            };
            var a = new Abc.Services.Contracts.Application()
            {
                Identifier = token.ApplicationId,
            };
            var editor = new Abc.Services.Contracts.UserApplication()
            {
                User        = u,
                Application = a,
            };

            var core = new ApplicationCore();

            core.Save(config, editor);
        }
Beispiel #2
0
        public void GetConfigurationItems()
        {
            var user      = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var userTable = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            userTable.AddEntity(user);
            var userApp = new UserApplicationData(user.Id, user.ApplicationId)
            {
                Active = true
            };
            var table = new AzureTable <UserApplicationData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userApp);

            var core    = new ApplicationCore();
            var config1 = this.Config(userApp.ApplicationId);

            var config2 = this.Config(userApp.ApplicationId);
            var u       = new Abc.Services.Contracts.User()
            {
                Identifier = userApp.UserId,
            };
            var a = new Abc.Services.Contracts.Application()
            {
                Identifier = user.ApplicationId,
            };
            var editor = new Abc.Services.Contracts.UserApplication()
            {
                User        = u,
                Application = a,
            };

            core.Save(config1, editor);
            core.Save(config2, editor);

            var query = new Abc.Services.Contracts.Configuration()
            {
                Token = config1.Token,
            };

            var returned = core.Get(query);

            Assert.IsNotNull(returned);
            var item1 = (from data in returned
                         where data.Key == config1.Key &&
                         data.Value == config1.Value
                         select data).First();

            Assert.AreEqual <string>(config1.Key, item1.Key);
            Assert.AreEqual <string>(config1.Value, item1.Value);

            var item2 = (from data in returned
                         where data.Key == config2.Key &&
                         data.Value == config2.Value
                         select data).First();

            Assert.AreEqual <string>(config2.Key, item2.Key);
            Assert.AreEqual <string>(config2.Value, item2.Value);
        }
Beispiel #3
0
        public void GetConfigurationItem()
        {
            var user      = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var userTable = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            userTable.AddEntity(user);
            var userApp = new UserApplicationData(user.Id, user.ApplicationId)
            {
                Active = true
            };
            var table = new AzureTable <UserApplicationData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userApp);

            var core   = new ApplicationCore();
            var config = this.Config(userApp.ApplicationId);
            var u      = new Abc.Services.Contracts.User()
            {
                Identifier = userApp.UserId,
            };
            var a = new Abc.Services.Contracts.Application()
            {
                Identifier = user.ApplicationId,
            };
            var editor = new Abc.Services.Contracts.UserApplication()
            {
                User        = u,
                Application = a,
            };

            core.Save(config, editor);

            var query = new Abc.Services.Contracts.Configuration()
            {
                Token = config.Token,
                Key   = config.Key,
            };

            var returned = core.Get(query);

            Assert.IsNotNull(returned);
            Assert.AreEqual <int>(1, returned.Count());
            var item = returned.ToArray()[0];

            Assert.AreEqual <string>(config.Key, item.Key);
            Assert.AreEqual <string>(config.Value, item.Value);
        }
Beispiel #4
0
        public IEnumerable <Abc.Services.Contracts.Configuration> GetConfiguration(Abc.Services.Contracts.Configuration configuration)
        {
            IEnumerable <Abc.Services.Contracts.Configuration> returnData = null;

            try
            {
                using (new PerformanceMonitor())
                {
                    var validator = new Validator <Abc.Services.Contracts.Configuration>();
                    if (!validator.IsValid(configuration, true))
                    {
                        logCore.Log(validator.AllMessages(configuration));
                    }
                    else if (!this.tokenValidator.IsValid(configuration.Token, true))
                    {
                        logCore.Log(this.tokenValidator.AllMessages(configuration.Token));
                    }
                    else
                    {
                        application.Validate(configuration.Token.ApplicationId, configuration.Token.ValidationKey);

                        logCore.StoreByteCount(configuration.Token.ApplicationId, DataCostType.Ingress, configuration);

                        returnData = applicationCore.Get(configuration);

                        logCore.StoreByteCount(configuration.Token.ApplicationId, DataCostType.Egress, returnData);
                    }
                }
            }
            catch (Exception ex)
            {
                logCore.Log(ex, EventTypes.Error, (int)DatumFault.GetConfigurationUnknownError);
                throw;
            }

            return(returnData);
        }