示例#1
0
        public void MergeIsCommutative()
        {
            var testContext = new TestContext();

            Sku sku1 = testContext.CreateNewSku("A", 100);
            Sku sku2 = testContext.CreateNewSku("B", 200);
            Sku sku3 = testContext.CreateNewSku("C", 300);

            ICart cart1 = testContext.CartFactory.Create();

            cart1.Add(sku1);

            ICart cart2 = testContext.CartFactory.Create();

            cart2.Add(sku2);
            cart2.Add(sku3);

            ICart mergedCart1 = cart1.Merge(cart2);
            ICart mergedCart2 = cart2.Merge(cart1);

            Assert.Equal(mergedCart1.Quantity, mergedCart2.Quantity);
            Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku1));
            Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku2));
            Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku3));
            Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku1));
            Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku2));
            Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku3));
        }