public async Task ShouldRaiseError_CreateLoanAgreement_UsingIDOfExistingLoan()
        {
            var model = new CreateLoanAgreementInfo
            {
                Id              = new Guid("1511c20b-6df0-4313-98a5-7c3561757dc2"),
                FinancierId     = new Guid("12998229-7ede-4834-825a-0c55bde75695"),
                LoanAmount      = 10000,
                InterestRate    = .006,
                LoanDate        = new DateTime(2021, 1, 5),
                MaturityDate    = new DateTime(2022, 1, 5),
                PaymentsPerYear = 12,
                UserId          = UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
            };

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await _cmdHdlr.Handle(model));
        }
 public void Configure(EntityTypeBuilder <LoanPayment> entity)
 {
     entity.ToTable("LoanPaymentSchedules", schema: "Finance");
     entity.HasKey(e => e.Id);
     entity.Property(p => p.Id).HasColumnType("UNIQUEIDENTIFIER").HasColumnName("LoanPaymentId");
     entity.HasOne(p => p.EconomicEvent).WithOne().HasForeignKey <LoanPayment>(p => p.Id);
     entity.HasOne(p => p.LoanAgreement).WithMany(p => p.LoanPayments).HasForeignKey(p => p.LoanId);
     entity.Property(p => p.LoanId)
     .HasColumnType("UNIQUEIDENTIFIER")
     .HasColumnName("LoanId")
     .IsRequired();
     entity.Property(p => p.PaymentNumber)
     .HasConversion(p => p.Value, p => PaymentNumber.Create(p))
     .HasColumnType("int")
     .HasColumnName("PaymentNumber")
     .IsRequired();
     entity.Property(p => p.PaymentDueDate)
     .HasConversion(p => p.Value, p => PaymentDueDate.Create(p))
     .HasColumnType("DATETIME2(0)")
     .HasColumnName("PaymentDueDate")
     .IsRequired();
     entity.Property(p => p.LoanPrincipalAmount)
     .HasConversion(p => p.Value, p => LoanPrincipalAmount.Create(p))
     .HasColumnType("DECIMAL(18,2)")
     .HasColumnName("PrincipalAmount")
     .IsRequired();
     entity.Property(p => p.LoanInterestAmount)
     .HasConversion(p => p.Value, p => LoanInterestAmount.Create(p))
     .HasColumnType("DECIMAL(18,2)")
     .HasColumnName("InterestAmount")
     .IsRequired();
     entity.Property(p => p.LoanPrincipalRemaining)
     .HasConversion(p => p.Value, p => LoanPrincipalRemaining.Create(p))
     .HasColumnType("DECIMAL(18,2)")
     .HasColumnName("PrincipalRemaining")
     .IsRequired();
     entity.Property(p => p.UserId)
     .HasConversion(p => p.Value, p => UserId.Create(p))
     .HasColumnType("UNIQUEIDENTIFIER")
     .HasColumnName("UserId")
     .IsRequired();
     entity.Property(e => e.CreatedDate)
     .HasColumnType("datetime2(7)")
     .ValueGeneratedOnAdd()
     .HasDefaultValueSql("sysdatetime()");
     entity.Property(e => e.LastModifiedDate).HasColumnType("datetime2(7)");
 }
Ejemplo n.º 3
0
 public DataResponse <string> GetNodeAddress([FromBody] GetNodeAddressRequest request)
 {
     if (request == null || request.ClientId == Guid.Empty || string.IsNullOrEmpty(request.UserId))
     {
         return(ResponseBase.InvalidInput <DataResponse <string> >("参数错误"));
     }
     try {
         var user = WebApiRoot.UserSet.GetUser(UserId.Create(request.UserId));
         if (user == null)
         {
             return(ResponseBase.InvalidInput <DataResponse <string> >("用戶不存在"));
         }
         return(DataResponse <string> .Ok(WebApiRoot.WsServerNodeSet.GetTargetNode(request.ClientId)));
     }
     catch (Exception e) {
         return(ResponseBase.ServerError <DataResponse <string> >(e.Message));
     }
 }
