Ejemplo n.º 1
0
        public void RemoveShares(ClientsSharesEntity clientsSharesInfo)
        {
            var clientSharesToRemove = clientsSharesRepository.LoadClientsSharesByID(clientsSharesInfo);

            if (clientSharesToRemove == null)
            {
                return;
            }
            clientsSharesRepository.Remove(clientSharesToRemove);
            clientsSharesRepository.SaveChanges();
        }
Ejemplo n.º 2
0
        public bool ValidateShareToClient(ClientsSharesInfo shareToClientInfo)
        {
            if (shareToClientInfo.ClientID < 0 && shareToClientInfo.ShareID < 0)
            {
                return(false);
            }

            if (clientsRepository.LoadClientByID(shareToClientInfo.ClientID) == null)
            {
                return(false);
            }

            var clientSharesInfo = new ClientsSharesEntity()
            {
                ClientID = shareToClientInfo.ClientID,
                ShareID  = shareToClientInfo.ShareID
            };

            var clientsSharesEntity = clientsSharesRepository.LoadClientsSharesByID(clientSharesInfo);

            if (clientsSharesEntity != null)
            {
                if (clientsSharesEntity.Amount + shareToClientInfo.Amount < 0)
                {
                    return(false);
                }
            }
            else if (shareToClientInfo.Amount < 0)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
 public void Initialize()
 {
     clientsRepository       = Substitute.For <IClientRepository>();
     shareRepository         = Substitute.For <IShareRepository>();
     clientsSharesRepository = Substitute.For <IClientsSharesRepository>();
     logger = Substitute.For <ILogger>();
     clientsSharesRepository.LoadClientsSharesByID(Arg.Any <ClientsSharesInfo>()).Returns((callInfo) =>
     {
         if (callInfo.Arg <ClientsSharesInfo>().ClientID == 1 && callInfo.Arg <ClientsSharesInfo>().ShareID == 2)
         {
             return(new ClientsSharesEntity()
             {
                 ClientID = callInfo.Arg <ClientsSharesInfo>().ClientID,
                 ShareID = callInfo.Arg <ClientsSharesInfo>().ShareID,
                 Amount = 15
             });
         }
         else
         {
             return(null);
         }
     });
     clientsRepository.LoadClientByID(Arg.Any <int>()).Returns((callInfo) =>
     {
         if (callInfo.Arg <int>() == 1 || callInfo.Arg <int>() == 2)
         {
             return(new ClientEntity()
             {
                 ClientID = callInfo.Arg <int>()
             });
         }
         else
         {
             return(null);
         }
     });
     shareRepository.LoadShareByID(Arg.Any <int>()).Returns((callInfo) =>
     {
         if (callInfo.Arg <int>() == 1 || callInfo.Arg <int>() == 2)
         {
             return(new ShareEntity()
             {
                 ShareID = callInfo.Arg <int>()
             });
         }
         else
         {
             return(null);
         }
     });
 }
Ejemplo n.º 4
0
 public void Initialize()
 {
     clientsSharesRepository = Substitute.For <IClientsSharesRepository>();
     clientsSharesRepository.LoadClientsSharesByID(Arg.Any <ClientsSharesInfo>()).Returns((callInfo) =>
                                                                                          { if (callInfo.Arg <ClientsSharesInfo>().ClientID == 1 && callInfo.Arg <ClientsSharesInfo>().ShareID == 2)
                                                                                            {
                                                                                                return(new ClientsSharesEntity()
             {
                 ClientID = 1,
                 ShareID = 2,
                 Amount = 15
             });
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                return(null);
                                                                                            } });
 }
        public int ChangeClientsSharesAmount(ClientsSharesInfo clientsSharesInfo)
        {
            var clientSharesToChange = clientsSharesRepository.LoadClientsSharesByID(clientsSharesInfo);

            if (clientSharesToChange != null)
            {
                clientSharesToChange.Amount += clientsSharesInfo.Amount;
            }
            else
            {
                clientSharesToChange = new ClientsSharesEntity()
                {
                    ShareID  = clientsSharesInfo.ShareID,
                    ClientID = clientsSharesInfo.ClientID,
                    Amount   = clientsSharesInfo.Amount,
                };
                clientsSharesRepository.Add(clientSharesToChange);
            }

            clientsSharesRepository.SaveChanges();
            return((int)clientSharesToChange.Amount);
        }
Ejemplo n.º 6
0
        public bool ValidateShareToClient(ClientsSharesInfo shareToClientInfo, ILogger logger)
        {
            if (shareToClientInfo.ClientID < 0 && shareToClientInfo.ShareID < 0)
            {
                logger.WriteWarn("ID cannot be less than 0");
                return(false);
            }

            if (clientsRepository.LoadClientByID(shareToClientInfo.ClientID) == null)
            {
                logger.WriteWarn($"Client with ID {shareToClientInfo.ClientID} not exist");
                return(false);
            }

            if (shareRepository.LoadShareByID(shareToClientInfo.ShareID) == null)
            {
                logger.WriteWarn($"Share with ID {shareToClientInfo.ShareID} not exist");
                return(false);
            }

            var clientsSharesEntity = clientsSharesRepository.LoadClientsSharesByID(shareToClientInfo);

            if (clientsSharesEntity != null)
            {
                if (clientsSharesEntity.Amount + shareToClientInfo.Amount < 0)
                {
                    logger.WriteWarn("Amount of shares cannot be less than 0");
                    return(false);
                }
            }
            else if (shareToClientInfo.Amount < 0)
            {
                logger.WriteWarn("Amount of shares cannot be less than 0");
                return(false);
            }
            return(true);
        }