A IResource adapter implementation encapsulating a simple string.
Inheritance: Spring.Core.IO.AbstractResource
コード例 #1
0
        public void ExecuteEmptyScript()
        {
            IResource scriptResource = new StringResource("");

            mocks.ReplayAll();

            SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP);
            mocks.VerifyAll();
        }
コード例 #2
0
        public void HashcodeIsCalculatedUsingResourceOnly()
        {
            StringResource testResource = new StringResource("test");
            EncodedResource er1 = new EncodedResource(testResource, Encoding.ASCII, true);
            EncodedResource er2 = new EncodedResource(testResource, Encoding.UTF8, false);

            Assert.AreEqual(testResource.GetHashCode(), er1.GetHashCode());
            Assert.AreEqual(er1.GetHashCode(), er2.GetHashCode());
        }
コード例 #3
0
        public void ExecuteSingleStatement()
        {
            IResource scriptResource = new StringResource("statement 1");

            Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "statement 1")).Return(0);
            mocks.ReplayAll();

            SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP);
            mocks.VerifyAll();
        }
コード例 #4
0
        public void ExecuteScriptWithMissingSeparatorOnLastBlock()
        {
            IResource scriptResource = new StringResource("\tstatement 1 \n\n\t GO\t \n   statement 2");

            Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "\tstatement 1 \n")).Return(0);
            Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "\n   statement 2")).Return(0);
            mocks.ReplayAll();

            SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_GO_EXP);
            mocks.VerifyAll();
        }
コード例 #5
0
 public void AcceptsNullContent()
 {
     Encoding utf7 = new UTF7Encoding();
     StringResource r = new StringResource(null, utf7);
     Assert.AreEqual(string.Empty, r.Content);
     Stream stm = r.InputStream;
     Assert.IsTrue(stm.CanRead);
     Assert.IsNotNull(stm);
     Assert.AreEqual(0, stm.Length);
     stm.Close();
 }
コード例 #6
0
        public void AppliesTxAttributeDrivenAttributes()
        {
            StringResource appCtxCfg = new StringResource(
                APPCTXCFG_START
                + "<tx:attribute-driven transaction-manager='otherTxManager' proxy-target-type='true' order='2' />"
                + APPCTXCFG_END);

            IApplicationContext appCtx = new ResourceXmlApplicationContext(appCtxCfg);
            //            DefaultAdvisorAutoProxyCreator daapc = (DefaultAdvisorAutoProxyCreator) appCtx.GetObject(AopNamespaceUtils.AUTO_PROXY_CREATOR_OBJECT_NAME);
            //            Assert.AreEqual(2, daapc.Order);
        }
コード例 #7
0
        public void ReturnsCorrectEncodedStream()
        {
            string FOO_CONTENT = "foo\u4567";
            StringResource r = new StringResource(FOO_CONTENT, Encoding.GetEncoding("utf-16"));
            Assert.AreEqual(FOO_CONTENT, r.Content);
            Stream istm = r.InputStream;
            Assert.IsTrue(istm.CanRead);

            byte[] chars = new byte[istm.Length];
            istm.Read(chars, 0, chars.Length);
            istm.Close();
            string result = Encoding.GetEncoding("utf-16").GetString( chars );
            Assert.AreEqual(FOO_CONTENT, result);
        }
コード例 #8
0
        public void EnsureDefaults()
        {
            Encoding enc = Encoding.Default;
            string FOO_CONTENT = "foo";
            string FOO_DESCRIPTION = "foo description";

            StringResource r = new StringResource(FOO_CONTENT);    
            Assert.AreEqual(FOO_CONTENT, r.Content);
            Assert.AreEqual(enc, r.Encoding);
            Assert.AreEqual(string.Empty, r.Description);

            enc = new UTF7Encoding();
            r = new StringResource(FOO_CONTENT, enc, FOO_DESCRIPTION);    
            Assert.AreEqual(FOO_CONTENT, r.Content);
            Assert.AreEqual(enc, r.Encoding);
            Assert.AreEqual(FOO_DESCRIPTION, r.Description);
        }
コード例 #9
0
        public void EnsureDefaults()
        {
            Encoding enc             = Encoding.Default;
            string   FOO_CONTENT     = "foo";
            string   FOO_DESCRIPTION = "foo description";

            StringResource r = new StringResource(FOO_CONTENT);

            Assert.AreEqual(FOO_CONTENT, r.Content);
            Assert.AreEqual(enc, r.Encoding);
            Assert.AreEqual(string.Empty, r.Description);

            enc = new UTF7Encoding();
            r   = new StringResource(FOO_CONTENT, enc, FOO_DESCRIPTION);
            Assert.AreEqual(FOO_CONTENT, r.Content);
            Assert.AreEqual(enc, r.Encoding);
            Assert.AreEqual(FOO_DESCRIPTION, r.Description);
        }
コード例 #10
0
        public void ExecuteScriptWithSemicolonSeparatedStatements()
        {
            IResource scriptResource = new StringResource("\tstatement 1  ;\nGO\n   statement 2;");

            Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "\tstatement 1  ")).Return(0);
            Expect.Call(adoTemplate.ExecuteNonQuery(CommandType.Text, "\nGO\n   statement 2")).Return(0);
            mocks.ReplayAll();

            SimpleAdoTestUtils.ExecuteSqlScript(adoTemplate, scriptResource, false, SimpleAdoTestUtils.BLOCKDELIM_SEMICOLON_EXP);
            mocks.VerifyAll();
        }
コード例 #11
0
        public void DoesntSupportRelativeResources()
        {
            StringResource r = new StringResource(string.Empty);

            Assert.Throws <NotSupportedException>(() => r.CreateRelative("foo"));
        }
コード例 #12
0
 public void AlwaysExists()
 {
     StringResource r = new StringResource(null);
     Assert.IsTrue(r.Exists);
     r = new StringResource(string.Empty);
     Assert.IsTrue(r.Exists);
     r = new StringResource("foo");
     Assert.IsTrue(r.Exists);
 }
コード例 #13
0
 public void DoesntSupportRelativeResources()
 {
     StringResource r = new StringResource(string.Empty);
     r.CreateRelative("foo");
 }
コード例 #14
0
        public void DoesntSupportRelativeResources()
        {
            StringResource r = new StringResource(string.Empty);

            r.CreateRelative("foo");
        }
コード例 #15
0
 public void DoesntSupportRelativeResources()
 {
     StringResource r = new StringResource(string.Empty);
     Assert.Throws<NotSupportedException>(() => r.CreateRelative("foo"));
 }