public void LocateAssemblyByPartialNameThrowsException()
        {
            MockWebApplication app = new MockWebApplication();

            app.ThrowExceptionInGetAssmblies = true;
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions", "", "");
        }
        public void LocateAssemblyByPartialNameNotFound()
        {
            MockWebApplication app = new MockWebApplication();

            app.SetReferencedAssemblies(new List <string>());
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions", "", "");
        }
        public void WhenGetStringByAssembly_IfResourceFound_ShouldReturnResource()
        {
            // Act
            MockWebApplication app = new MockWebApplication();

            WebResourceReader reader = new WebResourceReader(app);

            // Assert
            Assert.AreEqual("dummyString", reader.GetString((Assembly)Assembly.GetExecutingAssembly(), "", ""));
        }
        public void WhenGetStringByAssembly_IfResourceNotFound_ShouldThrow()
        {
            // Act
            MockWebApplication app = new MockWebApplication();

            app.SetReturnValueForGetString("");
            WebResourceReader reader = new WebResourceReader(app);

            // Assert
            ExceptionAssert.Throws <WebTestException>(
                () => reader.GetString((Assembly)Assembly.GetExecutingAssembly(), "", ""));
        }
        public void WhenGetStringByAssembly_IfAssemblyIsNull_ShouldThrow()
        {
            // Act
            MockWebApplication app = new MockWebApplication();

            WebResourceReader reader = new WebResourceReader(app);

            // Assert
            ExceptionAssert.Throws <WebTestException>(
                () => reader.GetString((Assembly)null, "", ""),
                "Failed to load resource string. Assembly provided was null.");
        }
        public void TrimDllFromAssemblyName()
        {
            MockWebApplication app = new MockWebApplication();

            app.SetReferencedAssemblies(new List <string> {
                "System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            });
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions.dll", "", "");

            Assert.AreEqual("System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", app.AssemblyName);
        }
        public void WhenGetStringByAssembly_IfInnerException_ShouldThrow()
        {
            // Act
            MockWebApplication app = new MockWebApplication();

            app.ThrowExceptionOnGetResourceString = true;

            WebResourceReader reader = new WebResourceReader(app);

            // Assert
            ExceptionAssert.Throws <WebTestException>(
                () => reader.GetString((Assembly)Assembly.GetExecutingAssembly(), "", ""));
        }
        public void ThrowErrorIfGetStringReturnsEmptyString()
        {
            MockWebApplication app = new MockWebApplication();
            List <string>      asm = new List <string> {
                "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            };

            app.SetReferencedAssemblies(asm);
            app.SetReturnValueForGetString(String.Empty);
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions", "", "");
        }
        public void GetStringThrowsException()
        {
            MockWebApplication app = new MockWebApplication();
            List <string>      asm = new List <string> {
                "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            };

            app.SetReferencedAssemblies(asm);
            app.ThrowExceptionOnGetResourceString = true;
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions", "", "");
        }
        public void LocateAssemblyByFullNameWithProcessor()
        {
            MockWebApplication app = new MockWebApplication();
            List <string>      asm = new List <string> {
                "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL",
                "System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL",
            };

            app.SetReferencedAssemblies(asm);
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", "", "");

            Assert.AreEqual("System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL", app.AssemblyName);
        }
        public void LocateAssemblyByPartialNameMultipleMatches()
        {
            MockWebApplication app = new MockWebApplication();
            List <string>      asm = new List <string> {
                "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                "System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            };

            app.SetReferencedAssemblies(asm);
            WebResourceReader reader = new WebResourceReader(app);

            reader.GetString("System.Web.Extensions", "", "");

            Assert.AreEqual("System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", app.AssemblyName);
        }
        public void TriggerEventIfAttached()
        {
            ServiceLocator.WebResourceReader = new MockResourceReader();
            MockWebApplication app    = new MockWebApplication();
            WebResourceReader  reader = new WebResourceReader(app);

            string result = null;

            try
            {
                result = reader.GetString("System.Web.Extensions", "", "");
                Assert.AreEqual("my dummy string", result);
            }
            finally
            {
                ServiceLocator.WebResourceReader = null;
            }
        }