Created
August 27, 2018 07:15
-
-
Save marhoily/7b83224ed4a175b354275182b2ce11fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FluentAssertions; | |
using Xunit; | |
namespace DesignPatters | |
{ | |
public sealed class Pattern6 | |
{ | |
interface IProduct { decimal Cost { get; } } | |
class Product : IProduct | |
{ | |
public decimal Cost { get; } | |
public Product(decimal cost) { Cost = cost; } | |
} | |
class Delivery : IProduct | |
{ | |
private readonly IProduct _baseProduct; | |
private readonly decimal _value; | |
public Delivery(IProduct baseProduct, decimal value) | |
{ | |
_baseProduct = baseProduct; | |
_value = value; | |
} | |
public decimal Cost => _baseProduct.Cost + _value; | |
} | |
class Tax : IProduct | |
{ | |
private readonly IProduct _baseProduct; | |
private readonly decimal _value; | |
public Tax(IProduct baseProduct, decimal value) | |
{ | |
_baseProduct = baseProduct; | |
_value = value; | |
} | |
public decimal Cost => _baseProduct.Cost * _value; | |
} | |
[Fact] | |
public void Test() | |
{ | |
new Tax(new Delivery(new Product(5), 3), 1.2m) | |
.Cost.Should().Be(9.6m); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment