Ejemplo n.º 1
0
        public static void Like <T>(T expected, T actual)
        {
            Likeness <T> likeness = new Likeness <T>(expected);

            if (!likeness.Equals(actual))
            {
                throw new EqualException(expected, actual);
            }
        }
Ejemplo n.º 2
0
        public void ConvertWillReturnCorrectResult()
        {
            // Fixture setup
            var fixture         = new CurrencyFixture();
            var currency        = fixture.CreateAnonymous <Currency>();
            var sut             = fixture.CreateAnonymous <Product>();
            var expectedProduct = new Likeness <Product, Product>(sut.WithUnitPrice(sut.UnitPrice.ConvertTo(currency)));
            // Exercise system
            Product result = sut.ConvertTo(currency);

            // Verify outcome
            Assert.True(expectedProduct.Equals(result));
            // Teardown
        }
Ejemplo n.º 3
0
        public void WithUnitPriceWillReturnCorrectResult()
        {
            // Fixture setup
            var fixture        = new Fixture();
            var sut            = fixture.CreateAnonymous <Product>();
            var newUnitPrice   = fixture.CreateAnonymous <Money>();
            var expectedResult = new Likeness <Product, Product>(new Product(sut.Id, sut.Name, newUnitPrice));
            // Exercise system
            Product result = sut.WithUnitPrice(newUnitPrice);

            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
Ejemplo n.º 4
0
        public void WithItemWillReturnCorrectExtent()
        {
            // Fixture setup
            var fixture        = new Fixture();
            var sut            = fixture.CreateAnonymous <Extent>();
            var newItem        = fixture.CreateAnonymous <Product>();
            var expectedResult = new Likeness <Extent, Extent>(new Extent(newItem)
            {
                Quantity = sut.Quantity, Updated = sut.Updated
            }).Without(d => d.Total);
            // Exercise system
            Extent result = sut.WithItem(newItem);

            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
Ejemplo n.º 5
0
        public void ParseValidArgsWillReturnCorrectResult(decimal rate, Mock <Currency> currencyStub, [Frozen] Mock <CurrencyProvider> currencyProviderStub, CurrencyParser sut)
        {
            // Fixture setup
            var srcCurrencyArg  = "EUR";
            var destCurrencyArg = "USD";
            var rateArg         = rate.ToString();

            currencyStub.Setup(c => c.Code).Returns(srcCurrencyArg);

            currencyProviderStub.Setup(cp => cp.GetCurrency(srcCurrencyArg)).Returns(currencyStub.Object);

            var expectedResult = new Likeness <CurrencyUpdateCommand, CurrencyUpdateCommand>(new CurrencyUpdateCommand(currencyStub.Object, destCurrencyArg, rate));
            // Exercise system
            var result = sut.Parse(new[] { destCurrencyArg, srcCurrencyArg, rateArg });

            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
        public void ApplyDiscountForNormalCustomerWillReturnEquivalentProduct()
        {
            // Fixture setup
            var fixture = new Fixture();

            var customerStub = new Mock<IPrincipal>();
            customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(false);

            var product = fixture.CreateAnonymous<Product>();

            var expectedResult = new Likeness<Product, Product>(product);

            var sut = fixture.CreateAnonymous<DefaultCustomerDiscountPolicy>();
            // Exercise system
            Product result = sut.Apply(product, customerStub.Object);
            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
        public void ApplyDiscountForPreferredCustomerWillReturnCorrectlyDiscountedProduct()
        {
            // Fixture setup
            var fixture = new Fixture();

            var customerStub = new Mock<IPrincipal>();
            customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(true);

            var product = fixture.CreateAnonymous<Product>();

            var expectedResult = new Likeness<Product, Product>(product)
                .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.Multiply(.95m).Equals(d.UnitPrice));

            var sut = fixture.CreateAnonymous<DefaultCustomerDiscountPolicy>();
            // Exercise system
            var result = sut.Apply(product, customerStub.Object);
            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
        public void ApplyDiscountForNormalCustomerWillReturnEquivalentProduct()
        {
            // Fixture setup
            var fixture = new Fixture();

            var customerStub = new Mock <IPrincipal>();

            customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(false);

            var product = fixture.CreateAnonymous <Product>();

            var expectedResult = new Likeness <Product, Product>(product);

            var sut = fixture.CreateAnonymous <DefaultCustomerDiscountPolicy>();
            // Exercise system
            Product result = sut.Apply(product, customerStub.Object);

            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
Ejemplo n.º 9
0
        public void ConvertToWillReturnConvertedItem()
        {
            // Fixture setup
            var fixture      = new Fixture();
            var currencyStub = new Mock <Currency>();

            currencyStub.SetupGet(c => c.Code).Returns(fixture.CreateAnonymous("CurrencyCode"));
            currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny <string>())).Returns(2.7m);

            var item = fixture.CreateAnonymous <Product>();
            var sut  = fixture.Build <Extent>()
                       .FromFactory(() => new Extent(item))
                       .OmitAutoProperties()
                       .CreateAnonymous();
            var expectedItem = new Likeness <Product, Product>(item.ConvertTo(currencyStub.Object));
            // Exercise system
            var result = sut.ConvertTo(currencyStub.Object).Product;

            // Verify outcome
            Assert.True(expectedItem.Equals(result));
            // Teardown
        }
        public void ApplyDiscountForPreferredCustomerWillReturnCorrectlyDiscountedProduct()
        {
            // Fixture setup
            var fixture = new Fixture();

            var customerStub = new Mock <IPrincipal>();

            customerStub.Setup(c => c.IsInRole("PreferredCustomer")).Returns(true);

            var product = fixture.CreateAnonymous <Product>();

            var expectedResult = new Likeness <Product, Product>(product)
                                 .With(d => d.UnitPrice).EqualsWhen((s, d) => s.UnitPrice.Multiply(.95m).Equals(d.UnitPrice));

            var sut = fixture.CreateAnonymous <DefaultCustomerDiscountPolicy>();
            // Exercise system
            var result = sut.Apply(product, customerStub.Object);

            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
Ejemplo n.º 11
0
        public void ConvertToWillReturnConvertedItem()
        {
            // Fixture setup
            var fixture = new Fixture();
            var currencyStub = new Mock<Currency>();
            currencyStub.SetupGet(c => c.Code).Returns(fixture.CreateAnonymous("CurrencyCode"));
            currencyStub.Setup(c => c.GetExchangeRateFor(It.IsAny<string>())).Returns(2.7m);

            var item = fixture.CreateAnonymous<Product>();
            var sut = fixture.Build<Extent>()
                .FromFactory(() => new Extent(item))
                .OmitAutoProperties()
                .CreateAnonymous();
            var expectedItem = new Likeness<Product, Product>(item.ConvertTo(currencyStub.Object));
            // Exercise system
            var result = sut.ConvertTo(currencyStub.Object).Product;
            // Verify outcome
            Assert.True(expectedItem.Equals(result));
            // Teardown
        }
Ejemplo n.º 12
0
 public void WithItemWillReturnCorrectExtent()
 {
     // Fixture setup
     var fixture = new Fixture();
     var sut = fixture.CreateAnonymous<Extent>();
     var newItem = fixture.CreateAnonymous<Product>();
     var expectedResult = new Likeness<Extent, Extent>(new Extent(newItem) { Quantity = sut.Quantity, Updated = sut.Updated }).Without(d => d.Total);
     // Exercise system
     Extent result = sut.WithItem(newItem);
     // Verify outcome
     Assert.True(expectedResult.Equals(result));
     // Teardown
 }
Ejemplo n.º 13
0
        public void ParseValidArgsWillReturnCorrectResult(decimal rate, Mock<Currency> currencyStub, [Frozen]Mock<CurrencyProvider> currencyProviderStub, CurrencyParser sut)
        {
            // Fixture setup
            var srcCurrencyArg = "EUR";
            var destCurrencyArg = "USD";
            var rateArg = rate.ToString();

            currencyStub.Setup(c => c.Code).Returns(srcCurrencyArg);

            currencyProviderStub.Setup(cp => cp.GetCurrency(srcCurrencyArg)).Returns(currencyStub.Object);

            var expectedResult = new Likeness<CurrencyUpdateCommand, CurrencyUpdateCommand>(new CurrencyUpdateCommand(currencyStub.Object, destCurrencyArg, rate));
            // Exercise system
            var result = sut.Parse(new[] { destCurrencyArg, srcCurrencyArg, rateArg });
            // Verify outcome
            Assert.True(expectedResult.Equals(result));
            // Teardown
        }
Ejemplo n.º 14
0
 public void ConvertWillReturnCorrectResult()
 {
     // Fixture setup
     var fixture = new CurrencyFixture();
     var currency = fixture.CreateAnonymous<Currency>();
     var sut = fixture.CreateAnonymous<Product>();
     var expectedProduct = new Likeness<Product, Product>(sut.WithUnitPrice(sut.UnitPrice.ConvertTo(currency)));
     // Exercise system
     Product result = sut.ConvertTo(currency);
     // Verify outcome
     Assert.True(expectedProduct.Equals(result));
     // Teardown
 }
Ejemplo n.º 15
0
 public void WithUnitPriceWillReturnCorrectResult()
 {
     // Fixture setup
     var fixture = new Fixture();
     var sut = fixture.CreateAnonymous<Product>();
     var newUnitPrice = fixture.CreateAnonymous<Money>();
     var expectedResult = new Likeness<Product, Product>(new Product(sut.Id, sut.Name, newUnitPrice));
     // Exercise system
     Product result = sut.WithUnitPrice(newUnitPrice);
     // Verify outcome
     Assert.True(expectedResult.Equals(result));
     // Teardown
 }