예제 #1
0
        public void SupportKnownValuesDuringEqualityCheck()
        {
            var sut = new InvoiceItem("1", 1, 1);

            Assert.False(sut.Equals(null));
            Assert.False(sut.Equals((object)null));
            Assert.True(sut.Equals((object)sut));
            object other = "other type";

            Assert.False(sut.Equals(other));
        }
예제 #2
0
        public void BeEqualBySimilarity(
            string productId1,
            decimal price1,
            uint amount1,
            string productId2,
            decimal price2,
            uint amount2,
            bool expected)
        {
            var sut   = new InvoiceItem(productId1, price1, amount1);
            var other = new InvoiceItem(productId2, price2, amount2);

            Assert.Equal(expected, sut.Equals(other));
            Assert.Equal(expected, sut.Equals((object)other));
            Assert.Equal(expected, sut == other);
            Assert.Equal(expected, !(sut != other));
            Assert.Equal(expected, sut.GetHashCode() == other.GetHashCode());
        }
예제 #3
0
        public void Equals_Test_TypeMismatch()
        {
            // arrange
            InvoiceItem a = new InvoiceItem {
                Description = "Item", Amount = 2.50M
            };
            int b = 0;

            // act/assert
            Assert.Throws <InvalidOperationException>(() => a.Equals(b));
        }
예제 #4
0
        public void Equals_Test_AreEqual()
        {
            // arrange
            InvoiceItem a = new InvoiceItem {
                Description = "Item", Amount = 2.50M
            };
            InvoiceItem b = new InvoiceItem {
                Description = "Item", Amount = 2.50M
            };

            // act/assert
            Assert.IsTrue(a.Equals(b));
        }
예제 #5
0
        public void Equals_Test_AreNotEqual(string descriptionA, decimal amountA,
                                            string descriptionB, decimal amountB)
        {
            // arrange
            InvoiceItem a = new InvoiceItem {
                Description = descriptionA, Amount = amountA
            };
            InvoiceItem b = new InvoiceItem {
                Description = descriptionB, Amount = amountB
            };

            // act/assert
            Assert.IsFalse(a.Equals(b));
        }