HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Online food ordering application structure

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
applicationorderingonlinestructurefood

Problem

I am not sure what I am doing is right or not and am looking for experienced opinions.

Entity Example

namespace Entities.Shop
{
    public class Shop
    {
        public virtual int ShopId { get; set; }
        public virtual string ShopName { get; set; }
        public virtual IList ShopScores { get; set; }
        public virtual IList ShopPromotions { get; set; }

        public virtual IList Menus { get; set; }

        public virtual Address.Address Address { get; set; }

        public virtual IList DeliveryDistricts { get; set; }
        public virtual IList PaymentMethods { get; set; }
        public virtual IList WorkHours { get; set; }

        public virtual int Status { get; set; }
        public virtual int Activity { get; set; }
        public virtual int Available { get; set; }
    }

    public class ShopScore
    {
        public virtual int ShopScoreId { get; set; }
        public virtual int ShopScoreTypeId { get; set; }
        public virtual int Score { get; set; }
    }

    public class ShopScoreType
    {
        public virtual int ShopScoreTypeId { get; set; }
        public virtual string ShopScoreTypeName { get; set; }
    }

    public class ShopPromotion
    {
        public virtual int ShopPromotionId { get; set; }
        public virtual int ShopPromotionTypeId { get; set; }
    }

    public class ShopPromotionType
    {
        public virtual int ShopScoreTypeId { get; set; }
        public virtual string ShopScoreTypeName { get; set; }
    }

    public class DeliveryDistrict
    {
        public virtual int DeliveryDistrictId { get; set; }
        public virtual Location.District District { get; set; }
        public virtual int MinimumPaymentAmount { get; set; }
    }

    public class WorkHour
    {
        public virtual int WorkHourId { get; set; }
        public virtual int Day { get; set; }
        public virtual string OpenAt { get; set; }
        public virtual string CloseAt { get; set; }
    }
}


Business Layer R

Solution

Browsing over the code one issue which jumped at me is the fact you have a tight coupling between your business layer and data access layer. Your BL is calling straight into the DAL by calling DAL.Entity.CRUD.Whatever(). This means that if you want to unit test your BL all of a sudden you have to set up a repository (most likely a database) while you should not have to. Testing the BL should not require to set up any other layer.

One way to achieve that is by injecting an interface to the DAL into the BL and all your test for BL.Shop.READ.All() then cares about is the appropriate method on the injected DAL interface was called. Then use a mocking framework like RhinoMocks or Moq to mock the DAL interface.

Context

StackExchange Code Review Q#43898, answer score: 5

Revisions (0)

No revisions yet.