Esempio n. 1
0
        public void RegisterResource_AlreadyRegisteredResource_ExceptionIsThrown()
        {
            // Arrange
            string          registerName = "TestRegister";
            HttpContextBase context      = this.CreateHttpContext();
            var             register     = new ResourceRegister(registerName, context);

            string fakeResourceKey = "test-resource";

            register.RegisterResource(fakeResourceKey);
            Assert.IsTrue(register.Container.Count(i => i == fakeResourceKey) == 1);

            // Act
            register.RegisterResource(fakeResourceKey);

            // Assert
            Assert.IsTrue(register.Container.Count(i => i == fakeResourceKey) == 1);
        }
Esempio n. 2
0
        public void TryRegisterResource_AlreadyRegisteredResource_ResourceIsNotRegisteredTwice()
        {
            // Arrange
            string          registerName = "TestRegister";
            HttpContextBase context      = this.CreateHttpContext();
            var             register     = new ResourceRegister(registerName, context);

            string fakeResourceKey = "test-resource";

            register.RegisterResource(fakeResourceKey);
            Assert.IsTrue(register.Container.Count(i => i == fakeResourceKey) == 1);

            // Act
            bool result = register.TryRegisterResource(fakeResourceKey);

            // Assert
            Assert.IsFalse(result);
            Assert.IsTrue(register.Container.Count(i => i == fakeResourceKey) == 1);
        }
Esempio n. 3
0
        /// <summary>
        /// Registers resource reference.
        /// </summary>
        /// <param name="register">The register.</param>
        /// <param name="resourceKey">The resource key.</param>
        /// <param name="throwException">if set to <c>true</c> [throw exception].</param>
        /// <param name="tagName">Name of the tag.</param>
        /// <param name="attribbutes">The attribbutes.</param>
        /// <returns></returns>
        private static MvcHtmlString RegisterResource(ResourceRegister register, string resourceKey, bool throwException, string tagName, KeyValuePair <string, string>[] attribbutes)
        {
            string        output;
            MvcHtmlString result;

            if (throwException)
            {
                register.RegisterResource(resourceKey);
                output = ResourceHelper.GenerateTag(tagName, attribbutes);
                result = new MvcHtmlString(output);
            }
            else if (register.TryRegisterResource(resourceKey))
            {
                output = ResourceHelper.GenerateTag(tagName, attribbutes);
                result = new MvcHtmlString(output);
            }
            else
            {
                result = MvcHtmlString.Empty;
            }

            return(result);
        }