Ejemplo n.º 1
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"));
        }
        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.º 3
0
 public void MoneyValueOf_WhenCurrencyIsNotProvided_ThrowsMoneyValueMustHaveCurrencyRuleBroken()
 {
     AssertBrokenRule <MoneyValueMustHaveCurrencyRule>(() =>
     {
         MoneyValue.Of(120, "");
     });
 }
 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 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);
        }
Ejemplo n.º 6
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);
 }
 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;
 }
Ejemplo n.º 8
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.º 9
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.º 10
0
        public void GivenTwoMoneyValuesWithTheSameCurrencies_WhenAddThem_IsSuccessful()
        {
            var valueInEuros  = MoneyValue.Of(100, "EUR");
            var valueInEuros2 = MoneyValue.Of(50, "EUR");

            MoneyValue add = valueInEuros + valueInEuros2;

            Assert.That(add.Value, Is.EqualTo(150));
            Assert.That(add.Currency, Is.EqualTo("EUR"));
        }
 public CreateAddOnCommand(long restaurantId, long foodId, string name, string nameEng, string description,
                           string descriptionEng, decimal price)
 {
     RestaurantId   = restaurantId;
     FoodId         = foodId;
     Name           = name;
     NameEng        = nameEng;
     Description    = description;
     DescriptionEng = descriptionEng;
     Price          = MoneyValue.Of(price);
 }
Ejemplo n.º 12
0
        public Task <Guid> Handle(CreateMeetingFeeCommand command, CancellationToken cancellationToken)
        {
            var meetingFee = MeetingFee.Create(
                new PayerId(command.PayerId),
                new MeetingId(command.MeetingId),
                MoneyValue.Of(command.Value, command.Currency));

            _aggregateStore.AppendChanges(meetingFee);

            return(Task.FromResult(meetingFee.Id));
        }
Ejemplo n.º 13
0
        public async Task <Unit> Handle(CreateMeetingPaymentCommand request, CancellationToken cancellationToken)
        {
            var meetingPayment = MeetingPayment.CreatePaymentForMeeting(
                request.PayerId,
                request.MeetingId,
                MoneyValue.Of(request.Value, request.Currency));

            await _meetingPaymentRepository.AddAsync(meetingPayment);

            return(Unit.Value);
        }
        public void MeetingPayment_WhenFeeIsNotGreaterThanZero_CannotBeCreated()
        {
            var payerId   = new PayerId(Guid.NewGuid());
            var meetingId = new MeetingId(Guid.NewGuid());
            var fee       = MoneyValue.Of(0, "EUR");

            AssertBrokenRule <MeetingPaymentFeeMustBeGreaterThanZeroRule>(() =>
            {
                MeetingPayment.CreatePaymentForMeeting(payerId, meetingId, fee);
            });
        }
        public Task <Guid> Handle(CreatePriceListItemCommand command, CancellationToken cancellationToken)
        {
            var priceListItem = PriceListItem.Create(
                command.CountryCode,
                SubscriptionPeriod.Of(command.SubscriptionPeriodCode),
                PriceListItemCategory.Of(command.CategoryCode),
                MoneyValue.Of(command.PriceValue, command.PriceCurrency));

            _aggregateStore.AppendChanges(priceListItem);

            return(Task.FromResult(priceListItem.Id));
        }
        public async Task <Unit> Handle(ChangePriceListItemAttributesCommand command, CancellationToken cancellationToken)
        {
            var priceListItem = await _aggregateStore.Load(new PriceListItemId(command.PriceListItemId));

            priceListItem.ChangeAttributes(
                command.CountryCode,
                SubscriptionPeriod.Of(command.SubscriptionPeriodCode),
                PriceListItemCategory.Of(command.CategoryCode),
                MoneyValue.Of(command.PriceValue, command.PriceCurrency));

            _aggregateStore.AppendChanges(priceListItem);
            return(Unit.Value);
        }