Ejemplo n.º 4
0
        protected bool IsValidUser <TResponse>(ISignableData data, out TResponse response, out UserData user) where TResponse : ResponseBase, new()
        {
            user = null;
            if (!WebApiRoot.UserSet.IsReadied)
            {
                string message = "服务器用户集启动中,请稍后";
                response = ResponseBase.NotExist <TResponse>(message);
                return(false);
            }
            ClientSignData query = ClientSign;

            if (!Timestamp.IsInTime(query.Timestamp))
            {
                response = ResponseBase.Expired <TResponse>();
                return(false);
            }
            // 对于User来说LoginName可以是LoginName、Email、Mobile
            if (!string.IsNullOrEmpty(query.LoginName))
            {
                user = WebApiRoot.UserSet.GetUser(UserId.Create(query.LoginName));
            }
            if (user == null)
            {
                string message = "用户不存在";
                response = ResponseBase.NotExist <TResponse>(message);
                return(false);
            }
            if (user.IsAdmin())
            {
                response = null;
                return(true);
            }
            string mySign = RpcUser.CalcSign(user.LoginName, user.Password, query.Timestamp, data);

            if (query.Sign != mySign)
            {
                string message = "签名错误:1. 可能因为登录名或密码错误;2. 可能因为软件版本过期需要升级软件,请将软件升级到最新版本再试。";
                response = ResponseBase.Forbidden <TResponse>(message);
                return(false);
            }
            response = null;
            return(true);
        }
        public void ShouldReturn_NewLoanAgreement()
        {
            var       economicEvent = new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement);
            Financier financier     = GetFinancier();

            LoanAgreement agreement = new LoanAgreement
                                      (
                economicEvent,
                FinancierId.Create(financier.Id),
                LoanAmount.Create(10000),
                InterestRate.Create(.006),
                LoanDate.Create(new DateTime(2020, 12, 31)),
                MaturityDate.Create(new DateTime(2021, 12, 31)),
                PaymentsPerYear.Create(12),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                      );

            Assert.IsType <LoanAgreement>(agreement);
        }
Ejemplo n.º 6
0
 public void Configure(EntityTypeBuilder <LoanAgreement> entity)
 {
     entity.ToTable("LoanAgreements", schema: "Finance");
     entity.HasKey(e => e.Id);
     entity.Property(p => p.Id).HasColumnType("UNIQUEIDENTIFIER").HasColumnName("LoanId");
     entity.HasOne(p => p.EconomicEvent).WithOne().HasForeignKey <LoanAgreement>(p => p.Id);
     entity.Property(p => p.FinancierId).HasColumnType("UNIQUEIDENTIFIER").HasColumnName("FinancierId");
     entity.Property(p => p.LoanAmount)
     .HasConversion(p => p.Value, p => LoanAmount.Create(p))
     .HasColumnType("DECIMAL(18,2)")
     .HasColumnName("LoanAmount")
     .IsRequired();
     entity.Property(p => p.InterestRate)
     .HasConversion(p => p.Value, p => InterestRate.Create(p))
     .HasColumnType("NUMERIC(9,6)")
     .HasColumnName("InterestRate")
     .IsRequired();
     entity.Property(p => p.LoanDate)
     .HasConversion(p => p.Value, p => LoanDate.Create(p))
     .HasColumnType("DATETIME2(0)")
     .HasColumnName("LoanDate")
     .IsRequired();
     entity.Property(p => p.MaturityDate)
     .HasConversion(p => p.Value, p => MaturityDate.Create(p))
     .HasColumnType("DATETIME2(0)")
     .HasColumnName("MaturityDate")
     .IsRequired();
     entity.Property(p => p.PaymentsPerYear)
     .HasConversion(p => p.Value, p => PaymentsPerYear.Create(p))
     .HasColumnType("INT")
     .HasColumnName("PymtsPerYear")
     .IsRequired();
     entity.Property(p => p.UserId)
     .HasConversion(p => p.Value, p => UserId.Create(p))
     .HasColumnType("UNIQUEIDENTIFIER")
     .HasColumnName("UserId")
     .IsRequired();
     entity.Property(e => e.CreatedDate)
     .HasColumnType("datetime2(7)")
     .ValueGeneratedOnAdd()
     .HasDefaultValueSql("sysdatetime()");
     entity.Property(e => e.LastModifiedDate).HasColumnType("datetime2(7)");
 }
