示例#1
0
        public void KeyIncrementer_Increments_Success()
        {
            string defaultPrefix = "ABC";

            KeepWithinSingleSecond();

            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            UniqueKeys uniqueKey = new UniqueKeys();
            string     key       = uniqueKey.GetKey(defaultPrefix);
            string     expKey    = defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid;

            Assert.AreEqual(
                expKey, key,
                "A10:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);


            // Now create 2 more keys.  They should have incrementers attched to them.
            string key2 = uniqueKey.GetKey(defaultPrefix);
            string key3 = uniqueKey.GetKey(defaultPrefix);

            Assert.AreNotEqual(key, key2, "A20:  Expected Key1 and Key2 to be different.");
            Assert.AreNotEqual(key2, key3, "A30:  Expected Key2 and Key3 to be different.");

            Assert.IsTrue(key2.EndsWith(uniqueKey.WhatIsIncrementSeparator + "1"), "A40:  Key2 should have ended with a 1.");
            Assert.IsTrue(key3.EndsWith(uniqueKey.WhatIsIncrementSeparator + "2"), "A50:  Key3 should have ended with a 2.");
        }
示例#2
0
        public void RefreshKeyWorks()
        {
            string defaultPrefix = "Key";

            KeepWithinSingleSecond();


            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            UniqueKeys uniqueKey = new UniqueKeys(constantTimeGuid: true);
            string     key       = uniqueKey.GetKey(defaultPrefix);
            string     expKey    = defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid + uniqueKey.WhatIsIncrementSeparator + "1";

            Assert.AreEqual(expKey, key, "A10:  Expected initial key value was not correct.   Expected: " + expKey + "   Actual: " + key);

            string key2 = uniqueKey.GetKey(defaultPrefix);

            // Now refresh the key.
            string key3 = uniqueKey.RefreshKey(defaultPrefix);

            // Because key3 requested RefreshKey, we should get a new TimeGuid as it would have made the thread sleep for at least 1 second.
            TimeGuid newGuid = new TimeGuid(DateTime.Now);


            Assert.IsTrue(key2.EndsWith(uniqueKey.WhatIsIncrementSeparator + "2"), "A20:  Key2 should have ended with a 2.");
            Assert.IsTrue(key3.EndsWith(newGuid.ToString), "A21:  Key3 should have ended with a 1 as it was called with the RefreshKey.");

            string expKey3 = defaultPrefix + uniqueKey.WhatIsKeySeparator + newGuid;

            Assert.AreEqual(
                expKey3, key3, "A30: Expected key after Refresh was not equal to the value returned by UniqueKeys.  Exp: " + expKey3 + "   Actual:  " + key3);
        }
示例#3
0
        public void KeyValueSeparator_CanBeSet_Success()
        {
            string defaultPrefix = "ABC";
            string sep           = "^";

            KeepWithinSingleSecond();

            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            // Set separator to be carat.
            UniqueKeys uniqueKey = new UniqueKeys(sep);
            string     key       = uniqueKey.GetKey(defaultPrefix);
            string     expKey    = defaultPrefix + sep + stGuid.ToString;

            Assert.AreEqual(
                expKey, key,
                "A10:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);
            TestContext.WriteLine("Unique Key Value:    {0}", key);
            TestContext.WriteLine("Expected Key Value:  {0}", expKey);
        }
示例#4
0
            public DocumentZone(HtmlHelper html, string targetZone, ZoneInjectMode injectMode, string key)
            {
                Guard.NotEmpty(targetZone, nameof(targetZone));

                _viewContext = html.ViewContext;
                _originalViewContextWriter = _viewContext.Writer;
                _page = (WebViewPage)html.ViewDataContainer;

                var writer = new StringWriter();

                _page.OutputStack.Push(writer);
                _viewContext.Writer = writer;

                _targetZone = targetZone;
                _injectMode = injectMode;

                if (key.HasValue())
                {
                    if (HasUniqueKey(key))
                    {
                        _isVoid = true;
                    }
                    else
                    {
                        UniqueKeys.Add(key);
                    }
                }

                if (_page.Request.IsAjaxRequest())
                {
                    _isVoid = true;
                }
            }
示例#5
0
        public void RefreshKeyWithUniquePrefix_Success()
        {
            string defaultPrefix = "unique";

            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            UniqueKeys uniqueKey = new UniqueKeys();
            string     key       = uniqueKey.GetKey(defaultPrefix);
            string     expKey    = defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid.ToString;

            Assert.AreEqual(
                expKey, key,
                "A1:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);


            // Now get a new key.  Note the TimeGuid portion should be updated and the increment should be updated.
            Thread.Sleep(1000);
            string   key2    = uniqueKey.RefreshKey(defaultPrefix);
            TimeGuid stGuid2 = new TimeGuid(DateTime.Now);
            string   expKey2 = defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid2;

            Assert.AreEqual(
                expKey2, key2, "A2: Expected key after Refresh was not equal to the value returned by UniqueKeys.  Exp: " + expKey2 + "   Actual:  " + key2);


            TestContext.WriteLine("Unique Key Value:    {0}", key2);
            TestContext.WriteLine("Expected Key Value:  {0}", expKey2);
        }
示例#6
0
        private void LoadUniqueKeys()
        {
            // Get foreign keys for table in context.
            var tableUniqueKeys = Database.UniqueKeys.AsEnumerable()
                                  .Where(
                uniqueKey => uniqueKey.Field <string>("table_name") == SqlName &&
                uniqueKey.Field <string>("table_schema_name") == Schema
                ).ToList();

            // If none, return.
            if (tableUniqueKeys.Any() == false)
            {
                return;
            }

            // Group uniqe key name/columns pair.
            var uniqueGroup = tableUniqueKeys
                              .GroupBy(x => x.Field <string>("unique_key_name"))
                              .ToDictionary(g => g.Key, g => g.Select(x => x));

            // For each group load key.
            foreach (var group in uniqueGroup)
            {
                var       uniqueColumns = group.Value;
                UniqueKey uniqueKey     = new UniqueKey(uniqueColumns, this);
                UniqueKeys.GetOrAdd(uniqueKey.Name, uniqueKey);
            }
        }
示例#7
0
        // Validates that the first key has a value of 1 and each subsequent call is increasing by 1.
        public void KeyNumberShouldIncrement_EachCall_Success()
        {
            string defaultPrefix = "Key";

            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            UniqueKeys uniqueKey = new UniqueKeys();
            string     key       = uniqueKey.GetKey();
            string     expKey    = defaultPrefix + stGuid + "1";

            Assert.AreEqual(
                expKey, key,
                "A1:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);


            // Now generate another key:
            string key2    = uniqueKey.GetKey();
            string expKey2 = defaultPrefix + stGuid + "2";

            Assert.AreEqual(
                expKey2, key2,
                "A2:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);
        }
        public void CosmosUniqueKeyPolicyProviderCorrectlyGetsOneUniqueKeyAndPropertyPath()
        {
            ICosmosUniqueKeyPolicyProvider provider = new DefaultCosmosUniqueKeyPolicyProvider();

            UniqueKeyPolicy?policy = provider.GetUniqueKeyPolicy <SomeInterestingClass5>();

            Assert.Equal("/name", policy !.UniqueKeys.Single().Paths.Single());
        }
 public void AddUniqueKey(MySqlKeyDefinition index)
 {
     if (IndexKeys == null)
     {
         UniqueKeys = new HashSet <MySqlKeyDefinition>();
     }
     UniqueKeys.Add(index);
 }
示例#10
0
        public async Task VaultAgentTest_OneTimeSetup()
        {
            _uk   = new UniqueKeys();
            name  = _uk.GetKey("vlt");
            vault = await VaultServerRef.ConnectVault(name);

            //new VaultAgentAPI(name, VaultServerRef.ipAddress, VaultServerRef.ipPort, VaultServerRef.rootToken);
        }
示例#11
0
        public void DefaultKeyPrefix_IsCorrect()
        {
            UniqueKeys uniqueKey = new UniqueKeys();
            string     key       = uniqueKey.GetKey();
            string     prefix    = key.Substring(0, 3);

            Assert.AreEqual(3, prefix.Length, "A1: String prefix was expected to be 3 characters long.");
            Assert.AreEqual("Key", prefix, "A2: Default prefix is expected to be Key");
        }
        public void CosmosUniqueKeyPolicyProviderCorrectlyGetsUniqueKeysWithTwoPaths()
        {
            ICosmosUniqueKeyPolicyProvider provider = new DefaultCosmosUniqueKeyPolicyProvider();

            UniqueKeyPolicy?policy = provider.GetUniqueKeyPolicy <SomeInterestingClass2>();

            Assert.Contains("/Street", policy !.UniqueKeys.Single().Paths);
            Assert.Contains("/HouseNumber", policy.UniqueKeys.Single().Paths);
            Assert.Equal(2, policy.UniqueKeys.Single().Paths.Count);
        }
示例#13
0
        public VC_AppRoleAuthEngine(VaultAgentAPI vaultAgent)
        {
            UniqueKeys uniqueKeys = new UniqueKeys();

            // We will create a unique App Role Authentication Engine with the given name.
            _AppBEName          = "BEAppRole";
            _vaultAgent         = vaultAgent;
            _vaultSystemBackend = new VaultSystemBackend(_vaultAgent.TokenID, _vaultAgent);
            _appRoleAuthEngine  = (AppRoleAuthEngine)vaultAgent.ConnectAuthenticationBackend(EnumBackendTypes.A_AppRole, _AppBEName, _AppBEName);
            _idEngine           = (IdentitySecretEngine)vaultAgent.ConnectToSecretBackend(EnumSecretBackendTypes.Identity);
        }
示例#14
0
		public SqlTableSource(ISqlTableSource source, string? alias, IEnumerable<SqlJoinedTable> joins, IEnumerable<ISqlExpression[]>? uniqueKeys)
		{
			Source = source ?? throw new ArgumentNullException(nameof(source));
			_alias = alias;

			if (joins != null)
				Joins.AddRange(joins);

			if (uniqueKeys != null)
				UniqueKeys.AddRange(uniqueKeys);
		}
        public void CosmosUniqueKeyPolicyProviderCorrectlyGetsTwoUniqueKeys()
        {
            ICosmosUniqueKeyPolicyProvider provider = new DefaultCosmosUniqueKeyPolicyProvider();

            UniqueKeyPolicy?policy = provider.GetUniqueKeyPolicy <SomeInterestingClass3>();
            UniqueKey       key1   = policy !.UniqueKeys.Single(key => key.Paths.Count == 2);
            UniqueKey       key2   = policy.UniqueKeys.Single(key => key.Paths.Count == 1);

            Assert.Contains("/Street", key1.Paths);
            Assert.Contains("/HouseNumber", key1.Paths);
            Assert.Equal(2, key1.Paths.Count);

            Assert.Contains("/Name", key2.Paths);
            Assert.Single(key2.Paths);
        }
示例#16
0
            public DocumentZone(WebViewPage page, string targetZone, ZoneInjectMode injectMode, string key)
            {
                Guard.NotEmpty(targetZone, nameof(targetZone));

                _page = page;
                _page.OutputStack.Push(new StringWriter());

                _targetZone = targetZone;
                _injectMode = injectMode;

                if (key.HasValue())
                {
                    UniqueKeys.Add(key);
                }
            }
示例#17
0
        public bool CanCreate(IRow prevRow, IEnumerable <string> prevUniqueKeys)
        {
            if (UniqueKeys.Count() == 0 && IsRootRow)
            {
                return(true);
            }

            foreach (var column in UniqueKeys)
            {
                if (this[column] == DBNull.Value)
                {
                    return(false);
                }
            }

            if (prevRow == null)
            {
                return(true);
            }
            if (UniqueKeys.Count() == 0)
            {
                return(true);
            }

            foreach (var column in prevUniqueKeys.Merge(UniqueKeys))
            {
                if (this[column] == DBNull.Value && prevRow[column] == DBNull.Value)
                {
                    continue;
                }
                if (this[column] == DBNull.Value && prevRow[column] != DBNull.Value)
                {
                    return(true);
                }
                if (this[column] != DBNull.Value && prevRow[column] == DBNull.Value)
                {
                    return(true);
                }
                if (this[column].ToString() != prevRow[column].ToString())
                {
                    return(true);
                }
            }

            return(false);
        }
示例#18
0
        public void StaticTimeGuid_StaysSameThruLifetimeOfUniqueKeyObject()
        {
            string defaultPrefix = "ABC";

            KeepWithinSingleSecond();

            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            //We want a constant TimeGuid
            UniqueKeys uniqueKey = new UniqueKeys(constantTimeGuid: true);
            string     key       = uniqueKey.GetKey(defaultPrefix);
            string     expKey    = defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid + uniqueKey.WhatIsIncrementSeparator + "1";

            Assert.AreEqual(
                expKey, key,
                "A10:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);

            // Now lets create 3 more keys with a second between them.  TimeGuid should be same and just the incrementer should be increasing.
            string key2 = uniqueKey.GetKey(defaultPrefix);

            Thread.Sleep(1000);
            string key3 = uniqueKey.GetKey(defaultPrefix);

            Thread.Sleep(1500);
            string key4 = uniqueKey.GetKey(defaultPrefix);

            Thread.Sleep(2000);

            Assert.IsTrue(key2.EndsWith(uniqueKey.WhatIsIncrementSeparator + "2"), "A20:  Key2 should have ended with a 2.");
            Assert.IsTrue(key3.EndsWith(uniqueKey.WhatIsIncrementSeparator + "3"), "A21:  Key3 should have ended with a 3.");
            Assert.IsTrue(key4.EndsWith(uniqueKey.WhatIsIncrementSeparator + "4"), "A22:  Key4 should have ended with a 4.");

            Assert.AreEqual(defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid + uniqueKey.WhatIsIncrementSeparator + "2", key2,
                            "A50:  key2 is not expected value.");
            Assert.AreEqual(defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid + uniqueKey.WhatIsIncrementSeparator + "3", key3,
                            "A51:  key3 is not expected value.");
            Assert.AreEqual(defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid + uniqueKey.WhatIsIncrementSeparator + "4", key4,
                            "A52:  key4 is not expected value.");
        }
示例#19
0
        internal void Init(
            SqlSelectClause select,
            SqlFromClause from,
            SqlWhereClause where,
            SqlGroupByClause groupBy,
            SqlWhereClause having,
            SqlOrderByClause orderBy,
            List <SqlSetOperator>?setOperators,
            List <ISqlExpression[]>?uniqueKeys,
            SelectQuery?parentSelect,
            bool parameterDependent,
            string?queryName,
            bool doNotSetAliases)
        {
            Select               = select;
            From                 = from;
            Where                = where;
            GroupBy              = groupBy;
            Having               = having;
            OrderBy              = orderBy;
            _setOperators        = setOperators;
            ParentSelect         = parentSelect;
            IsParameterDependent = parameterDependent;
            QueryName            = queryName;
            DoNotSetAliases      = doNotSetAliases;

            if (uniqueKeys != null)
            {
                UniqueKeys.AddRange(uniqueKeys);
            }

            foreach (var col in select.Columns)
            {
                col.Parent = this;
            }

            Select.SetSqlQuery(this);
            From.SetSqlQuery(this);
            Where.SetSqlQuery(this);
            GroupBy.SetSqlQuery(this);
            Having.SetSqlQuery(this);
            OrderBy.SetSqlQuery(this);
        }
示例#20
0
        public async Task NormalLogin()
        {
            // SETUP

            // We need our own vault since we will be manipulating the token value
            VaultAgentAPI ourVault = await VaultServerRef.ConnectVault("TokenTest");

            TokenAuthEngine ourTokenAuthEngine = (TokenAuthEngine)ourVault.ConnectAuthenticationBackend(EnumBackendTypes.A_Token);

            // Need a Token Role so we can autogenerate a token
            TokenRole tokenRole = new TokenRole();

            UniqueKeys UK = new UniqueKeys("", "");       // Unique Key generator

            tokenRole.Name = UK.GetKey();
            await ourTokenAuthEngine.SaveTokenRole(tokenRole);

            string           tokenName        = "Name" + tokenRole.Name;
            TokenNewSettings tokenNewSettings = new TokenNewSettings()
            {
                Name          = tokenName,
                NumberOfUses  = 6,
                NoParentToken = true,
                RoleName      = tokenRole.Name
            };

            Token token = await ourTokenAuthEngine.CreateToken(tokenNewSettings);

            Assert.NotNull(token, "A10:  Expected to receive the new token back, instead we received a null value.");

            // Read the token we just created.
            //Token token = await _tokenAuthEngine.GetTokenWithID(tokenID);
            Assert.IsNotNull(token, "A20: No Token returned.  Was expecting one.");


            VaultAgentAPI vault2 = await VaultServerRef.ConnectVault("TokenLoginTest");

            TokenLoginConnector loginConnector = new TokenLoginConnector(vault2, "test");

            loginConnector.TokenId = token.ID;
            Assert.IsTrue(await loginConnector.Connect(), "A30:  Login Failed");
        }
示例#21
0
        public void DefaultConstructor_CreatesExpectedKey()
        {
            string key = "ABC";

            // For this test we want to make sure we do not cross a second boundary.  So any time above 700ms we will wait out until the next second hits.
            int millisec = DateTimeOffset.Now.Millisecond;
            int sleepInt = 0;

            if (millisec > 800)
            {
                sleepInt = 1000 - millisec;
                Thread.Sleep(sleepInt);
            }

            // We will test twice to determine if the TimeGuid is being set correctly.
            UniqueKeys uniqueKeys = new UniqueKeys();
            string     key1       = uniqueKeys.GetKey(key);

            // Now sleep so we can make sure the next call to uniqueKeys will generate a new timeGuid.
            millisec = DateTimeOffset.Now.Millisecond;
            sleepInt = 1000 - millisec + 10;
            Thread.Sleep(sleepInt);

            // Create another unique key.  The TimeGuid's should be different.
            string key2 = uniqueKeys.GetKey(key);

            Assert.AreNotEqual(key1, key2, "A10:  Expected the keys to be different.");
            Assert.True(key2.StartsWith(key + ":"), "A20:  Expected the generated key to start with ABC:");


            // Now get the TimeGuid parts of the keys
            string [] timeGuidPart1 = key1.Split(":");
            Assert.AreEqual(2, timeGuidPart1.Length, "A30:  Expected the generated key to contain 2 parts.");


            string [] timeGuidPart2 = key2.Split(":");
            Assert.AreEqual(2, timeGuidPart2.Length, "A30:  Expected the generated key to contain 2 parts.");

            Assert.AreNotEqual(timeGuidPart1 [1], timeGuidPart2 [1], "A40:  Expected the TimeGuid part of the keys to be different.");
            Assert.AreEqual(timeGuidPart1 [0], timeGuidPart2 [0], "A50:  Expected the Key part of the keys to be the same.");
        }
示例#22
0
        public async Task InitialSetup()
        {
            // Connect to Redis
            RedisCommunicator redisCommunicator = new RedisCommunicator();

            redisCommunicator.TalkToRedis();

            _redisCacheClient = redisCommunicator.RedisCacheClient;

            // Now create a locker
            _locker = new RedisLocker(_redisCacheClient);

            // Setup random number generator
            _idGenerator = new Random();

            // Create Unique Key object to provide unique LockCategories per test, so they can run in parallel without clobbering each other
            _uniqueKeys = new UniqueKeys();

            // Tell Redis to clear everything out of its system
            await _redisCacheClient.Db0.FlushDbAsync();
        }
示例#23
0
        public void GetKeyWithUniquePrefix_Success()
        {
            string defaultPrefix = "unique";

            // We need to simulate the Timeguid logic to derive at the initial key value.
            TimeGuid stGuid = new TimeGuid(DateTime.Now);


            UniqueKeys uniqueKey = new UniqueKeys();
            string     key       = uniqueKey.GetKey(defaultPrefix);
            string     expKey    = defaultPrefix + uniqueKey.WhatIsKeySeparator + stGuid.ToString;

            Assert.AreEqual(
                expKey, key,
                "A1:  Expected initial key value was not correct. Note:  On Failures run a second time.  There is a very slight chance that due to a second rollover the values could be different.  Expected: " +
                expKey +
                "   Actual: " +
                key);

            TestContext.WriteLine("Unique Key Value:    {0}", key);
            TestContext.WriteLine("Expected Key Value:  {0}", expKey);
        }
示例#24
0
 public virtual DdlCreateTableStatement AddUniqueIndex(Identifier colname, IndexDefinition def)
 {
     UniqueKeys.Add(new Pair <Identifier, IndexDefinition>(colname, def));
     return(this);
 }