Ejemplo n.º 1
0
        public void AddReceipt()
        {
            var receipts     = this.GetTestReceipts();
            var kindsOfGoods = new[] { new KindOfGoods {
                                           UId = Guid.NewGuid().ToString(), Name = "kind 01", Customized = true
                                       }, new KindOfGoods {
                                           UId = Guid.NewGuid().ToString(), Name = "kind 02", Customized = true
                                       } };

            receipts[0].KindOfGoods = kindsOfGoods[0];
            receipts[1].KindOfGoods = kindsOfGoods[1];
            var receiptDb = new ReceiptDb();

            kindsOfGoods.Each(k => receiptDb.Save(k));
            receiptDb.GetAll().Select(r => r.No).ToList().ForEach(n => receiptDb.Remove(n));

            // add one
            receiptDb.Save(receipts[0]);
            Assert.AreEqual(1, receiptDb.GetAll().Count());
            Assert.AreEqual(1, new ReceiptDb().GetAll().Count());
            var actual = receiptDb.GetAll().First();

            this.AssertAreEqual(receipts[0], actual);
            actual = new ReceiptDb().GetAll().First();
            this.AssertAreEqual(receipts[0], actual);
            actual = new ReceiptDb().Get(receipts[0].No);
            this.AssertAreEqual(receipts[0], actual);
            Assert.AreNotEqual(null, actual.KindOfGoods);
            Assert.AreEqual(receipts[0].ReceiptTankDetails.Count, actual.ReceiptTankDetails.Count);
            receipts[0].ReceiptTankDetails.ForEach(d => this.AssertAreEqual(d, actual.ReceiptTankDetails.First(actualDetail => actualDetail.TankName.Equals(d.TankName))));

            // add another
            receiptDb.Save(receipts[1]);
            Assert.AreEqual(2, receiptDb.GetAll().Count());
            Assert.AreEqual(2, new ReceiptDb().GetAll().Count());
            actual = receiptDb.GetAll().First(r => r.No.Equals(receipts[1].No));
            this.AssertAreEqual(receipts[1], actual);
            actual = new ReceiptDb().GetAll().First(r => r.No.Equals(receipts[1].No));
            this.AssertAreEqual(receipts[1], actual);
            actual = new ReceiptDb().Get(receipts[1].No);
            this.AssertAreEqual(receipts[1], actual);
            Assert.AreNotEqual(null, actual.KindOfGoods);
            Assert.AreEqual(receipts[1].ReceiptTankDetails.Count, actual.ReceiptTankDetails.Count);
            receipts[1].ReceiptTankDetails.ForEach(d => this.AssertAreEqual(d, actual.ReceiptTankDetails.First(actualDetail => actualDetail.TankName.Equals(d.TankName))));
        }
Ejemplo n.º 2
0
        public void RemoveReceipt()
        {
            var receipt   = this.GetTestReceipts()[0];
            var receiptDb = new ReceiptDb();

            receiptDb.Save(receipt);
            receiptDb.Remove(receipt.No);

            Assert.IsFalse(receiptDb.GetAll().Any(r => r.No.Equals(receipt.No)));
            Assert.IsFalse(new ReceiptDb().GetAll().Any(r => r.No.Equals(receipt.No)));
        }
Ejemplo n.º 3
0
        public void UpdateReceipt()
        {
            var receipt   = this.GetTestReceipts()[0];
            var receiptDb = new ReceiptDb();

            receiptDb.Save(receipt);
            receipt.AgentName   = "AgentName changed";
            receipt.TotalOfMass = 10101.010101m;
            receiptDb.Save(receipt);

            var actual = receiptDb.GetAll().First(r => r.No.Equals(receipt.No));

            Assert.AreEqual(receipt.AgentName, actual.AgentName);
            Assert.AreEqual(receipt.TotalOfMass, actual.TotalOfMass);
            actual = new ReceiptDb().GetAll().First(r => r.No.Equals(receipt.No));
            Assert.AreEqual(receipt.AgentName, actual.AgentName);
            Assert.AreEqual(receipt.TotalOfMass, actual.TotalOfMass);
            actual = new ReceiptDb().Get(receipt.No);
            Assert.AreEqual(receipt.AgentName, actual.AgentName);
            Assert.AreEqual(receipt.TotalOfMass, actual.TotalOfMass);
        }