예제 #1
0
        public DiscountCampaignDTO GenerateGrpcDtoFromDiscountCampaign()
        {
            var discountCampaignDto = new DiscountCampaignDTO
            {
                Id = Id.ToString(), Name = Name,
            };

            var discountValue = DiscountValue;

            if (CodePrefix != null)
            {
                discountCampaignDto.CodePrefix = CodePrefix;
            }
            if (discountValue != null)
            {
                discountCampaignDto.DiscountValue = DecimalValue.FromDecimal(discountValue.Value);
            }
            discountCampaignDto.StartDate               = StartDate.ToString();
            discountCampaignDto.ExpirationDate          = ExpirationDate.ToString();
            discountCampaignDto.ApplyOnId               = ApplyOnId.ToString();
            discountCampaignDto.DiscountCampaignType    = (uint)DiscountCampaignType.GetHashCode();
            discountCampaignDto.DiscountUnitId          = DiscountUnitId.ToString();
            discountCampaignDto.DiscountCampaignApplyOn = (uint)DiscountCampaignApplyOn.GetHashCode();

            foreach (var discountValidation in DiscountValidations)
            {
                var discountValidationDto = discountValidation.GenerateGrpcDtoFromProductValidation();
                discountCampaignDto.DiscountValidations.Add(discountValidationDto);
            }

            return(discountCampaignDto);
        }
        public ProductDTO GenerateGrpcProduct()
        {
            var category = Category;

            var c = new CategoryDTO
            {
                Id   = category.Id,
                Code = category.Code,
                Name = category.Name
            };

            var p = new ProductDTO
            {
                Id   = Id,
                Name = Name,
                InventoryQuantity = InventoryQuantity,
                Packaging         = Packaging,
                PriceUnit         = PriceUnit,
                PriceValue        = DecimalValue.FromDecimal(PriceValue),

                Sku      = Sku,
                Category = c
            };

            if (OldPriceValue.HasValue)
            {
                p.OldPriceValue = DecimalValue.FromDecimal(OldPriceValue.Value);
            }

            return(p);
        }
        private async Task <CartDTO> GenerateCartDto(App.Support.Common.Models.CartService.Cart cart)
        {
            var subTotalAmount = 0m;
            var cartDto        = new CartDTO
            {
                Id = cart.Id, AccountId = cart.AccountId.ToString(), CreatedAt = cart.CreatedAt.ToString()
            };

            if (cart.DiscountCode != null)
            {
                cartDto.DiscountCode = cart.DiscountCode;
            }

            foreach (var cartItem in cart.CartItems)
            {
                var cartItemDto = await GenerateCartItemDto(cartItem);

                subTotalAmount += cartItemDto.ItemSubTotalAmount.ToDecimal();
                cartDto.CartItems.Add(cartItemDto);
            }

            cartDto.SubTotalAmount = DecimalValue.FromDecimal(subTotalAmount);

            return(cartDto);
        }
예제 #4
0
 public override DecimalValue?ReadJson(
     JsonReader reader,
     Type objectType,
     DecimalValue?existingValue,
     bool hasExistingValue,
     JsonSerializer serializer
     )
 {
     return(reader.Value != null?DecimalValue.FromDecimal(Convert.ToDecimal(reader.Value)) : null);
 }
        public static void AssertStateIsValid(this BalanceDto balance)
        {
            balance.Should().NotBeNull();

            balance.CurrencyType.Should().NotBeNull();

            (balance.Available >= DecimalValue.FromDecimal(decimal.Zero)).Should().BeTrue();

            (balance.Pending >= DecimalValue.FromDecimal(decimal.Zero)).Should().BeTrue();
        }
        public async Task HandleAsync_WhenChallengeParticipantRegisteredIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var participantId = new ParticipantId();

            TestMock.UserService.Setup(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            var handler = new ChallengeParticipantRegisteredIntegrationEventHandler(TestMock.UserService.Object, TestMock.SendgridOptions.Object);

            var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent
            {
                Participant = new ChallengeParticipantDto
                {
                    ChallengeId    = new ChallengeId(),
                    GamePlayerId   = "testId",
                    Id             = participantId,
                    Score          = new DecimalValue(50.0m),
                    SynchronizedAt = DateTime.UtcNow.ToTimestamp(),
                    UserId         = new UserId(),
                    Matches        =
                    {
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        },
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        }
                    }
                }
            };

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.UserService.Verify(userService => userService.SendEmailAsync(It.IsAny <UserId>(), It.IsAny <string>(), It.IsAny <object>()), Times.Once);
        }