Ejemplo n.º 7
0
 public void Configure(EntityTypeBuilder <CashAccount> entity)
 {
     entity.ToTable("CashAccounts", schema: "Finance");
     entity.HasKey(e => e.Id);
     entity.Property(p => p.Id).HasColumnType("UNIQUEIDENTIFIER").HasColumnName("CashAccountId");
     entity.HasMany(p => p.CashAccountTransactions).WithOne().HasForeignKey(p => p.CashAccountId);
     entity.Property(p => p.BankName)
     .HasConversion(p => p.Value, p => BankName.Create(p))
     .HasColumnType("NVARCHAR(50)")
     .HasColumnName("BankName")
     .IsRequired();
     entity.Property(p => p.CashAccountName)
     .HasConversion(p => p.Value, p => CashAccountName.Create(p))
     .HasColumnType("NVARCHAR(50)")
     .HasColumnName("AccountName")
     .IsRequired();
     entity.Property(p => p.CashAccountNumber)
     .HasConversion(p => p.Value, p => CashAccountNumber.Create(p))
     .HasColumnType("NVARCHAR(50)")
     .HasColumnName("AccountNumber")
     .IsRequired();
     entity.Property(p => p.RoutingTransitNumber)
     .HasConversion(p => p.Value, p => RoutingTransitNumber.Create(p))
     .HasColumnType("NCHAR(9)")
     .HasColumnName("RoutingTransitNumber")
     .IsRequired();
     entity.Property(p => p.DateOpened)
     .HasConversion(p => p.Value, p => DateOpened.Create(p))
     .HasColumnType("datetime2(0)")
     .HasColumnName("DateOpened")
     .IsRequired();
     entity.Property(p => p.UserId)
     .HasConversion(p => p.Value, p => UserId.Create(p))
     .HasColumnType("UNIQUEIDENTIFIER")
     .HasColumnName("UserId")
     .IsRequired();
     entity.Property(e => e.CreatedDate)
     .HasColumnType("datetime2(7)")
     .ValueGeneratedOnAdd()
     .HasDefaultValueSql("sysdatetime()");
     entity.Property(e => e.LastModifiedDate).HasColumnType("datetime2(7)");
 }
Ejemplo n.º 8
0
        public async Task ShouldInsert_StockSubscription_UsingStockSubscriptionRepo()
        {
            StockSubscription subscription = new StockSubscription
                                             (
                new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromStockSubscription),
                FinancierId.Create(new Guid("84164388-28ff-4b47-bd63-dd9326d32236")),
                StockIssueDate.Create(new DateTime(2021, 11, 9)),
                SharesIssured.Create(33333),
                PricePerShare.Create(.33M),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                             );

            await _stockSubscriptionRepo.AddAsync(subscription);

            await _unitOfWork.Commit();

            var result = await _stockSubscriptionRepo.Exists(subscription.Id);

            Assert.True(result);
        }
        public void ShouldRaiseError_DefaultLoanDate()
        {
            var       economicEvent = new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement);
            Financier financier     = GetFinancier();

            Assert.Throws <ArgumentNullException>(() =>
            {
                new LoanAgreement
                (
                    economicEvent,
                    FinancierId.Create(financier.Id),
                    LoanAmount.Create(10000),
                    InterestRate.Create(.006),
                    LoanDate.Create(new DateTime()),
                    MaturityDate.Create(new DateTime(2021, 12, 31)),
                    PaymentsPerYear.Create(12),
                    UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                );
            });
        }
