Skip to content

Instantly share code, notes, and snippets.

Avatar
🤘
I may be slow to respond.

Ashish avegaraju

🤘
I may be slow to respond.
View GitHub Profile
View OrderCheckout.cs
public class Order
{
//properties removed for brevity
public decimal Checkout()
{
decimal amountToPay = 0;
foreach (var orderLine in this.OrderLines)
{
decimal discountAmount = GetApplicableDiscount(orderLine);
View OrderTests.cs
[Property(Arbitrary = new[]
{
typeof (Generator)
})]
public void DiscountIsApplied_UponCheckout(decimal discount,
decimal price)
{
var productRequest = new ProductRequest()
{
Discount = discount,
View Order.cs
public class Order
{
public OrderId OrderId { get; }
public CustomerId CustomerId { get; }
public IReadOnlyCollection<OrderLine> OrderLines { get; }
public IPaymentMethod PaymentMethod {get;}
public DiscountCode DiscountCode {get;}
public Order(OrderId orderId,
View FSharpUnion.fs
type CardType =
| Visa
| MC
type PaypalId =
| Id of int
type CardNumber =
| Number of int
View CSharp7PatternMatch.cs
public void PaymentMethod(object o)
{
switch (o)
{
case string s when s.Contains("CashOnDelivery"):
Console.WriteLine("cash on delivery");
break;
case Paypal pId when pId.Id != null:
Console.WriteLine($"paypal {pId.Id}");
break;
View FSharpOption.fs
type Order(paymentMethod: PaymentMethod, discountCode: Option<string>)=
//Other members removed for brevity
member val PaymentMethod: PaymentMethod = paymentMethod with get
member val DiscountCode: Option<String> = discountCode with get
View OptionInspection.cs
private Result<Unit> ApplyDiscountWhenAvailable(Option<string> discountCode)
{
return discountCode.Match(Some: ApplyDiscount,
None: () => Unit.Default);
}
private Result<Unit> ApplyDiscount(string discountCode)
{
//mimic applying discount code (whatever that means)
return Unit.Default;
View LanguageExtCSharpOrder.cs
public class Order
{
public OrderId Order{get;}
public Option<String> DiscountCode {get;}
//Constructor and other properies removed for brevity
}
View PaymentMethodPatternMatching.fs
type Order(selectedPaymentMethod: PaymentMethod,
discountCode: Option<string>) =
let paymentMethod pm =
match pm with
| x when x = CashOnDelivery ->
printfn "Cash on delivery"
| Paypal id->
printf "paid by paypal %A" id
| Card (cardNumber , cardType) ->
View referentiality.fs
member this.updateProductDimensionWorkflow(productId, (height,length,weight,width)) =
productDimensionWorkflow.getProduct
|> productDimensionWorkflow.updateProduct
|> productDimensionWorkflow.notifyWarehouseWhenDimensionsUpdate
You can’t perform that action at this time.