Ejemplo n.º 1
0
 public DiscountedValueFromPriceListPricingStrategy(
     List <PriceListItemData> items,
     MoneyValue discountValue)
 {
     _items         = items;
     _discountValue = discountValue;
 }
Ejemplo n.º 2
0
        protected virtual void UpdateValue(object target, object eventArgs)
        {
            IValue value;

            switch (this.Value)
            {
            case StringValue _:
                value = new StringValue(this.Input.Text);
                break;

            case DecimalValue _:
                value = new DecimalValue(this.Input.Text);
                break;

            case IntegerValue _:
                value = new IntegerValue(this.Input.Text);
                break;

            case MoneyValue _:
                value = new MoneyValue(this.Input.Text);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(this.Value));
            }

            this.Value = value;
        }
Ejemplo n.º 3
0
 public PriceOfferMustMatchPriceInPriceListRule(
     MoneyValue priceOffer,
     MoneyValue priceInPriceList)
 {
     _priceOffer       = priceOffer;
     _priceInPriceList = priceInPriceList;
 }
        public async Task <Guid> Handle(BuySubscriptionRenewalCommand command, CancellationToken cancellationToken)
        {
            var priceList = await PriceListProvider.GetPriceList(_sqlConnectionFactory.GetOpenConnection());

            var subscriptionId = new SubscriptionId(command.SubscriptionId);

            var subscription = await _aggregateStore.Load(new SubscriptionId(command.SubscriptionId));

            if (subscription == null)
            {
                throw new InvalidCommandException(new List <string> {
                    "Subscription for renewal must exist."
                });
            }

            var subscriptionRenewalPayment = SubscriptionRenewalPayment.Buy(
                _payerContext.PayerId,
                subscriptionId,
                SubscriptionPeriod.Of(command.SubscriptionTypeCode),
                command.CountryCode,
                MoneyValue.Of(command.Value, command.Currency),
                priceList);

            _aggregateStore.AppendChanges(subscriptionRenewalPayment);

            return(subscriptionRenewalPayment.Id);
        }
        public void AddActivityToCostsTest()
        {
            var travel = new Travel
            {
                Name = "My Travel"
            };
            var activity = new TravelActivity
            {
                Name = "My Activity"
            };

            travel.ActivityList.Add(activity);
            _repository.AddTravel(travel);
            Assert.AreEqual(1, _repository.GetTravel(travel.Id).ActivityList.Count);
            Assert.AreEqual(0, _repository.GetTravel(travel.Id).CostList.Count);
            CollectionAssert.AreEqual(travel.ActivityList as ICollection, _repository.GetTravel(travel.Id).ActivityList as ICollection);

            var cost = new MoneyValue
            {
                Value    = 24.0,
                Currency = null
            };

            _repository.AddActivityToCosts(travel.Id, activity, cost);
            Assert.AreEqual(0, _repository.GetTravel(travel.Id).ActivityList.Count);
            Assert.AreEqual(1, _repository.GetTravel(travel.Id).CostList.Count);
        }
Ejemplo n.º 6
0
 public void MoneyValueOf_WhenCurrencyIsNotProvided_ThrowsMoneyValueMustHaveCurrencyRuleBroken()
 {
     AssertBrokenRule <MoneyValueMustHaveCurrencyRule>(() =>
     {
         MoneyValue.Of(120, "");
     });
 }
Ejemplo n.º 7
0
        public static SubscriptionPayment Buy(
            PayerId payerId,
            SubscriptionPeriod period,
            string countryCode,
            MoneyValue priceOffer,
            PriceList priceList)
        {
            var priceInPriceList = priceList.GetPrice(countryCode, period, PriceListItemCategory.New);

            CheckRule(new PriceOfferMustMatchPriceInPriceListRule(priceOffer, priceInPriceList));

            var subscriptionPayment = new SubscriptionPayment();

            var subscriptionPaymentCreated = new SubscriptionPaymentCreatedDomainEvent(
                Guid.NewGuid(),
                payerId.Value,
                period.Code,
                countryCode,
                SubscriptionPaymentStatus.WaitingForPayment.Code,
                priceOffer.Value,
                priceOffer.Currency);

            subscriptionPayment.Apply(subscriptionPaymentCreated);
            subscriptionPayment.AddDomainEvent(subscriptionPaymentCreated);

            return(subscriptionPayment);
        }