Ejemplo n.º 17
0
        public void GivenTwoMoneyValuesWithTheSameCurrencies_SumThem_IsSuccessful()
        {
            MoneyValue valueInEuros  = MoneyValue.Of(100, "EUR");
            MoneyValue valueInEuros2 = MoneyValue.Of(50, "EUR");

            IList <MoneyValue> values = new List <MoneyValue> {
                valueInEuros, valueInEuros2
            };

            MoneyValue add = values.Sum();

            Assert.That(add.Value, Is.EqualTo(150));
            Assert.That(add.Currency, Is.EqualTo("EUR"));
        }
        private PriceList CreatePriceList()
        {
            var priceListItem = new PriceListItemData(
                "PL",
                SubscriptionPeriod.Month,
                MoneyValue.Of(60, "PLN"),
                PriceListItemCategory.New);

            var priceList = PriceList.CreateFromItems(new List <PriceListItemData> {
                priceListItem
            });

            return(priceList);
        }
        public void MeetingPayment_WhenFeeIsGreaterThanZero_IsCreated()
        {
            var payerId   = new PayerId(Guid.NewGuid());
            var meetingId = new MeetingId(Guid.NewGuid());
            var fee       = MoneyValue.Of(100, "EUR");

            var meetingPayment = MeetingPayment.CreatePaymentForMeeting(payerId, meetingId, fee);

            var meetingCreated = AssertPublishedDomainEvent <MeetingPaymentCreatedDomainEvent>(meetingPayment);

            Assert.That(meetingCreated.PayerId, Is.EqualTo(payerId));
            Assert.That(meetingCreated.MeetingId, Is.EqualTo(meetingId));
            Assert.That(meetingCreated.Fee, Is.EqualTo(fee));
        }
Ejemplo n.º 20
0
        public void CreatePriceListItem_IsSuccessful()
        {
            // Act
            var priceListItem = PriceListItem.Create(
                "BRA",
                SubscriptionPeriod.Month,
                PriceListItemCategory.New,
                MoneyValue.Of(50, "BRL"));

            // Assert
            var priceListItemCreated = AssertPublishedDomainEvent <PriceListItemCreatedDomainEvent>(priceListItem);

            Assert.That(priceListItemCreated.PriceListItemId, Is.EqualTo(priceListItem.Id));
        }
Ejemplo n.º 21
0
        public static async Task <List <ProductPriceData> > GetAllProductPrices(IDbConnection connection)
        {
            var productPrices = await connection.QueryAsync <ProductPriceResponse>("SELECT " +
                                                                                   $"[ProductPrice].ProductId AS [{nameof(ProductPriceResponse.ProductId)}], " +
                                                                                   $"[ProductPrice].Value AS [{nameof(ProductPriceResponse.Value)}], " +
                                                                                   $"[ProductPrice].Currency AS [{nameof(ProductPriceResponse.Currency)}] " +
                                                                                   "FROM orders.v_ProductPrices AS [ProductPrice]");

            return(productPrices.AsList()
                   .Select(x => new ProductPriceData(
                               new ProductId(x.ProductId),
                               MoneyValue.Of(x.Value, x.Currency)))
                   .ToList());
        }
        public static async Task <PriceList> GetPriceList(IDbConnection connection)
        {
            var priceListItemList = await GetPriceListItems(connection);

            return(PriceList.CreateFromItems(
                       priceListItemList
                       .Select(x =>
                               new PriceListItemData(
                                   x.CountryCode,
                                   SubscriptionPeriod.Of(x.SubscriptionPeriodCode),
                                   MoneyValue.Of(x.MoneyValue, x.MoneyCurrency),
                                   PriceListItemCategory.Of(x.CategoryCode)))
                       .ToList()));
        }
        private PriceList CreatePriceList()
        {
            var priceListItem = new PriceListItemData(
                "PL",
                SubscriptionPeriod.Month,
                MoneyValue.Of(60, "PLN"),
                PriceListItemCategory.New);

            var priceListItems = new List <PriceListItemData> {
                priceListItem
            };
            var priceList = PriceList.Create(priceListItems, new DirectValueFromPriceListPricingStrategy(priceListItems));

            return(priceList);
        }
