Example #1
0
        public void RemoveKvpFailsWhenValueNotEqualTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            var actualRemoved = dict.Remove(new KeyValuePair <int, string>(4, "555"));

            // Assert
            var expectedKvp = new[]
            {
                new KeyValuePair <int, string>(2, "3"),
                new KeyValuePair <int, string>(3, "4"),
                new KeyValuePair <int, string>(4, "5"),
                new KeyValuePair <int, string>(5, "1"),
                new KeyValuePair <int, string>(1, "2")
            };

            Assert.IsFalse(actualRemoved);
            CollectionAssert.AreEqual(expectedKvp, dict);
        }
Example #2
0
        public void InsertValueBeforeFirstKeyTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                // {2, "3"},
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            dict.InsertBefore(3, 2, "3");

            // Assert
            var expectedKvp = new[]
            {
                new KeyValuePair <int, string>(2, "3"),
                new KeyValuePair <int, string>(3, "4"),
                new KeyValuePair <int, string>(4, "5"),
                new KeyValuePair <int, string>(5, "1"),
                new KeyValuePair <int, string>(1, "2")
            };

            CollectionAssert.AreEqual(expectedKvp, dict);
        }
Example #3
0
        public void UpdateExistingValueUsingIndexerTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "444" },
                { 4, "5" },
                { 5, "111" },
                { 1, "2" }
            };

            // Act
            dict[3] = "4";
            dict[5] = "1";

            // Assert
            var expectedKvp = new[]
            {
                new KeyValuePair <int, string>(2, "3"),
                new KeyValuePair <int, string>(3, "4"),
                new KeyValuePair <int, string>(4, "5"),
                new KeyValuePair <int, string>(5, "1"),
                new KeyValuePair <int, string>(1, "2")
            };

            CollectionAssert.AreEqual(expectedKvp, dict);
        }
Example #4
0
        public void PrependItemTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                // {2, "3"},
                // {3, "4"},
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            dict.Prepend(3, "4");
            dict.Prepend(2, "3");

            // Assert
            var expectedKvp = new[]
            {
                new KeyValuePair <int, string>(2, "3"),
                new KeyValuePair <int, string>(3, "4"),
                new KeyValuePair <int, string>(4, "5"),
                new KeyValuePair <int, string>(5, "1"),
                new KeyValuePair <int, string>(1, "2")
            };

            CollectionAssert.AreEqual(expectedKvp, dict);
        }
Example #5
0
        public void ContainsReturnsFalseWhenValueIsNotEqualTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            var actualContains = dict.Contains(new KeyValuePair <int, string>(4, "555"));

            // Assert
            Assert.IsFalse(actualContains);
        }
Example #6
0
        public void ContainsKeyReturnsFalseWhenKeyDoesNotExistTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            var actualContains = dict.ContainsKey(6);

            // Assert
            Assert.IsFalse(actualContains);
        }
Example #7
0
        public void TryGetValueWhenKeyDoesNotExistTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            string actualValue;
            var    actualExists = dict.TryGetValue(6, out actualValue);

            // Assert
            Assert.IsFalse(actualExists);
            Assert.IsNull(actualValue);
        }
		public void ValuesCollectionIsOrderedTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			var actualValues = dict.Values;

			// Assert
			var expectedValues = new[] { "3", "4", "5", "1", "2" };

			CollectionAssert.AreEqual(expectedValues, actualValues);
		}
Example #9
0
        public void GetValueUsingIndexerTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            var actualValues = new[] { dict[2], dict[3], dict[4], dict[5], dict[1] };

            // Assert
            var expectedValues = new[] { "3", "4", "5", "1", "2" };

            CollectionAssert.AreEqual(expectedValues, actualValues);
        }
Example #10
0
        public void ValuesCollectionIsOrderedTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            var actualValues = dict.Values;

            // Assert
            var expectedValues = new[] { "3", "4", "5", "1", "2" };

            CollectionAssert.AreEqual(expectedValues, actualValues);
        }
Example #11
0
        public void KeysCollectionIsOrderedTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            var actualKeys = dict.Keys;

            // Assert
            var expectedKeys = new[] { 2, 3, 4, 5, 1 };

            CollectionAssert.AreEqual(expectedKeys, actualKeys);
        }
		public void KeysCollectionIsOrderedTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			var actualKeys = dict.Keys;

			// Assert
			var expectedKeys = new[] {2, 3, 4, 5, 1};

			CollectionAssert.AreEqual(expectedKeys, actualKeys);
		}