예제 #7
0
 private ApplicantProfileReply FromPoco(ApplicantProfilePoco poco)
 {
     return(new ApplicantProfileReply()
     {
         Id = poco.Id.ToString(),
         Login = poco.Login.ToString(),
         CurrentSalary = poco.CurrentSalary == null?
                         DecimalValue.FromDecimal(0) :
                             DecimalValue.FromDecimal((decimal)poco.CurrentSalary),
                             CurrentRate = poco.CurrentRate == null?
                                           DecimalValue.FromDecimal(0) :
                                               DecimalValue.FromDecimal((decimal)poco.CurrentRate),
                                               Currency = poco.Currency,
                                               Country = poco.Country,
                                               Province = poco.Province,
                                               Street = poco.Street,
                                               City = poco.City,
                                               PostalCode = poco.PostalCode
     });
 }
        private async Task <CartItemDTO> GenerateCartItemDto(CartItem cartItem)
        {
            var cartItemDto = new CartItemDTO
            {
                Id        = cartItem.Id.ToString(),
                Quantity  = (uint)cartItem.Quantity,
                AddedAt   = cartItem.AddedAt.ToString(),
                ProductId = cartItem.ProductId.ToString()
            };

            var productDto = await GetProductDtoFromProductId(Guid.Parse(cartItemDto.ProductId));

            cartItemDto.Product = productDto;

            var itemSubTotalAmount = cartItemDto.Quantity * cartItemDto.Product.PriceValue.ToDecimal();

            cartItemDto.ItemSubTotalAmount = DecimalValue.FromDecimal(itemSubTotalAmount);

            return(cartItemDto);
        }
예제 #9
0
        public async Task HandleAsync_ChallengeParticipantRegisteredIntegrationEventIsValid_ShouldBeCompletedTask()
        {
            // Arrange
            var userId        = new UserId();
            var account       = new Account(userId);
            var participantId = new ParticipantId();

            var mockLogger = new MockLogger <ChallengeParticipantRegisteredIntegrationEventHandler>();

            TestMock.AccountService.Setup(accountService => accountService.AccountExistsAsync(It.IsAny <UserId>())).ReturnsAsync(true).Verifiable();

            TestMock.AccountService.Setup(accountService => accountService.FindAccountAsync(It.IsAny <UserId>())).ReturnsAsync(account).Verifiable();

            TestMock.AccountService
            .Setup(
                accountService => accountService.MarkAccountTransactionAsSucceededAsync(
                    It.IsAny <IAccount>(),
                    It.IsAny <TransactionMetadata>(),
                    It.IsAny <CancellationToken>()))
            .ReturnsAsync(new DomainValidationResult <ITransaction>())
            .Verifiable();

            var handler = new ChallengeParticipantRegisteredIntegrationEventHandler(TestMock.AccountService.Object, mockLogger.Object);

            var integrationEvent = new ChallengeParticipantRegisteredIntegrationEvent
            {
                Participant = new ChallengeParticipantDto
                {
                    ChallengeId    = new ChallengeId(),
                    GamePlayerId   = new PlayerId(),
                    UserId         = userId,
                    Score          = DecimalValue.FromDecimal(20),
                    SynchronizedAt = DateTime.UtcNow.ToTimestamp(),
                    Id             = participantId,
                    Matches        =
                    {
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        },
                        new ChallengeMatchDto
                        {
                            Id            = new MatchId(),
                            ParticipantId = participantId,
                            Score         = DecimalValue.FromDecimal(10)
                        }
                    }
                }
            };

            // Act
            await handler.HandleAsync(integrationEvent);

            // Assert
            TestMock.AccountService.Verify(accountService => accountService.AccountExistsAsync(It.IsAny <UserId>()), Times.Once);
            TestMock.AccountService.Verify(accountService => accountService.FindAccountAsync(It.IsAny <UserId>()), Times.Once);

            TestMock.AccountService.Verify(
                accountService => accountService.MarkAccountTransactionAsSucceededAsync(
                    It.IsAny <IAccount>(),
                    It.IsAny <TransactionMetadata>(),
                    It.IsAny <CancellationToken>()),
                Times.Once);

            mockLogger.Verify(Times.Once());
        }
