none
Testing EF - how to quickly render an input form RRS feed

  • Question

  • Hi all,

    I am tesing EF and have built up some entities that represent some of our key data/bus objects.  Now I need to test.  It's easy to test data retrieval.  But I need to do some inserts as well.

    I am hoping that someone out there knows of a tool that can take a class and generate a seriese of textboxes that can be used to input data for testing.  At first, I was going to just do a bunch of ctx.entity.property = "some value", but this doesn't allow for some of the varieties that will be encountered, especially with child tables.

    Any help is appreciated...

    me


    FletcherJ
    Tuesday, August 9, 2011 9:47 PM

Answers

  • Thanks for the info.  This isn't really what I was looking for, but it does have some usefull info.  I have written a small program that just creates a bunch of lines that are hardcoded that populate all the values of the entity from an exisitng table.  Then I tweeked that a bit so the values are not dups and it is what I need to test.

    I was kinda figuring that someone had some code that would parse the xml info and create a set of labels and textboxes that would allow me to just input the values for a given entity, but I guess I will need to write one in my spare time (from 1 am - 3am)...

    Thanks,

    me


    FletcherJ
    • Marked as answer by FletcherJ Thursday, August 18, 2011 10:57 PM
    Friday, August 12, 2011 9:19 PM

All replies

  • On 8/9/2011 5:47 PM, FletcherJ wrote:
    > Hi all,
    >
    > I am tesing EF and have built up some entities that represent some of
    > our key data/bus objects. Now I need to test. It's easy to test data
    > retrieval. But I need to do some inserts as well.
    >
    > I am hoping that someone out there knows of a tool that can take a class
    > and generate a seriese of textboxes that can be used to input data for
    > testing. At first, I was going to just do a bunch of ctx.entity.property
    > = "some value", but this doesn't allow for some of the varieties that
    > will be encountered, especially with child tables.
    >
    > Any help is appreciated...
    >
    Why wouldn't you be doing functional testing with a test harness like
    MBunit, Nunit etc to make these objects from data you give in the
    functional tests? You should be able to run the tests from the VS IDE
    that does Unit Testing.
     
    The functional tests are testing the DAL methods for expected results
    which are using the Entity Framework in the DAL below. Either you pass
    the test, you fail the test or it blew-up. BUT you don't need the UI and
    textboxes to do a functional test, and you can give the string
    information for the functional tests and pass the data to the method,
    like using a List<String>.
     
    Oh, the connection string for EF must be placed in the app.config of the
    functional testing project.
     
     
    using System;
    using DataAccessLayer;
    using MbUnit.Framework;
     
    namespace FunctionalTests.DAL
    {
        [TestFixture]
        public class DalTests
        {
             [Test]
             public void GetAuthors()
             {
                try
                {
                     var authors = new Author().GetAuthors();
                     Assert.IsTrue(authors.Count > 0);
                }
                catch (Exception ex)
                {
                     Assert.Fail(ex.ToString());
                }
             }
              [Test]
             public void GetAuthorsWhere()
             {
                 try
                 {
                     var authors = new Author().GetAuthorsWhere();
                     Assert.IsTrue(authors.Count > 0);
                 }
                 catch (Exception ex)
                 {
                     Assert.Fail(ex.ToString());
                 }
             }
    >
             [Test]
             [Row(1)]
             public void GetPayRollByAuthorID(int id)
             {
                 try
                 {
                     var payroll = new PayRoll().GetPayRollByAuthorID(id);
                     Assert.IsNotNull(payroll.AuthorID = id);
                 }
                 catch (Exception ex)
                 {
                     Assert.Fail(ex.ToString());
                 }
             }
         }
     }
     Here is the DAL for Payroll where GetPayRollByAuthorID() functional test
    was run to test functionality of the method.
      using System.Linq;
     using DataAccessLayer.Model;
     using DataAccessLayer.DTO;
     using System.Data.EntityClient;
     using DataAccessLayer.IDAL;
      namespace DataAccessLayer
     {
         public class PayRoll :IPayRoll
         {
             private const string pcdb = "name=PublishingCompanyEntities";
              public Payroll GetPayRollByAuthorID(int id)
             {
                 var payroll = new Payroll();
                  using (var conn = new EntityConnection(pcdb))
                 using (var db = new PublishingCompanyEntities(conn))
                 {
                     try
                     {
                         var thepayroll = (from p in db.Payrolls
                                    where p.Author.AuthorID == id
                         select p).FirstOrDefault();
                          if (thepayroll != null)
                             payroll = thepayroll;
                     }
                     finally
                     {
                         conn.Close();
                     }
                 }
                  return payroll;
             }
              public Payroll AddPayRoll(DTOPayroll pr)
             {
                 var payroll = new Payroll {AuthorID = pr.AuthorID, Salary
    = pr.Salary};
                  using (var conn = new EntityConnection(pcdb))
                 using (var db = new PublishingCompanyEntities(conn))
                 {
                     try
                     {
                         db.AddToPayrolls(payroll);
                         db.SaveChanges();
                     }
                     finally
                     {
                         conn.Close();
                     }
                 }
                  return payroll;
             }
              public void UpdatePayRollSalary(DTOPayroll pr)
             {
                 var payroll = new Payroll {PayrollID = pr.PayRollID};
                  using (var conn = new EntityConnection(pcdb))
                 using (var db = new PublishingCompanyEntities(conn))
                 {
                     try
                     {
                         db.AttachTo("Payrolls", payroll);
                         payroll.AuthorID = pr.AuthorID;
                         payroll.Salary = pr.Salary;
                         db.SaveChanges();
                     }
                     finally
                     {
                         conn.Close();
                     }
                 }
             }
              public void DeletePayRoll(DTOPayroll pr)
             {
                 var payroll = new Payroll { PayrollID = pr.PayRollID };
                  using (var conn = new EntityConnection(pcdb))
                 using (var db = new PublishingCompanyEntities(conn))
                 {
                     try
                     {
                         db.AttachTo("Payrolls", payroll);
                         db.DeleteObject(payroll);
                         db.SaveChanges();
                     }
                     finally
                     {
                         conn.Close();
                     }
                 }
             }
         }
     }
     
     
    Wednesday, August 10, 2011 2:08 AM
  • Thanks for the info.  This isn't really what I was looking for, but it does have some usefull info.  I have written a small program that just creates a bunch of lines that are hardcoded that populate all the values of the entity from an exisitng table.  Then I tweeked that a bit so the values are not dups and it is what I need to test.

    I was kinda figuring that someone had some code that would parse the xml info and create a set of labels and textboxes that would allow me to just input the values for a given entity, but I guess I will need to write one in my spare time (from 1 am - 3am)...

    Thanks,

    me


    FletcherJ
    • Marked as answer by FletcherJ Thursday, August 18, 2011 10:57 PM
    Friday, August 12, 2011 9:19 PM