Ejemplo n.º 10
0
        // TODO: This is actually a web-server user management functions.  Move them somewhere else!

        /// <summary>
        /// Verifies the username/password with the entry in the table SiteUser.
        /// Acquires the role from the table Role and sets it in the session manager.
        /// </summary>
        /// <returns>Null if user not found.</returns>
        public UserId Login(UserName username, PlainTextPassword password)
        {
            DataTable dt = db.Query(db.GetView("SiteUser"), "username=@username or email=@username", new Dictionary <string, object>()
            {
                { "@username", username.Value },
            });

            List <DataRow> match = (from user in dt.AsEnumerable() where PasswordHash.ValidatePassword(password.Value, user.Field <string>("PasswordHash")) select user).ToList();
            UserId         id    = null;

            if (match.Count == 1)
            {
                id = UserId.Create(match[0].Field <int>("Id"));
                db.Update(db.GetView("SiteUser"), new Dictionary <string, object>()
                {
                    { "Id", id.Value }, { "LastSignOn", DateTime.UtcNow }
                });
            }

            return(id);
        }
        public async Task ShouldInsert_CashTransaction_UsingCashAccountAggregate()
        {
            CashAccount account = await _cashAcctRepo.GetByIdAsync(new Guid("6a7ed605-c02c-4ec8-89c4-eac6306c885e"));

            CashAccountTransaction transaction = new CashAccountTransaction
                                                 (
                CashTransactionType.CashDisbursementLoanPayment,
                CashAccountId.Create(account.Id),
                CashAcctTransactionDate.Create(new DateTime(2021, 11, 7)),
                CashAcctTransactionAmount.Create(4363.82M),
                ExternalAgentId.Create(new Guid("12998229-7ede-4834-825a-0c55bde75695")),
                EconomicEventId.Create(new Guid("cf4279a1-da26-4d10-bff0-cf6e0933661c")),
                CheckNumber.Create("12214554"),
                "12M877",
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                                 );

            account.AddCashAccountTransaction(transaction);
            _cashAcctRepo.Update(account);
            await _unitOfWork.Commit();
        }
        public async Task ShouldInsert_LoanAgreement_UsingCreateLoanAgreementInfoWriteModel()
        {
            Guid id    = Guid.NewGuid();
            var  model = new CreateLoanAgreementInfo
            {
                Id              = id,
                FinancierId     = new Guid("12998229-7ede-4834-825a-0c55bde75695"),
                LoanAmount      = 10000,
                InterestRate    = .006,
                LoanDate        = new DateTime(2021, 1, 5),
                MaturityDate    = new DateTime(2022, 1, 5),
                PaymentsPerYear = 12,
                UserId          = UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
            };

            await _cmdHdlr.Handle(model);

            LoanAgreement result = await _dbContext.LoanAgreements.FindAsync(id);

            Assert.NotNull(result);
        }
        public async Task ShouldInsert_CashAccount_UsingCashAccountRepo()
        {
            CashAccount account = new CashAccount
                                  (
                CashAccountId.Create(new Guid("1e5b3dcf-9ffd-4671-95ee-373e4ca08804")),
                BankName.Create("ABCDEFG Banking & Hair Stylist, Inc."),
                CashAccountName.Create("Entertainment"),
                CashAccountNumber.Create("12345-678987"),
                RoutingTransitNumber.Create("125478991"),
                DateOpened.Create(new DateTime(2021, 11, 6)),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                  );

            await _cashAcctRepo.AddAsync(account);

            await _unitOfWork.Commit();

            var result = await _cashAcctRepo.Exists(account.Id);

            Assert.True(result);
        }
        public async Task ShouldUpdate_LoanAgreement_UsingEditLoanAgreementInfoWriteModel()
        {
            var model = new EditLoanAgreementInfo
            {
                Id              = new Guid("1511c20b-6df0-4313-98a5-7c3561757dc2"),
                LoanAmount      = 70000,
                InterestRate    = .12,
                LoanDate        = new DateTime(2021, 1, 5),
                MaturityDate    = new DateTime(2023, 1, 5),
                PaymentsPerYear = 24,
                UserId          = UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
            };

            await _cmdHdlr.Handle(model);

            LoanAgreement result = await _dbContext.LoanAgreements.FindAsync(model.Id);

            Assert.Equal(model.LoanAmount, result.LoanAmount);
            Assert.Equal(model.InterestRate, result.InterestRate);
            Assert.Equal(model.PaymentsPerYear, result.PaymentsPerYear);
            Assert.Equal(model.MaturityDate, result.MaturityDate);
        }