예제 #10
0
        public void OpenXmlSimpleTypeConverterTest()
        {
            // 1. Base64BinaryValue
            Base64BinaryValue base64 = new Base64BinaryValue();

            base64 = "AA3322";
            Assert.True(base64 == "AA3322");
            Assert.Equal("AA3322", base64.Value);
            base64 = Base64BinaryValue.FromString("1234");
            Assert.Equal("1234", base64.ToString());
            Assert.Equal("1234", Base64BinaryValue.ToString(base64));

            // 2. BooleanValue
            BooleanValue booleanValue = new BooleanValue();

            booleanValue = true;
            Assert.True(booleanValue);
            Assert.True(booleanValue.Value);
            booleanValue = BooleanValue.FromBoolean(false);
            Assert.False(booleanValue);
            Assert.False(BooleanValue.ToBoolean(booleanValue));

            // 3. ByteValue
            ByteValue byteValue = new ByteValue();
            byte      bt        = 1;

            byteValue = bt;
            Assert.True(bt == byteValue);
            Assert.Equal(bt, byteValue.Value);
            bt        = 2;
            byteValue = ByteValue.FromByte(bt);
            Assert.Equal(bt, ByteValue.ToByte(byteValue));

            // 4. DateTimeValue
            DateTimeValue dtValue = new DateTimeValue();
            DateTime      dt      = DateTime.Now;

            dtValue = dt;
            Assert.True(dt == dtValue);
            dt      = DateTime.Now.AddDays(1);
            dtValue = DateTimeValue.FromDateTime(dt);
            Assert.Equal(dt, dtValue.Value);
            Assert.Equal(dt, DateTimeValue.ToDateTime(dt));

            // 5. DecimalValue
            DecimalValue decimalValue = new DecimalValue();
            decimal      dcm          = 10;

            decimalValue = dcm;
            Assert.True(dcm == decimalValue);
            decimalValue = DecimalValue.FromDecimal(20);
            Assert.Equal(20, decimalValue.Value);
            Assert.Equal(20, DecimalValue.ToDecimal(decimalValue));

            // 6. DoubleValue
            DoubleValue doubleValue = new DoubleValue();
            double      dbl         = 1.1;

            doubleValue = dbl;
            Assert.True(dbl == doubleValue);
            doubleValue = DoubleValue.FromDouble(2.2);
            Assert.Equal(2.2, doubleValue.Value);
            Assert.Equal(2.2, DoubleValue.ToDouble(doubleValue));

            // 7. HexBinaryValue
            HexBinaryValue hexBinaryValue = new HexBinaryValue();
            string         hex            = "0X99CCFF";

            hexBinaryValue = hex;
            Assert.True(hex == hexBinaryValue);
            hex            = "111111";
            hexBinaryValue = HexBinaryValue.FromString(hex);
            Assert.Equal(hex, hexBinaryValue.Value);
            Assert.Equal(hex, HexBinaryValue.ToString(hexBinaryValue));

            // 8. Int16
            Int16Value int16Value = new Int16Value();
            short      int16      = 16;

            int16Value = int16;
            Assert.True(int16 == int16Value);
            int16      = 17;
            int16Value = Int16Value.FromInt16(int16);
            Assert.Equal(int16, int16Value.Value);
            Assert.Equal(int16, Int16Value.ToInt16(int16Value));

            // 9. Int32
            Int32Value int32Value = new Int32Value();
            int        int32      = 32;

            int32Value = int32;
            Assert.True(int32 == int32Value);
            int32      = 33;
            int32Value = Int32Value.FromInt32(int32);
            Assert.Equal(int32, int32Value.Value);
            Assert.Equal(int32, Int32Value.ToInt32(int32Value));

            // 10. Int64
            Int64Value int64Value = new Int64Value();
            long       int64      = 64;

            int64Value = int64;
            Assert.True(int64 == int64Value);
            int64      = 17;
            int64Value = Int64Value.FromInt64(int64);
            Assert.Equal(int64, int64Value.Value);
            Assert.Equal(int64, Int64Value.ToInt64(int64Value));

            // 11. IntegerValue
            IntegerValue integerValue = new IntegerValue();
            int          integer      = 64;

            integerValue = integer;
            Assert.True(integer == integerValue);
            integer      = 17;
            integerValue = IntegerValue.FromInt64(integer);
            Assert.Equal(integer, integerValue.Value);
            Assert.Equal(integer, IntegerValue.ToInt64(integerValue));

            // 12. OnOffValue
            OnOffValue onOffValue = new OnOffValue();

            onOffValue = true;
            Assert.True(onOffValue);
            onOffValue = OnOffValue.FromBoolean(false);
            Assert.False(onOffValue.Value);
            Assert.False(OnOffValue.ToBoolean(onOffValue));

            // 13. SByteValue
            SByteValue sbyteValue = new SByteValue();
            sbyte      sbt        = sbyte.MaxValue;

            sbyteValue = sbt;
            Assert.True(sbt == sbyteValue);
            sbt        = sbyte.MinValue;
            sbyteValue = SByteValue.FromSByte(sbt);
            Assert.Equal(sbt, sbyteValue.Value);
            Assert.Equal(sbt, SByteValue.ToSByte(sbt));

            // 14. SingleValue
            SingleValue singleValue = new SingleValue();
            float       single      = float.MaxValue;

            singleValue = single;
            Assert.True(single == singleValue);
            single      = float.NaN;
            singleValue = SingleValue.FromSingle(single);
            Assert.Equal(single, singleValue.Value);
            Assert.Equal(single, SingleValue.ToSingle(singleValue));

            // 15. StringValue
            StringValue stringValue = new StringValue();
            string      str         = "Ethan";

            stringValue = str;
            Assert.True(str == stringValue);
            str         = "Yin";
            stringValue = StringValue.FromString(str);
            Assert.Equal(str, stringValue.Value);
            Assert.Equal(str, stringValue.ToString());
            Assert.Equal(str, StringValue.ToString(stringValue));

            // 16. TrueFalseBlankValue
            TrueFalseBlankValue tfbValue = new TrueFalseBlankValue();

            tfbValue = true;
            Assert.True(tfbValue);
            tfbValue = TrueFalseBlankValue.FromBoolean(false);
            Assert.False(tfbValue.Value);
            Assert.False(TrueFalseBlankValue.ToBoolean(tfbValue));

            // 17. TrueFalseValue
            TrueFalseValue tfValue = new TrueFalseValue();

            tfValue = true;
            Assert.True(tfValue);
            tfValue = TrueFalseValue.FromBoolean(false);
            Assert.False(tfValue.Value);
            Assert.False(TrueFalseValue.ToBoolean(tfValue));

            // 18. UInt16Value
            UInt16Value uint16Value = new UInt16Value();
            ushort      uint16      = ushort.MaxValue;

            uint16Value = uint16;
            Assert.True(uint16 == uint16Value);
            uint16      = ushort.MinValue;
            uint16Value = UInt16Value.FromUInt16(uint16);
            Assert.Equal(uint16, uint16Value.Value);
            Assert.Equal(uint16, UInt16Value.ToUInt16(uint16Value));

            // 19. UInt32Value
            UInt32Value uint32Value = new UInt32Value();
            uint        uint32      = uint.MaxValue;

            uint32Value = uint32;
            Assert.True(uint32 == uint32Value);
            uint32      = uint.MinValue;
            uint32Value = UInt32Value.FromUInt32(uint32);
            Assert.Equal(uint32, uint32Value.Value);
            Assert.Equal(uint32, UInt32Value.ToUInt32(uint32Value));

            // 20. UInt64Value
            UInt64Value uint64Value = new UInt64Value();
            ulong       uint64      = ulong.MaxValue;

            uint64Value = uint64;
            Assert.True(uint64 == uint64Value);
            uint64      = ulong.MinValue;
            uint64Value = UInt64Value.FromUInt64(uint64);
            Assert.Equal(uint64, uint64Value.Value);
            Assert.Equal(uint64, UInt64Value.ToUInt64(uint64Value));
        }
        private static SheetData CreateSheetData <T>(List <T> dataList, bool createHeaderRow, List <ClassToExcelColumn> columns) where T : class
        {
            var sheetData = new SheetData();

            // create row
            uint rowIndex = 0;

            if (createHeaderRow)
            {
                rowIndex++;

                Row headeRow = sheetData.AppendChild(new Row {
                    RowIndex = rowIndex
                });
                foreach (var dataColumn in columns)
                {
                    // Assign COLUMN NAME to the cell
                    Cell newCell = new Cell {
                        CellReference = String.Format("{0}1", dataColumn.ExcelColumnLetter),
                        DataType      = CellValues.String,
                        CellValue     = new CellValue(dataColumn.ColumnName)
                    };
                    headeRow.Append(newCell);
                }
            }

            foreach (var row in dataList)
            {
                rowIndex++;
                Row newRow = sheetData.AppendChild(new Row {
                    RowIndex = rowIndex
                });

                foreach (ClassToExcelColumn dataColumn in columns)
                {
                    object value = dataColumn.Property.GetValue(row, null);
                    if (value != null)
                    {
                        Cell newCell;
                        if (dataColumn.IsDate)
                        {
                            DateTime valueAsDate = (DateTime)value;

                            newCell = new Cell
                            {
                                CellReference = String.Format("{0}{1}", dataColumn.ExcelColumnLetter, rowIndex),
                                DataType      = CellValues.Number,
                                StyleIndex    = dataColumn.StyleIndex,
                                CellValue     = new CellValue(valueAsDate.ToOADate().ToString(CultureInfo.InvariantCulture))
                            };
                        }
                        else if (dataColumn.IsDouble)
                        {
                            newCell = new Cell
                            {
                                CellReference = String.Format("{0}{1}", dataColumn.ExcelColumnLetter, rowIndex),
                                DataType      = CellValues.Number,
                                StyleIndex    = dataColumn.StyleIndex,
                                CellValue     = new CellValue(DoubleValue.FromDouble((double)value)) // nulls can't make it here
                            };
                        }
                        else if (dataColumn.IsDecimal)
                        {
                            newCell = new Cell
                            {
                                CellReference = String.Format("{0}{1}", dataColumn.ExcelColumnLetter, rowIndex),
                                DataType      = CellValues.Number,
                                StyleIndex    = dataColumn.StyleIndex,
                                CellValue     = new CellValue(DecimalValue.FromDecimal((decimal)value)) // nulls can't make it here
                            };
                        }
                        else if (dataColumn.IsInteger)
                        {
                            newCell = new Cell
                            {
                                CellReference = String.Format("{0}{1}", dataColumn.ExcelColumnLetter, rowIndex),
                                DataType      = CellValues.Number,
                                StyleIndex    = dataColumn.StyleIndex,
                                CellValue     = new CellValue(IntegerValue.FromInt64((int)value)) // nulls can't make it here
                            };
                        }
                        else if (dataColumn.IsBoolean)
                        {
                            newCell = new Cell
                            {
                                CellReference = String.Format("{0}{1}", dataColumn.ExcelColumnLetter, rowIndex),
                                DataType      = CellValues.Boolean,
                                StyleIndex    = dataColumn.StyleIndex,
                                CellValue     = new CellValue(BooleanValue.FromBoolean((bool)value))
                            };
                        }
                        else
                        {
                            newCell = new Cell
                            {
                                CellReference = String.Format("{0}{1}", dataColumn.ExcelColumnLetter, rowIndex),
                                DataType      = CellValues.String,
                                StyleIndex    = dataColumn.StyleIndex,
                                CellValue     = new CellValue(value.ToString())
                            };
                        }

                        newRow.Append(newCell);
                    }
                }
            }

            return(sheetData);
        }