Ejemplo n.º 24
0
        public void ActivatePriceListItem_WhenItemIsActive_ThenActivationIgnored()
        {
            // Arrange
            var priceListItem = PriceListItem.Create(
                "BRA",
                SubscriptionPeriod.Month,
                PriceListItemCategory.New,
                MoneyValue.Of(50, "BRL"));

            // Act
            priceListItem.Activate();

            // Assert
            AssertDomainEventNotPublished <PriceListItemActivatedDomainEvent>(priceListItem);
        }
        public void MarkPaymentAsPayed_WhenIsPayedAlready_CannotBePayedTwice()
        {
            var payerId   = new PayerId(Guid.NewGuid());
            var meetingId = new MeetingId(Guid.NewGuid());
            var fee       = MoneyValue.Of(100, "EUR");

            var meetingPayment = MeetingPayment.CreatePaymentForMeeting(payerId, meetingId, fee);

            meetingPayment.MarkIsPayed();

            AssertBrokenRule <MeetingPaymentCannotBePayedTwiceRule>(() =>
            {
                meetingPayment.MarkIsPayed();
            });
        }
        public async Task <Guid> Handle(BuySubscriptionCommand command, CancellationToken cancellationToken)
        {
            var priceList = await PriceListProvider.GetPriceList(_sqlConnectionFactory.GetOpenConnection());

            var subscription = SubscriptionPayment.Buy(
                _payerContext.PayerId,
                SubscriptionPeriod.Of(command.SubscriptionTypeCode),
                command.CountryCode,
                MoneyValue.Of(command.Value, command.Currency),
                priceList);

            _aggregateStore.AppendChanges(subscription);

            return(subscription.Id);
        }
        public async Task <Unit> Handle(ChangeMeetingMainAttributesCommand request, CancellationToken cancellationToken)
        {
            var meeting = await _meetingRepository.GetByIdAsync(new MeetingId(request.MeetingId));

            meeting.ChangeMainAttributes(request.Title,
                                         MeetingTerm.CreateNewBetweenDates(request.TermStartDate, request.TermStartDate),
                                         request.Description,
                                         MeetingLocation.CreateNew(request.MeetingLocationName, request.MeetingLocationAddress, request.MeetingLocationPostalCode, request.MeetingLocationCity),
                                         MeetingLimits.Create(request.AttendeesLimit, request.GuestsLimit),
                                         Term.CreateNewBetweenDates(request.RSVPTermStartDate, request.RSVPTermEndDate),
                                         request.EventFeeValue.HasValue ? MoneyValue.Of(request.EventFeeValue.Value, request.EventFeeCurrency) : MoneyValue.Undefined,
                                         _memberContext.MemberId);

            return(Unit.Value);
        }
        public void BuySubscription_IsSuccessful()
        {
            // Arrange
            var subscriptionPaymentTestData = CreateSubscriptionPaymentTestData();

            // Act
            var subscriptionPayment = SubscriptionPayment.Buy(
                subscriptionPaymentTestData.PayerId,
                SubscriptionPeriod.Month,
                "PL",
                MoneyValue.Of(60, "PLN"),
                subscriptionPaymentTestData.PriceList);

            // Assert
            AssertPublishedDomainEvent <SubscriptionPaymentCreatedDomainEvent>(subscriptionPayment);
        }
        public void BuySubscriptionRenewal_WhenPriceDoesNotExist_IsNotPossible()
        {
            // Arrange
            var subscriptionPaymentTestData = CreateSubscriptionPaymentTestData();

            // Act & Assert
            AssertBrokenRule <PriceOfferMustMatchPriceInPriceListRule>(() =>
            {
                SubscriptionPayment.Buy(
                    subscriptionPaymentTestData.PayerId,
                    SubscriptionPeriod.Month,
                    "PL",
                    MoneyValue.Of(50, "PLN"),
                    subscriptionPaymentTestData.PriceList);
            });
        }
        public Result <bool> UpdateVariantPrice(VariantPriceUpdateModel model)
        {
            var variant =
                _variants.FirstOrDefault(x => x.Name.ToLowerInvariant() == model.VariantName.ToLowerInvariant());

            if (variant.HasValue())
            {
                if (model.VariantName.Equals(DefaultVariant))
                {
                    UpdateBasePrice(model.NewPrice);
                }

                variant.UpdatePrice(MoneyValue.Of(model.NewPrice));
                return(Result.Ok(variant.IsPriceReduced()));
            }

            return(Result.Failure <bool>("failed to update"));
        }