Ejemplo n.º 8
0
        public void MoneyValueOf_WhenCurrencyIsProvided_IsSuccessful()
        {
            var value = MoneyValue.Of(120, "EUR");

            Assert.That(value.Value, Is.EqualTo(120));
            Assert.That(value.Currency, Is.EqualTo("EUR"));
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            var error = false;

            try
            {
                var value = Convert.ToDouble(Value.Get <string>(executionContext));

                FloatValue.Set(executionContext, value);

                DecimalValue.Set(executionContext, Convert.ToDecimal(Math.Round(value, 2)));

                MoneyValue.Set(executionContext, new Money {
                    Value = Convert.ToDecimal(Math.Round(value, 2))
                });

                TruncatedValue.Set(executionContext, Convert.ToInt32(Math.Truncate(value)));

                RoundedValue.Set(executionContext, Convert.ToInt32(Math.Round(value, 0)));
            }
            catch
            {
                error = true;
            }

            ProcessingError.Set(executionContext, error);
        }
        public async Task when_remove_daily_route_command_handler_should_not_be_null()
        {
            var dailyRouteRepositoryMock = new Mock <IDailyRouteRepository>();

            var startNode = Node.Create("asdas", 21, 22);
            var endNode   = Node.Create("asdas", 21, 22);

            var route      = Route.Create(startNode, endNode);
            var moneyValue = new MoneyValue(13, "Pln");

            var dailyRoute = DailyRoute.CreateDailyRoute(DateTime.UtcNow, DateTime.UtcNow, route, Guid.NewGuid(), 5, moneyValue);

            dailyRouteRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>()))
            .ReturnsAsync(dailyRoute);

            var command = new RemoveDailyRouteCommand()
            {
                RouteId = Guid.NewGuid(), UserId = Guid.NewGuid()
            };

            var handler = new RemoveDailyRouteCommandHandler(dailyRouteRepositoryMock.Object);

            var result = await handler.Handle(command, CancellationToken.None);

            result.Should().NotBeNull();
        }
        public void PlaceOrder_WhenAtLeastOneProductIsAdded_IsSuccessful()
        {
            // Arrange
            Customer customer = CustomerFactory.Create();

            List <OrderProductData> orderProductsData = new List <OrderProductData>();

            orderProductsData.Add(new OrderProductData(SampleProducts.Product1Id, 2));

            List <ProductPriceData> allProductPrices = new List <ProductPriceData>
            {
                SampleProductPrices.Product1EUR, SampleProductPrices.Product1USD
            };

            const string          currency        = "EUR";
            List <ConversionRate> conversionRates = GetConversionRates();

            // Act
            customer.PlaceOrder(
                orderProductsData,
                allProductPrices,
                currency,
                conversionRates);

            // Assert
            OrderPlacedEvent orderPlaced = AssertPublishedDomainEvent <OrderPlacedEvent>(customer);

            Assert.That(orderPlaced.Value, Is.EqualTo(MoneyValue.Of(200, "EUR")));
        }
