Exemplo n.º 1
0
        public void Given_some_prices_When_entity_receives_a_negative_value_for_cost_or_customer_price_Then_throws_a_exception()
        {
            // Given
            var product = new Product {
                Id = 1
            };
            decimal        costPrice        = -12.99m;
            decimal        endCustomerPrice = -15.99m;
            DateTimeOffset startDate        = DateTimeOffset.UtcNow;

            // When..., Then
            Assert.Throws <ArgumentException>(() => ProductPrice.CreateNewPrice(product, costPrice, endCustomerPrice, startDate));
        }
Exemplo n.º 2
0
        public void Given_Update_Price_Object_When_Calling_UpdatePrice_Method_On_Instance_Of_Product_And_Pass_UpdatePrice_Object_Then_Add_Object_Collection_And_Update_Internal_Fields()
        {
            //Given
            var product      = new ProductSeed().GetSeedObject();
            var productPrice = ProductPrice.CreateNewPrice(product, costPrice: 12.99m, endCustomerDrugPrice: 15.99m, DateTimeOffset.UtcNow);

            //When
            product.SetNewPrice(productPrice);
            var newPrice = product.ProductPrices.Where(p => p == productPrice).FirstOrDefault();

            //Then
            Assert.Equal(12.99m, newPrice.CostPrice);
            Assert.Equal(15.99m, newPrice.EndCustomerDrugPrice);
            Assert.Equal(productPrice, newPrice);
        }
Exemplo n.º 3
0
        public void Given_some_start_date_When_entity_receives_a_date_older_than_actual_Then_set_date_to_actual_utc_date()
        {
            // Given
            var product = new Product {
                Id = 1
            };
            decimal        costPrice        = 12.99m;
            decimal        endCustomerPrice = 15.99m;
            DateTimeOffset startDate        = DateTimeOffset.UtcNow;
            // When
            var price = ProductPrice.CreateNewPrice(product, costPrice, endCustomerPrice, startDate);

            // Then
            Assert.NotEqual(startDate, price.Pricestartdate);
        }
Exemplo n.º 4
0
        public void Given_Cost_Price_And_Customer_Price_For_A_ProductPrice_When_Calling_Method_To_Calculates_Percentage_Of_Saving_Then_Return_Saving_Percentage_Between_Cost_Price_And_Customer_Price()
        {
            // Given
            var product = new Product
            {
                Id = 1
            };
            decimal costPrice        = 12.99m;
            decimal endCustomerPrice = 15.99m;
            var     productPrice     = ProductPrice.CreateNewPrice(product, costPrice, endCustomerPrice, DateTimeOffset.UtcNow);
            // When
            var savingPercentage = productPrice.CalculatePercentageSaving();

            // Then
            Assert.Equal(0.187617m, savingPercentage, 6);
        }