|
| 1 | +/****************************************************************************** |
| 2 | + Copyright (c) 2011 Seth H. Richards |
| 3 | + |
| 4 | + Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + of this software and associated documentation files (the "Software"), to deal |
| 6 | + in the Software without restriction, including without limitation the rights |
| 7 | + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + copies of the Software, and to permit persons to whom the Software is |
| 9 | + furnished to do so, subject to the following conditions: |
| 10 | + The above copyright notice and this permission notice shall be included in |
| 11 | + all copies or substantial portions of the Software. |
| 12 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | + THE SOFTWARE. |
| 19 | +******************************************************************************/ |
| 20 | + |
| 21 | +using System; |
| 22 | +using System.Text; |
| 23 | +using System.Collections.Generic; |
| 24 | +using System.Linq; |
| 25 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 26 | +using System.Data.SqlClient; |
| 27 | +using shr.Visualizers.SqlCommandVisualizer; |
| 28 | +using System.Data; |
| 29 | + |
| 30 | +namespace VisualizerTests |
| 31 | +{ |
| 32 | + /// <summary> |
| 33 | + /// Summary description for TSqlGeneratorTests |
| 34 | + /// </summary> |
| 35 | + [TestClass] |
| 36 | + public class TSqlGeneratorTests |
| 37 | + { |
| 38 | + public TSqlGeneratorTests() |
| 39 | + { |
| 40 | + // |
| 41 | + // TODO: Add constructor logic here |
| 42 | + // |
| 43 | + } |
| 44 | + |
| 45 | + private TestContext testContextInstance; |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + ///Gets or sets the test context which provides |
| 49 | + ///information about and functionality for the current test run. |
| 50 | + ///</summary> |
| 51 | + public TestContext TestContext |
| 52 | + { |
| 53 | + get |
| 54 | + { |
| 55 | + return testContextInstance; |
| 56 | + } |
| 57 | + set |
| 58 | + { |
| 59 | + testContextInstance = value; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + #region Additional test attributes |
| 64 | + // |
| 65 | + // You can use the following additional attributes as you write your tests: |
| 66 | + // |
| 67 | + // Use ClassInitialize to run code before running the first test in the class |
| 68 | + // [ClassInitialize()] |
| 69 | + // public static void MyClassInitialize(TestContext testContext) { } |
| 70 | + // |
| 71 | + // Use ClassCleanup to run code after all tests in a class have run |
| 72 | + // [ClassCleanup()] |
| 73 | + // public static void MyClassCleanup() { } |
| 74 | + // |
| 75 | + // Use TestInitialize to run code before running each test |
| 76 | + // [TestInitialize()] |
| 77 | + // public void MyTestInitialize() { } |
| 78 | + // |
| 79 | + // Use TestCleanup to run code after each test has run |
| 80 | + // [TestCleanup()] |
| 81 | + // public void MyTestCleanup() { } |
| 82 | + // |
| 83 | + #endregion |
| 84 | + |
| 85 | + [TestMethod] |
| 86 | + public void Can_Generate_SQL_For_Single_Parameter() |
| 87 | + { |
| 88 | + SqlCommand Cmd = new SqlCommand(); |
| 89 | + Cmd.Parameters.AddWithValue("@IntParam", 33); |
| 90 | + TSqlGenerator Generator = new TSqlGenerator(Cmd); |
| 91 | + |
| 92 | + Assert.AreEqual(1, Generator.Declarations.Count); |
| 93 | + Assert.AreEqual(1, Generator.Assignments.Count); |
| 94 | + } |
| 95 | + |
| 96 | + [TestMethod] |
| 97 | + public void Param_Without_Value_Should_Only_Generate_Declaration() |
| 98 | + { |
| 99 | + SqlCommand Cmd = new SqlCommand(); |
| 100 | + Cmd.Parameters.Add("@Param", SqlDbType.Int); |
| 101 | + |
| 102 | + TSqlGenerator Generator = new TSqlGenerator(Cmd); |
| 103 | + Assert.AreEqual(1, Generator.Declarations.Count); |
| 104 | + Assert.AreEqual(0, Generator.Assignments.Count); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments