Пример #1
0
        public void Should_AssignTypes()
        {
            var holderInfo = new HolderInfo(typeof(ObjectSpecificationHolder), typeof(CustomClass));

            holderInfo.HolderType.Should().Be(typeof(ObjectSpecificationHolder));
            holderInfo.SpecifiedType.Should().Be(typeof(CustomClass));
        }
Пример #2
0
        void kbtnNew_Click(object sender, EventArgs e)
        {
            var holder = new HolderInfo
            {
                DateOfBirth = DrivingLicense.MinDate
            };

            var dl = new DrivingLicense
            {
                Id           = 0,
                Holder       = holder,
                DateOfIssue  = DateTime.Now,
                DateOfExpiry = DateTime.Now.AddYears(ValidityPeriod),
                Status       = TextUI.InWait
            };

            var frm = new DrivingLicenseObjectForm {
                Object = dl, ShowInTaskbar = false
            };
            var dr = frm.ShowDialog();

            if (dr == DialogResult.OK)
            {
                FillDataGrid();
            }
        }
Пример #3
0
        public void Should_ThrowException_When_HolderTypeIsNotSpecificationHolderForSpecifiedType()
        {
            Action action = () => _ = new HolderInfo(typeof(ObjectSpecificationHolder), typeof(int));

            var exception = action.Should().ThrowExactly <ArgumentException>().And;

            exception.ParamName.Should().Be("holderType");
            exception.Message.Should().StartWith("ObjectSpecificationHolder is not a holder for Int32 specification (doesn't implement ISpecificationHolder<Int32>)");
        }
Пример #4
0
        public void Should_ThrowException_When_HolderTypeDoesntHaveDefaultConstructor()
        {
            Action action = () => _ = new HolderInfo(typeof(HolderWithoutDefaultConstructor), typeof(CustomClass));

            var exception = action.Should().ThrowExactly <ArgumentException>().And;

            exception.ParamName.Should().Be("holderType");
            exception.Message.Should().StartWith("HolderWithoutDefaultConstructor must be a class and have parameterless constructor.");
        }
        private ManagementAddress CheckMoveFromMainPermission(HolderInfo holderInfo, long amount)
        {
            var managementAddress = GetManagementAddressFromHolderInfo(holderInfo);

            Assert(managementAddress.Amount >= amount,
                   "current management address can not move this asset, more amount required");

            return(managementAddress);
        }
Пример #6
0
        public void Should_ThrowException_When_HolderTypeIsNotClass()
        {
            Action action = () => _ = new HolderInfo(typeof(CustomStruct), typeof(CustomClass));

            var exception = action.Should().ThrowExactly <ArgumentException>().And;

            exception.ParamName.Should().Be("holderType");
            exception.Message.Should().StartWith("CustomStruct must be a class and have parameterless constructor.");
        }
        private ManagementAddress GetManagementAddressFromHolderInfo(HolderInfo holderInfo)
        {
            ManagementAddress managementAddress;

            Assert(
                holderInfo.ManagementAddresses.TryGetValue(Context.Sender.Value.ToBase64(), out managementAddress),
                "sender is not registered as management address in the holder");

            return(managementAddress);
        }
Пример #8
0
        public void Should_CreateValidator_ReturnValidatorInitializedWithSpecificationAndSettings()
        {
            var holderInfo = new HolderInfo(typeof(ObjectSpecificationAndSettingsHolder), typeof(CustomClass));

            var createdValidator = holderInfo.CreateValidator();

            createdValidator.Should().NotBeNull();
            createdValidator.Should().BeOfType <Validator <CustomClass> >();

            var validator = (Validator <CustomClass>)createdValidator;

            var case1 = new CustomClass()
            {
                CustomValue = "@b"
            };

            var case2 = new CustomClass()
            {
                CustomValue = "abcdef"
            };

            var case3 = new CustomClass()
            {
                CustomValue = "@bcdef"
            };

            var case4 = new CustomClass()
            {
                CustomValue = "a"
            };

            validator.Validate(case1).ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "CustomValue: Must not contain @");

            validator.Validate(case2).ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "CustomValue: MUST HAVE MAX 3 CHARACTERS");

            validator.Validate(case3).ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "CustomValue: MUST HAVE MAX 3 CHARACTERS",
                "CustomValue: Must not contain @");

            validator.IsValid(case4).Should().BeTrue();
        }
Пример #9
0
        public void Should_CreateValidator_ReturnValidatorInitializedWithSpecificationAndSettings_When_HolderHoldsMultipleSpecifications()
        {
            var intHolderInfo = new HolderInfo(typeof(MultipleSpecificationAndSettingsHolder), typeof(int));

            var createdIntValidator = intHolderInfo.CreateValidator();

            createdIntValidator.Should().NotBeNull();
            createdIntValidator.Should().BeOfType <Validator <int> >();

            var intValidator = (Validator <int>)createdIntValidator;

            intValidator.IsValid(5).Should().BeTrue();
            intValidator.IsValid(9).Should().BeTrue();

            intValidator.Validate(0).ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "Only values 1-10 are valid");

            intValidator.Validate(11).ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "Only values 1-10 are valid");

            var stringHolderInfo = new HolderInfo(typeof(MultipleSpecificationAndSettingsHolder), typeof(string));

            var createdStringValidator = stringHolderInfo.CreateValidator();

            createdStringValidator.Should().NotBeNull();
            createdStringValidator.Should().BeOfType <Validator <string> >();

            var stringValidator = (Validator <string>)createdStringValidator;

            stringValidator.IsValid("abc").Should().BeTrue();
            stringValidator.IsValid("abcdefgh").Should().BeTrue();

            stringValidator.Validate("").ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "Only values with length 1-10 are valid");

            stringValidator.Validate("01234567890987654321").ToString().ShouldResultToStringHaveLines(
                ToStringContentType.Messages,
                "Only values with length 1-10 are valid");
        }
        public override HolderCreateReturnDto CreateHolder(HolderCreateDto input)
        {
            Assert(!string.IsNullOrWhiteSpace(input.Symbol), "symbol cannot be null or white space");

            HolderInfo holderInfo = new HolderInfo();

            var holderId = HashHelper.ConcatAndCompute(Context.TransactionId, Context.PreviousBlockHash);

            Assert(State.HashToHolderInfoMap[holderId] == null, "already have a holder");

            holderInfo.MainAddress = Context.ConvertVirtualAddressToContractAddress(holderId);
            foreach (var managementAddress in input.ManagementAddresses)
            {
                holderInfo.ManagementAddresses[managementAddress.Address.Value.ToBase64()] = managementAddress;
            }

            holderInfo.OwnerAddress          = input.OwnerAddress;
            holderInfo.ShutdownAddress       = input.ShutdowAddress;
            holderInfo.SettingsEffectiveTime = input.SettingsEffectiveTime;

            var tokenInfo = State.TokenContract.GetTokenInfo.Call(new GetTokenInfoInput()
            {
                Symbol = input.Symbol
            });

            Assert(tokenInfo.Symbol == input.Symbol, "symbol is not registered in token contract");

            holderInfo.Symbol = input.Symbol;


            State.HashToHolderInfoMap[holderId] = holderInfo;

            var result = new HolderCreateReturnDto()
            {
                Id   = holderId,
                Info = holderInfo
            };


            return(result);
        }
Пример #11
0
        public static void FillByDriverLicense(List <ITask> rs)
        {
            var db    = new DbHelper(Setting.DlDbPath);
            var table = db.FetchAll("PrintQueue", String.Format("WHERE Status = '{0}'", Texts.Published));

            if (ReferenceEquals(table, null))
            {
                return;
            }

            for (var i = 0; i < table.Rows.Count; i++)
            {
                var row              = table.Rows[i];
                var lastName         = row["LastName"].ConvertTo <string>();
                var firstName        = row["FirstName"].ConvertTo <string>();
                var middleName       = row["MiddleName"].ConvertTo <string>();
                var personalNumber   = row["PersonalNumber"].ConvertTo <string>();
                var cardNumber       = row["CardNumber"].ConvertTo <string>();
                var placeOfResidence = row["PlaceOfResidence"].ConvertTo <string>();
                var category         = row["Category"].ConvertTo <string>();
                var status           = row["Status"].ConvertTo <string>();

                var dateOfBirth  = row["DateOfBirth"].ConvertTo <DateTime>();
                var dateOfIssue  = row["DateOfIssue"].ConvertTo <DateTime>();
                var dateOfExpiry = row["DateOfExpiry"].ConvertTo <DateTime>();

                var photo = row["Photo"].ConvertTo <string>();
                var sign  = row["Signature"].ConvertTo <string>();

                var region         = row["Region"].ConvertTo <string>();
                var district       = row["District"].ConvertTo <string>();
                var placeOfBirth   = row["PlaceOfBirth"].ConvertTo <string>();
                var placeOfIssue   = row["PlaceOfIssue"].ConvertTo <string>();
                var passportSeries = row["PassportSeries"].ConvertTo <string>();
                var passportNumber = row["PassportNumber"].ConvertTo <int>();
                var licenseId      = row["LicenseId"].ConvertTo <long>();

                var location = new Location
                {
                    Region   = region,
                    District = district,
                    Address  = placeOfResidence
                };

                var holder = new HolderInfo
                {
                    LastName         = lastName,
                    FirstName        = firstName,
                    MiddleName       = middleName,
                    PlaceOfBirth     = placeOfBirth,
                    PersonalNumber   = personalNumber,
                    DateOfBirth      = dateOfBirth,
                    PlaceOfResidence = location,
                    PhotoData        = photo,
                    SignatureData    = sign,
                    Passport         = new Passport {
                        Seria = passportSeries, Number = passportNumber
                    }
                };

                var item = new DrivingLicense
                {
                    Id           = licenseId,
                    Holder       = holder,
                    CardNumber   = cardNumber,
                    PlaceOfIssue = placeOfIssue,
                    DateOfIssue  = dateOfIssue,
                    DateOfExpiry = dateOfExpiry,
                    Category     = category,
                    CategoryList = Category.Deserialize(category).ToArray(),
                    Status       = status
                };
                rs.Add(item);
            }
        }
 private void CheckManagementAddressPermission(HolderInfo holderInfo)
 {
     GetManagementAddressFromHolderInfo(holderInfo);
 }
Пример #13
0
 public void Should_Initialize()
 {
     _ = new HolderInfo(typeof(ObjectSpecificationHolder), typeof(CustomClass));
 }
Пример #14
0
        public void Should_HoldsSettings_Should_BeTrue_When_HolderIsSettingsHolder()
        {
            var holderInfo = new HolderInfo(typeof(ObjectSpecificationAndSettingsHolder), typeof(CustomClass));

            holderInfo.HoldsSettings.Should().BeTrue();
        }
Пример #15
0
        public void Should_ValidatorType_BeSetAs_IValidatorOfSpecifiedType()
        {
            var holderInfo = new HolderInfo(typeof(ObjectSpecificationHolder), typeof(CustomClass));

            holderInfo.ValidatorType.Should().Be(typeof(IValidator <CustomClass>));
        }
Пример #16
0
        public void Constructor_Should_ThrowException_When_HolderTypeIsNull()
        {
            Action action = () => _ = new HolderInfo(null, typeof(CustomClass));

            action.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("holderType");
        }
Пример #17
0
        public void Constructor_Should_ThrowException_When_SpecifiedTypeIsNull()
        {
            Action action = () => _ = new HolderInfo(typeof(ObjectSpecificationHolder), null);

            action.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("specifiedType");
        }