public override void TrackChange(Product p1, Product p2, ref PChange change)
 {
     baseComparer.Compare(p1, p2, ref change);
     if (((AdvancedProduct)p1).CurrentVersion != ((AdvancedProduct)p2).CurrentVersion)
     {
         change.CurrentVersion = true;
     }
 }
 public override void TrackChange(Product p1, Product p2, ref PChange change)
 {
     baseComparer.Compare(p1, p2, ref change);
     if (p1.CurrentVersion != p2.CurrentVersion)
     {
         change.CurrentVersion = true;
     }
 }
    public bool Equals(Product p1, Product p2)
    {
        PChanges newChange = new PChanges();

        comparer.Compare(p1, p2, ref newChange);

        this.change = newChange;
        return(newChange.CurrentVersion || newChange.NameChange);
    }
Ejemplo n.º 4
0
        public void CompareShouldThrowArgumentNullExceptionWhenConsumptionLessThanZero()
        {
            // Arrange
            var consumption     = -300;
            var productComparer = new ProductComparer();

            // Act
            productComparer.Compare(consumption);
        }
        public void Compare_Products_ShouldCompareProducts(long consumptionProductLeft,
                                                           long consumptionProductRight,
                                                           int comparisonResult)
        {
            // Arrange
            var productComparer = new ProductComparer <Product>();

            // Act
            Product productLeft  = Product.Create("pLeft", consumptionProductLeft, new BasicTariffCalculator());
            Product productRight = Product.Create("pRight", consumptionProductRight, new BasicTariffCalculator());

            // Assert
            Assert.Equal(comparisonResult, productComparer.Compare(productLeft, productRight));
        }
Ejemplo n.º 6
0
            public static void Main()
            {
                IComparer <Product> comp  = new ProductComparer();
                Product             book  = new Product(name: "C++ Primer", price: 100);
                Product             book2 = new Product(name: "C++ Primer", price: 10);
                Product             pc    = new Product(name: "Apple PC", price: 10000);
                Product             hdd   = new Product(name: "Seagate 1TB", price: 100);
                Product             bbc   = new Product(name: "BBC", price: 5);

                Product[] products = new Product[] { book, book2, pc, hdd, bbc };
                Array.Sort(products, comp);
                foreach (Product p in products)
                {
                    Console.WriteLine($"{p.Name}:{p.Price}");
                }
                Product bbc2 = new Product(name: "BBC", price: 5);

                Console.WriteLine(comp.Compare(bbc2, bbc));//引用对象地址不同,comp.Compare方法返回比较的属性相同
                Product none = null;

                Console.WriteLine(comp.Compare(none, bbc) == 0);
                Console.ReadKey();
            }
Ejemplo n.º 7
0
        public void CompareShouldReturnListWithCorrectOrder()
        {
            // Arrange
            var productComparer = new ProductComparer();
            var product1        = new Product(TariffConstants.BasicTariffName);
            var product2        = new Product(TariffConstants.PackagedTariffName);
            var expectedResult  = new List <Product>();

            expectedResult.Add(product2);
            expectedResult.Add(product1);

            // Act
            productComparer.Add(product1);
            productComparer.Add(product2);
            var actualResult = productComparer.Compare(3400).ToList();

            // Assert
            CollectionAssert.AreEqual(expectedResult, actualResult);
        }