Ejemplo n.º 1
0
        public Guid AddStore(string StoreName, string StoreAddress)
        {
            var newStore = new StoreDoc {
                StoreName = StoreName, StoreAddress = StoreAddress
            };

            AddOne(newStore);
            return(newStore.Id);
        }
Ejemplo n.º 2
0
        public void TestCompositeIdAndCascade()
        {
            const string docRef = "123";

            Product product = new Product();

            product.RefCode = "PROD" + docRef;
            product.Caption = ProductCaption;
            product.Save();

            StoreDoc doc = new StoreDoc();

            doc.RefNum = docRef;

            StoreDocLine line1 = new StoreDocLine();

            line1.Doc      = doc;
            line1.Position = 1;
            line1.Product  = product;
            line1.Quantity = 10;

            StoreDocLine line2 = new StoreDocLine();

            line2.Doc      = doc;
            line2.Position = 2;
            line2.Product  = product;
            line2.Quantity = 15;

            UnitOfWork uow = new UnitOfWork();

            uow.Save(doc);
            uow.Save(line1);
            uow.Save(line2);
            uow.Commit();

            doc.Refresh();
            Assert.AreEqual(2, doc.Lines.Count);

            SessionManager.CloseSession();
            StoreDoc doc2 = StoreDoc.GetByRefNum(docRef);

            Assert.IsNotNull(doc2, "Document was not saved. Ref: {0}", docRef);
            Assert.AreEqual(2, doc2.Lines.Count, "Document lines was not saved. Ref: {0}", docRef);
            int docId = doc2.Id;

            doc2.Delete();

            SessionManager.CloseSession();
            StoreDoc doc3 = StoreDoc.GetByRefNum(docRef);

            Assert.IsNull(doc3, "Document was not deleted. Ref: {0}", docRef);
            IList <StoreDocLine> lines3 = StoreDocLine.GetCollectionByStoreDocId(docId);

            Assert.IsNotNull(lines3, "Collection is null");
            Assert.AreEqual(0, lines3.Count, "Collection is not empty");
        }