Ejemplo n.º 15
0
        public async Task ShouldInsert_LoanAgreement_UsingLoanAgreementRepo()
        {
            LoanAgreement agreement = new LoanAgreement
                                      (
                new EconomicEvent(Guid.NewGuid(), EventType.CashReceiptFromLoanAgreement),
                FinancierId.Create(new Guid("b49471a0-5c1e-4a4d-97e7-288fb0f6338a")),
                LoanAmount.Create(175000),
                InterestRate.Create(.0675),
                LoanDate.Create(new DateTime(2021, 11, 5)),
                MaturityDate.Create(new DateTime(2022, 11, 5)),
                PaymentsPerYear.Create(12),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                      );

            await _loanAgreementRepo.AddAsync(agreement);

            await _unitOfWork.Commit();

            var result = await _loanAgreementRepo.Exists(agreement.Id);

            Assert.True(result);
        }
        public async Task ShouldUpdate_CashAccount_UsingCashAccountRepo()
        {
            CashAccount account = await _cashAcctRepo.GetByIdAsync(new Guid("765ec2b0-406a-4e42-b831-c9aa63800e76"));

            account.UpdateBankName(BankName.Create("Test Bank"));
            account.UpdateCashAccountName(CashAccountName.Create("Testing Account"));
            account.UpdateCashAccountNumber(CashAccountNumber.Create("9876543210"));
            account.UpdateRoutingTransitNumber(RoutingTransitNumber.Create("125478991"));
            account.UpdateDateOpened(DateOpened.Create(new DateTime(2021, 11, 7)));
            account.UpdateUserId(UserId.Create(UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))));

            await _unitOfWork.Commit();

            CashAccount result = await _cashAcctRepo.GetByIdAsync(new Guid("765ec2b0-406a-4e42-b831-c9aa63800e76"));

            Assert.Equal("Test Bank", result.BankName);
            Assert.Equal("Testing Account", result.CashAccountName);
            Assert.Equal("9876543210", result.CashAccountNumber);
            Assert.Equal("125478991", result.RoutingTransitNumber);
            Assert.Equal(new DateTime(2021, 11, 7), result.DateOpened);
            Assert.Equal(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"), result.UserId);
        }
Ejemplo n.º 17
0
        public static bool TryGetUser(string base64String, out WsUserName wsUserName, out UserData userData, out string errMsg)
        {
            wsUserName = null;
            userData   = null;
            errMsg     = string.Empty;
            if (string.IsNullOrEmpty(base64String))
            {
                errMsg = $"{nameof(base64String)}为空";
                return(false);
            }
            string json = Encoding.UTF8.GetString(Convert.FromBase64String(base64String));

            wsUserName = VirtualRoot.JsonSerializer.Deserialize <WsUserName>(json);
            if (wsUserName == null)
            {
                errMsg = $"{nameof(base64String)}编码的json字符串格式错误";
                return(false);
            }
            if (!wsUserName.IsValid())
            {
                errMsg = "wsUserName提交的数据无效";
                return(false);
            }
            userData = UserSet.GetUser(UserId.Create(wsUserName.UserId));
            if (userData == null)
            {
                errMsg = $"用户{wsUserName.UserId}不存在";
                return(false);
            }
            if (!userData.IsEnabled)
            {
                errMsg = $"用户{wsUserName.UserId}已被禁用";
                return(false);
            }
            return(true);
        }
Ejemplo n.º 18
0
        public async Task ShouldInsert_DividendDeclaration_UsingStockSubscriptionAggregate()
        {
            StockSubscription stockSubscription = await _stockSubscriptionRepo.GetByIdAsync(new Guid("5997f125-bfca-4540-a144-01e444f6dc25"));

            EconomicEvent economicEvent = new EconomicEvent(Guid.NewGuid(), EventType.CashDisbursementForDividentPayment);
            await _stockSubscriptionRepo.AddEconomicEventAsync(economicEvent);

            DividendPaymentRate dividendPayment = new DividendPaymentRate
                                                  (
                economicEvent,
                stockSubscription,
                DividendDeclarationDate.Create(new DateTime(2021, 11, 22)),
                DividendPerShare.Create(.02M),
                UserId.Create(new Guid("660bb318-649e-470d-9d2b-693bfb0b2744"))
                                                  );

            stockSubscription.AddDividendPaymentRate(dividendPayment);
            _stockSubscriptionRepo.Update(stockSubscription);
            await _unitOfWork.Commit();

            DividendPaymentRate result = stockSubscription.DividendPaymentRates.FirstOrDefault(p => p.Id == dividendPayment.EconomicEvent.Id);

            Assert.NotNull(result);
        }
Ejemplo n.º 19
0
 protected void Friends(User user)
 {
     demoController.PushMenuSection <FriendsSection>(section => section.User = UserId.Create(user.Id));
 }
Ejemplo n.º 20
0
 protected void Topics(User user)
 {
     demoController.PushMenuSection <FollowedTopicsSection>(section => section.User = UserId.Create(user.Id));
 }
 public UserTests()
 {
     Register(() => TenantId.Create("dev"));
     Register(() => UserId.Create("dev"));
     Register(() => new User(Fixture.Create <UserId>()));
 }