Example #13
0
        public void TryGetValueWhenKeyExistsTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act
            string actualValue;
            var    actualExists = dict.TryGetValue(4, out actualValue);

            // Assert
            Assert.IsTrue(actualExists);
            Assert.AreEqual("5", actualValue);
        }
Example #14
0
        public void EnumerationIsOrderedTest()
        {
            // Arrange
            var dict = new InsertOrderedDictionary <int, string>
            {
                { 2, "3" },
                { 3, "4" },
                { 4, "5" },
                { 5, "1" },
                { 1, "2" }
            };

            // Act, Assert
            var expectedKvp = new[]
            {
                new KeyValuePair <int, string>(2, "3"),
                new KeyValuePair <int, string>(3, "4"),
                new KeyValuePair <int, string>(4, "5"),
                new KeyValuePair <int, string>(5, "1"),
                new KeyValuePair <int, string>(1, "2")
            };

            CollectionAssert.AreEqual(expectedKvp, dict);
        }
		public void EnumerationIsOrderedTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act, Assert
			var expectedKvp = new[]
			{
				new KeyValuePair<int, string>(2, "3"),
				new KeyValuePair<int, string>(3, "4"),
				new KeyValuePair<int, string>(4, "5"),
				new KeyValuePair<int, string>(5, "1"),
				new KeyValuePair<int, string>(1, "2")
			};

			CollectionAssert.AreEqual(expectedKvp, dict);
		}
        private static string AttachResources(IEnumerable<AbstractComponent> components, string config)
        {
            InsertOrderedDictionary<string, string> scripts = new InsertOrderedDictionary<string, string>();
            InsertOrderedDictionary<string, string> styles = new InsertOrderedDictionary<string, string>();
            List<string> ns = new List<string>();

            foreach (AbstractComponent seed in components)
            {
                ComponentLoader.FindResources(seed, scripts, styles, ns);
            }

            if (scripts.Count == 0 && styles.Count == 0 && ns.Count == 0)
            {
                return config;
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("{'x.res':{");
            
            
            if (ns.Count > 0)
            {
                sb.Append("ns:");
                sb.Append(JSON.Serialize(ns));
            }

            if (scripts.Count == 0 || styles.Count == 0)
            {
                if (ns.Count > 0)
                {
                    sb.Append(",");
                }

                sb.Append("res:[");

                bool comma = false;
                foreach (KeyValuePair<string, string> item in scripts)
                {
                    if (comma)
                    {
                        sb.Append(",");
                    }

                    comma = true;
                    sb.Append("{url:").Append(JSON.Serialize(item.Value)).Append("}");
                }

                foreach (KeyValuePair<string, string> item in styles)
                {
                    if (comma)
                    {
                        sb.Append(",");
                    }

                    comma = true;
                    sb.Append("{mode:\"css\",url:").Append(JSON.Serialize(item.Value)).Append("}");
                }

                sb.Append("]");
            }

            sb.Append("},config:").Append(JSON.Serialize(config));
            sb.Append("}");
            return sb.ToString();
        }
		public void RemoveKvpFailsWhenValueNotEqualTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			var actualRemoved = dict.Remove(new KeyValuePair<int, string>(4, "555"));

			// Assert
			var expectedKvp = new[]
			{
				new KeyValuePair<int, string>(2, "3"),
				new KeyValuePair<int, string>(3, "4"),
				new KeyValuePair<int, string>(4, "5"),
				new KeyValuePair<int, string>(5, "1"),
				new KeyValuePair<int, string>(1, "2")
			};

			Assert.IsFalse(actualRemoved);
			CollectionAssert.AreEqual(expectedKvp, dict);
		}
		public void ContainsKeyReturnsFalseWhenKeyDoesNotExistTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			var actualContains = dict.ContainsKey(6);

			// Assert
			Assert.IsFalse(actualContains);
		}
		public void InsertValueBeforeFirstKeyTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				// {2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			dict.InsertBefore(3, 2, "3");

			// Assert
			var expectedKvp = new[]
			{
				new KeyValuePair<int, string>(2, "3"),
				new KeyValuePair<int, string>(3, "4"),
				new KeyValuePair<int, string>(4, "5"),
				new KeyValuePair<int, string>(5, "1"),
				new KeyValuePair<int, string>(1, "2")
			};

			CollectionAssert.AreEqual(expectedKvp, dict);
		}
		public void ContainsReturnsFalseWhenValueIsNotEqualTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			var actualContains = dict.Contains(new KeyValuePair<int, string>(4, "555"));

			// Assert
			Assert.IsFalse(actualContains);
		}
		public void UpdateExistingValueUsingIndexerTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "444"},
				{4, "5"},
				{5, "111"},
				{1, "2"}
			};

			// Act
			dict[3] = "4";
			dict[5] = "1";

			// Assert
			var expectedKvp = new[]
			{
				new KeyValuePair<int, string>(2, "3"),
				new KeyValuePair<int, string>(3, "4"),
				new KeyValuePair<int, string>(4, "5"),
				new KeyValuePair<int, string>(5, "1"),
				new KeyValuePair<int, string>(1, "2")
			};

			CollectionAssert.AreEqual(expectedKvp, dict);
		}
		public void PrependItemTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				// {2, "3"},
				// {3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			dict.Prepend(3, "4");
			dict.Prepend(2, "3");

			// Assert
			var expectedKvp = new[]
			{
				new KeyValuePair<int, string>(2, "3"),
				new KeyValuePair<int, string>(3, "4"),
				new KeyValuePair<int, string>(4, "5"),
				new KeyValuePair<int, string>(5, "1"),
				new KeyValuePair<int, string>(1, "2")
			};

			CollectionAssert.AreEqual(expectedKvp, dict);
		}
        private static void CheckResources(BaseControl control, InsertOrderedDictionary<string, string> scripts, InsertOrderedDictionary<string, string> styles)
        {            
            foreach (ClientScriptItem item in control.GetScripts())
            {
                string resourcePath = GlobalConfig.Settings.ScriptMode == ScriptMode.Debug && item.PathEmbeddedDebug.IsNotEmpty() ? item.PathEmbeddedDebug : item.PathEmbedded;

                if (!scripts.ContainsKey(resourcePath))
                {
                    scripts.Add(resourcePath, ExtNetTransformer.GetWebResourceUrl(item.Type, resourcePath));
                }
            }

            foreach (ClientStyleItem item in control.GetStyles())
            {
                if (!styles.ContainsKey(item.PathEmbedded) && item.Theme.Equals(Theme.Default))
                {
                    styles.Add(item.PathEmbedded, ExtNetTransformer.GetWebResourceUrl(item.Type, item.PathEmbedded));
                }
            }
        }
		public void TryGetValueWhenKeyDoesNotExistTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			string actualValue;
			var actualExists = dict.TryGetValue(6, out actualValue);

			// Assert
			Assert.IsFalse(actualExists);
			Assert.IsNull(actualValue);
		}
		public void TryGetValueWhenKeyExistsTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			string actualValue;
			var actualExists = dict.TryGetValue(4, out actualValue);

			// Assert
			Assert.IsTrue(actualExists);
			Assert.AreEqual("5", actualValue);
		}
		public void GetValueUsingIndexerTest()
		{
			// Arrange
			var dict = new InsertOrderedDictionary<int, string>
			{
				{2, "3"},
				{3, "4"},
				{4, "5"},
				{5, "1"},
				{1, "2"}
			};

			// Act
			var actualValues = new[] { dict[2], dict[3], dict[4], dict[5], dict[1] };

			// Assert
			var expectedValues = new[] { "3", "4", "5", "1", "2" };

			CollectionAssert.AreEqual(expectedValues, actualValues);
		}
        private static void FindResources(Control seed, InsertOrderedDictionary<string, string> scripts, InsertOrderedDictionary<string, string> styles, List<string> ns)
        {            
            if (ReflectionUtils.IsTypeOf(seed, typeof(BaseControl), false))
            {
                BaseControl ctrl = (BaseControl)seed;

                ComponentLoader.CheckNS(ctrl, ns);
                ComponentLoader.CheckResources(ctrl, scripts, styles);
                ctrl.EnsureChildControlsInternal();
            }


            foreach (Control control in seed.Controls)
            {
                bool isBaseControl = ReflectionUtils.IsTypeOf(control, typeof(BaseControl), false);

                if (isBaseControl && !(control is UserControlLoader))
                {
                    BaseControl ctrl = (BaseControl)control;
                    ComponentLoader.CheckNS(ctrl, ns);
                    ComponentLoader.CheckResources(ctrl, scripts, styles);
                    ctrl.EnsureChildControlsInternal();                    
                }

                if (ControlUtils.HasControls(control))
                {
                    ComponentLoader.FindResources(control, scripts, styles, ns);
                }
            }
        }