public void SetNoteLineItemToNote_CorrectItemAndNote()
        {
            PrepareNoteLineItemData.DeleteAllSampleData();
            PrepareDeliveryNoteData.DeleteAllSampleData();

            DeliveryNote note = new DeliveryNote();
            note = PrepareDeliveryNoteData.SampleData();
            deliveryNoteDAO.CreateDeliveryNote(note);

            NoteLineItem item = new NoteLineItem();
            item = PrepareNoteLineItemData.Sample();
            noteLineItemDAO.CreateNoteLineItem(item);

            // Method ที่ต้องการ Test---------------

            noteLineItemService.SetNoteLineItemToNote(item.Id, note.Id);

            //------------------------------------------

            ManeeDataContainer context = new ManeeDataContainer();
            NoteLineItem itemInDB = context.NoteLineItems.Where(m => m.ItemCode == item.ItemCode).FirstOrDefault();
            DeliveryNote noteInDB = context.DeliveryNotes.Where(m => m.Code == note.Code).FirstOrDefault();
            int expectedDeliveryNoteId = noteInDB.Id;

            int accualDeliveryNoteId = itemInDB.DeliveryNote.Id;

            //ต้องลบ NoteLinteItem ก่อนเพราะเรื่อง Foreign Key

            PrepareNoteLineItemData.DeleteAllSampleData();
            PrepareDeliveryNoteData.DeleteAllSampleData();

            Assert.AreEqual(expectedDeliveryNoteId, accualDeliveryNoteId, "Failed");
        }
 public static void DeleteAllSampleData()
 {
     ManeeDataContainer context = new ManeeDataContainer();
         List<DeliveryNote> dns = context.DeliveryNotes.Where(b => b.Code == "DN001").ToList();
         IDeliveryNoteDAO dnDao = (IDeliveryNoteDAO)DAOFactory.GetDao("DELIVERY_NOTE");
         foreach(DeliveryNote dn in dns)
         {
             dnDao.DeleteDeliveryNote(dn.Id);
         }
 }
        public static NoteLineItem Sample()
        {
            ILocationDAO locationDAO = (ILocationDAO)DAOFactory.GetDao("LOCATION");
            ManeeDataContainer context = new ManeeDataContainer();

            NoteLineItem item = new NoteLineItem();
            item.Id=0;
            item.ItemCode = "LK-001";
            item.ItemDescription = "steel";

            item.Location = new Location();
            item.Location.Id = context.Locations.FirstOrDefault(m=>m.Id==2).Id;
            item.Quantity=1;
            item.Status = 1;
            item.Unit = "ton";
            return item;
        }
        public static DeliveryNote SampleData()
        {
            ManeeDataContainer context = new ManeeDataContainer();
                DeliveryNote note = new DeliveryNote();

                note.Code = "DN001";
                note.DeliveryDate = DateTime.Now;
                note.Id = 0;
                note.Destination = new Location();
                note.Destination.Id = context.Locations.FirstOrDefault(b => b.Id == 2).Id;
                note.Origin =new Location() ;
                note.Origin.Id = context.Locations.FirstOrDefault(b=>b.Id==3).Id;

                //note.Destination = context.Locations.FirstOrDefault(b => b.Id == 2);
                //note.Origin = context.Locations.FirstOrDefault(b => b.Id == 3);

                note.SenderCode = "Sender1";
                note.SenderName = "SS";
                note.CarType = "Car";
                note.CarLicensePlate = "a-222";
                return note;
        }