Ejemplo n.º 12
0
        public void CreatingNewObject_ShouldHaveCorrectValueCorectDataGiven()
        {
            var expected = new MoneyValue(1.25M);
            var actual   = new MoneyLiteral("1.25");

            Assert.Equal(expected, actual.Value);
        }
 private void When(PriceListItemAttributesChangedDomainEvent @event)
 {
     this._countryCode        = @event.CountryCode;
     this._subscriptionPeriod = SubscriptionPeriod.Of(@event.SubscriptionPeriodCode);
     this._category           = PriceListItemCategory.Of(@event.CategoryCode);
     this._price = MoneyValue.Of(@event.Price, @event.Currency);
 }
        public Food(string name, MoneyValue unitPrice, FoodItemType type,
                    bool isGlutenFree, bool isVeg, bool isNonVeg, string imageUrl, Categories.Category category, Cuisine cuisine,
                    string description,
                    string descriptionEng, Menu menu, List <string> ingredients)
        {
            CheckRule(new ConditionMustBeTrueRule(category.Categorize == Categorize.Food, "invalid category"));

            ImageUrl          = imageUrl;
            Category          = category;
            Cuisine           = cuisine;
            Description       = description;
            DescriptionEng    = descriptionEng;
            Name              = name;
            UnitPrice         = unitPrice;
            Type              = type;
            IsGlutenFree      = isGlutenFree;
            IsVeg             = !isNonVeg && isVeg;
            IsNonVeg          = !isVeg && isNonVeg;
            OldUnitPrice      = unitPrice;
            Status            = FoodStatus.Available;
            Rating            = 0;
            TotalRatingsCount = 0;
            TotalOrderCount   = 0;
            SetDefaultVariant();
            Menu = menu;

            void SetDefaultVariant()
            {
                AddVariant(new Variant(DefaultVariant, DefaultVariantEng, unitPrice, "", ""));
            }

            SetIngredients(ingredients);
        }
        public Meeting CreateMeeting(
            string title,
            MeetingTerm term,
            string description,
            MeetingLocation location,
            int?attendeesLimit,
            int guestsLimit,
            Term rsvpTerm,
            MoneyValue eventFee,
            List <MemberId> hostsMembersIds,
            MemberId creatorId)
        {
            this.CheckRule(new MeetingCanBeOrganizedOnlyByPayedGroupRule(_paymentDateTo));

            this.CheckRule(new MeetingHostMustBeAMeetingGroupMemberRule(creatorId, hostsMembersIds, _members));

            return(Meeting.CreateNew(this.Id,
                                     title,
                                     term,
                                     description,
                                     location,
                                     MeetingLimits.Create(attendeesLimit, guestsLimit),
                                     rsvpTerm,
                                     eventFee,
                                     hostsMembersIds,
                                     creatorId));
        }
Ejemplo n.º 16
0
        public static int GetGoldAmount()
        {
            //Requires ColorSpace == GrayScale || Color (This Means a check needs to be added to see if the value is -1 retry with ColorSpace == Color.
            string MoneyText = GetOcrResponse(TextConstants.GOLD_START, TextConstants.GOLD_START_SIZE, "2");

            MoneyText = MoneyText.ToLower();
            MessageBox.Show(MoneyText);

            int MoneyValue;

            if (MoneyText.EndsWith("k"))
            {
                MoneyValue = MultiplyValue(MoneyText, 1000);
            }
            else if (MoneyText.EndsWith("m"))
            {
                MoneyValue = MultiplyValue(MoneyText, 1000000);
            }
            else
            {
                MoneyValue = StringToInt(MoneyText);
            }
            MessageBox.Show(MoneyValue.ToString());
            return(MoneyValue);
        }
Ejemplo n.º 17
0
        public async Task when_try_to_create_passenger_and_command_are_null_should_not_find_command_handler_and_throw_exception()
        {
            var driverRepositoryMock     = new Mock <IDriverRepository>();
            var nodeManagerMock          = new Mock <INodeManager>();
            var dailyRouteRepositoryMock = new Mock <IDailyRouteRepository>();

            var startNode = Node.Create("asdas", 21, 22);
            var endNode   = Node.Create("asdas", 21, 22);

            var route      = Route.Create(startNode, endNode);
            var moneyValue = new MoneyValue(13, "Pln");

            var dailyRoute =
                DailyRoute.CreateDailyRoute(DateTime.UtcNow, DateTime.UtcNow, route, Guid.NewGuid(), 5, moneyValue);

            dailyRouteRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>()))
            .ReturnsAsync(dailyRoute);

            CreateDailyRouteCommand command = null;

            var handler = new CreateDailyRouteCommandHandler(driverRepositoryMock.Object, nodeManagerMock.Object);

            Func <Task> act = async() => await handler.Handle(command, CancellationToken.None);

            act.Should().Throw <Exception>();
        }
Ejemplo n.º 18
0
 public PaymentCreatedCommand(Guid user, UserAccount userAccount, Currency sourceCurrency, Currency targetCurrency, decimal sourceValue)
 {
     this._user           = user;
     this._sourceCurrency = sourceCurrency;
     this._userAccount    = userAccount;
     this._targetCurrency = targetCurrency;
     this._sourceValue    = new MoneyValue(sourceValue, sourceCurrency);
 }
Ejemplo n.º 19
0
        public string Income(MoneyValue money)
        {
            money = _cantorPolicy.Exchange(money, Currency.EUR);

            _ballance = new MoneyValue(_ballance.Amount + money.Amount, Currency.EUR);

            return($"Income {money} success! {_currentBalance}");
        }
