Click here to Skip to main content
15,884,353 members
Articles / Programming Languages / C#

In memory data access, a methodology to simplify agile development

Rate me:
Please Sign up or sign in to vote.
4.75/5 (11 votes)
25 Nov 2008CPOL5 min read 44.4K   304   40  
An article on architecting application layers to separate concerns and, particularly, data access.
using InMemoryDal.Logic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using InMemoryDal.Entities;

namespace InMemoryDal.Tests
{
    
    
    /// <summary>
    ///This is a test class for OrderLogicTest and is intended
    ///to contain all OrderLogicTest Unit Tests
    ///</summary>
    [TestClass()]
    public class OrderLogicTest
    {


        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)
        //{
        //}
        //
        //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 AddOrder
        ///</summary>
        [TestMethod()]
        public void AddOrderTest()
        {
            OrderLogic target = new OrderLogic();
            CustomerLogic customerLogic = new CustomerLogic();
            Customer customer = customerLogic.AddCustomer("Mike", "Smith", "First street 23, Boston, MA");
            Order actual = target.AddOrder(customer.Id);
            Assert.IsNotNull(actual);
            Assert.AreEqual("Mike", actual.Customer.Firstname);

        }

        [TestMethod(), ExpectedException(typeof(ArgumentException))]
        public void AddOrderExceptionTest()
        {
            OrderLogic target = new OrderLogic();
            Order actual = target.AddOrder(Guid.NewGuid());
        }

        /// <summary>
        ///A test for LoadOrderItems
        ///</summary>
        [TestMethod()]
        public void LoadOrderItemsTest()
        {
            OrderLogic orderLogic = new OrderLogic(); // TODO: Initialize to an appropriate value
            OrderItemLogic orderItemLogic = new OrderItemLogic();
            CustomerLogic customerLogic = new CustomerLogic();
            ProductLogic productLogic = new ProductLogic();
            Customer customer = customerLogic.AddCustomer("Mike", "Smith", "First street 23, Boston, MA");
            Order order = orderLogic.AddOrder(customer.Id);
            Assert.IsNotNull(order);
            Product product1 = productLogic.AddProduct("Wizard of Oz", 1, 10);
            Product product2 = productLogic.AddProduct("Wizard of Boz", 2, 1);
            OrderItem orderItem1 = orderItemLogic.AddOrderItem(product1.Id, order.Id, 12);
            OrderItem orderItem2 = orderItemLogic.AddOrderItem(product2.Id, order.Id, 1);
            orderLogic.LoadOrderItems(order);
            Assert.AreEqual(2, order.OrderItems.Count); 
           
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Italy Italy
Software architect. At present working on C# development, with mainly Asp.net Ajax and MVC user inteface. Particularly interested in OOP, test driven, agile development.

Comments and Discussions