Announcement

Collapse
No announcement yet.

NUnit Datenbankzugriff

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • NUnit Datenbankzugriff

    Einen wunderschönen guten morgen allerseits.

    und zwar hab ich ein problem. ich möchte gerne einen unit test ausführen über nunit der sich daten aus einer datenbank holt. mit visual studio hat das auch ganz gut funktioniert, nur soll das ganz jetzt über NUnit laufen.
    nun hab ich mal angefangen den code auf NUnit umzustellen, nur leider hat er noch ein problem mit dem datenbankzugriff.
    meine vermutung ist dass es an der "TestContext" Anweisung liegt, dass diese nur bei Visual Studio funktioniert. kann mir an der stelle jemand weiterhelfen oder hat schonmal jemand dieses problem gehabt?

    vielen dank für eure hilfe

    Kim

    Code:
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using NUnit.Framework;
    
    
    
    
    
    namespace TestProject2
    {
        
        
        /// <summary>
        ///This is a test class for PreisberechnungTest and is intended
        ///to contain all PreisberechnungTest Unit Tests
        ///</summary>
        [TestFixture]
        public class PreisberechnungTest
        {
    
    
            private TestContext testContextInstance;
    
            /// <summary>
            ///Gets or sets the test context which provides
            ///information about and functionality for the current test run.
            ///</summary>
            public TestContext TestContext
            {
                get
                {
                    return testContextInstance;
                }
                set
                {
                    testContextInstance = value;
                }
            }
    
            #region Additional test attributes
            // 
            //You can use the following additional attributes as you write your tests:
            //
            //Use ClassInitialize to run code before running the first test in the class
            [ClassInitialize()]
            public static void MyClassInitialize(TestContext testContext)
            {
                DataGenerator.Generate();
            }
            //
            //Use ClassCleanup to run code after all tests in a class have run
            //[ClassCleanup()]
            //public static void MyClassCleanup()
            //{
            //}
            //
            //Use TestInitialize to run code before running each test
            //[TestInitialize()]
            //public void MyTestInitialize()
            //{
            //}
            //
            //Use TestCleanup to run code after each test has run
            //[TestCleanup()]
            //public void MyTestCleanup()
            //{
            //}
            //
            #endregion
    
    
            /// <summary>
            ///A test for GetPreis
            ///</summary>
    
            [Test]
            [DataSource("System.Data.SqlClient", 
                "Data Source=jwvirtual\\sqlexpress;Initial Catalog = Testing;Integrated Security=True", "Preisberechnung",
                DataAccessMethod.Sequential)]
            public void GetPreisTest()
            {
    
                string Artikelnummer = (string)TestContext.DataRow["Artikel"];
                Artikel xArtikel = DataGenerator.GetArtikel(Artikelnummer);
    
    
                int Kundennummer = (int)TestContext.DataRow["Kunde"];
                Kunde xKunde = DataGenerator.GetKunde(Kundennummer);
    
    
               
                decimal expected2 = (decimal)TestContext.DataRow["Ergebnis"];
                double expected = Convert.ToDouble(expected2);
                double actual;
                actual = Preisberechnung.GetPreis(xArtikel, xKunde);
                double x = Math.Round(actual, 2);
                Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(expected, x);
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }
    
    
            /// <summary>
            ///A test for Preisberechnung Constructor
            ///</summary>
            //[TestMethod()]
            //public void PreisberechnungConstructorTest()
            //{
            //    Preisberechnung target = new Preisberechnung();
            //    Assert.Inconclusive("TODO: Implement code to verify target");
            //}
        }
    }
Working...
X