Ejemplo n.º 20
0
 private void When(MeetingFeeCreatedDomainEvent meetingFeeCreated)
 {
     this.Id    = meetingFeeCreated.MeetingFeeId;
     _payerId   = new PayerId(meetingFeeCreated.PayerId);
     _meetingId = new MeetingId(meetingFeeCreated.MeetingId);
     _fee       = MoneyValue.Of(meetingFeeCreated.FeeValue, meetingFeeCreated.FeeCurrency);
     _status    = MeetingFeeStatus.Of(meetingFeeCreated.Status);
 }
 public AddOn(string name, string nameEng, string description, string descriptionEng, MoneyValue price)
 {
     Name           = name;
     NameEng        = nameEng;
     Description    = description;
     DescriptionEng = descriptionEng;
     Price          = price;
 }
Ejemplo n.º 22
0
 public Variant(string name, string nameEng, MoneyValue price, string description, string descriptionEng)
 {
     Name           = name;
     NameEng        = nameEng;
     Price          = price;
     OldPrice       = price;
     Description    = description;
     DescriptionEng = descriptionEng;
 }
 private void When(PriceListItemCreatedDomainEvent @event)
 {
     this.Id             = @event.PriceListItemId;
     _countryCode        = @event.CountryCode;
     _subscriptionPeriod = SubscriptionPeriod.Of(@event.SubscriptionPeriodCode);
     _category           = PriceListItemCategory.Of(@event.CategoryCode);
     _price    = MoneyValue.Of(@event.Price, @event.Currency);
     _isActive = true;
 }
 public OrderPlacedEvent(
     OrderId orderId,
     CustomerId customerId,
     MoneyValue value)
 {
     OrderId    = orderId;
     CustomerId = customerId;
     Value      = value;
 }
Ejemplo n.º 25
0
 public Order(OrderType type, MoneyValue totalAmount,
              MoneyValue payableAmount, SupportedPaymentType paymentType)
 {
     Type          = type;
     TotalAmount   = totalAmount;
     PayableAmount = payableAmount;
     PaymentType   = paymentType;
     CreatedAt     = DateTime.Now;
 }
Ejemplo n.º 26
0
    static void Main()
    {
        var nullMoneyValue = (MoneyValue?)null;
        var moneyValue     = new MoneyValue(123);

        var crashApplication = nullMoneyValue < moneyValue;

        Console.WriteLine("All OK");
    }
Ejemplo n.º 27
0
 private void When(SubscriptionPaymentCreatedDomainEvent @event)
 {
     this.Id                    = @event.SubscriptionPaymentId;
     _payerId                   = new PayerId(@event.PayerId);
     _subscriptionPeriod        = SubscriptionPeriod.Of(@event.SubscriptionPeriodCode);
     _countryCode               = @event.CountryCode;
     _subscriptionPaymentStatus = SubscriptionPaymentStatus.Of(@event.Status);
     _value = MoneyValue.Of(@event.Value, @event.Currency);
 }
Ejemplo n.º 28
0
        private void CalculateValue(string currency, List <ConversionRate> conversionRates)
        {
            var totalValueForOrderProduct = this.Quantity * this.Product.GetPrice(currency).Value;

            this.Value = new MoneyValue(totalValueForOrderProduct, currency);

            var conversionRate = conversionRates.Single(x => x.SourceCurrency == currency && x.TargetCurrency == "EUR");

            this.ValueInEUR = conversionRate.Convert(this.Value);
        }
Ejemplo n.º 29
0
        public void GivenTwoMoneyValuesWithDifferentCurrencies_WhenAddThem_ThrowsMoneyValueOperationMustBePerformedOnTheSameCurrencyRule()
        {
            var valueInEuros   = MoneyValue.Of(100, "EUR");
            var valueInDollars = MoneyValue.Of(50, "USD");

            AssertBrokenRule <MoneyValueOperationMustBePerformedOnTheSameCurrencyRule>(() =>
            {
                var add = valueInEuros + valueInDollars;
            });
        }
Ejemplo n.º 30
0
        private void CalculateOrderValue()
        {
            var value = this._orderProducts.Sum(x => x.Value.Value);

            this._value = new MoneyValue(value, this._orderProducts.First().Value.Currency);

            var valueInEUR = this._orderProducts.Sum(x => x.ValueInEUR.Value);

            this._valueInEUR = new MoneyValue(valueInEUR, "EUR");
        }