Example #1
0
        public void ShouldThrowExceptionCantFindShares()
        {
            var sharesTableRepository = Substitute.For <ISharesTableRepository>();

            sharesTableRepository.ContainsById(Arg.Is <int>(1)).Returns(false);
            SharesService sharesService = new SharesService(sharesTableRepository);

            var shares = sharesService.GetShares(1);
        }
Example #2
0
 public StockExchange(Container traidingRegistryContainer)
 {
     this.traidingRegistryContainer = traidingRegistryContainer;
     this.balancesService           = traidingRegistryContainer.GetInstance <BalancesService>();
     this.clientsService            = traidingRegistryContainer.GetInstance <ClientsService>();
     this.reportsService            = traidingRegistryContainer.GetInstance <ReportsService>();
     this.salesService      = traidingRegistryContainer.GetInstance <SalesService>();
     this.sharesService     = traidingRegistryContainer.GetInstance <SharesService>();
     this.shareTypesService = traidingRegistryContainer.GetInstance <ShareTypesService>();
 }
 public TradingSimulation(ILogger logger, IValidationService validationService, ClientService clientService,
                          SharesService sharesService, PortfoliosService portfoliosService, TransactionsService transactionsService)
 {
     this.logger              = logger;
     this.validationService   = validationService;
     this.clientService       = clientService;
     this.sharesService       = sharesService;
     this.portfoliosService   = portfoliosService;
     this.transactionsService = transactionsService;
 }
Example #4
0
        public void ShouldGetSharesInfo()
        {
            var sharesTableRepository = Substitute.For <ISharesTableRepository>();

            sharesTableRepository.ContainsById(Arg.Is <int>(12)).Returns(true);
            SharesService sharesService = new SharesService(sharesTableRepository);

            var shares = sharesService.GetShares(12);

            sharesTableRepository.Received(1).Get(12);
        }
        public void GetAllSharesTest()
        {
            // Arrange
            var shareRepositoryMock = Substitute.For <ISharesRepository>();

            var sut = new SharesService(shareRepositoryMock);

            // Act
            sut.GetAllShares();

            // Asserts
            shareRepositoryMock.Received(1).GetAllShares();
        }
        public void ShouldRemoveShare()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            this.shareTableRepository.ContainsById(Arg.Is(55)).Returns(true);
            SharesService sharesService = new SharesService(this.shareTableRepository);

            // Act
            sharesService.RemoveShare(55);

            // Assert
            this.shareTableRepository.Received(1).Deactivate(55);
            this.shareTableRepository.Received(1).SaveChanges();
        }
        public void ShouldThrowExceptionIfCantFindShare()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            int testId = 55;

            this.shareTableRepository.ContainsById(Arg.Is(testId)).Returns(false); // Now Contains returns false (table don't contains share type with this Id)
            SharesService sharesService = new SharesService(this.shareTableRepository);

            // Act
            sharesService.ContainsById(testId); // Try to get share type and get exception

            // Assert
        }
Example #8
0
        public void ShouldRegisterNewShares()
        {
            var                    sharesTableRepository = Substitute.For <ISharesTableRepository>();
            SharesService          sharesService         = new SharesService(sharesTableRepository);
            SharesRegistrationInfo args = new SharesRegistrationInfo();

            args.Name  = "AAPL";
            args.Price = 201;


            var SharesId = sharesService.RegisterNewShares(args);

            sharesTableRepository.Received(1).Add(Arg.Is <SharesEntity>(w => w.Name == args.Name && w.Price == args.Price));
            sharesTableRepository.Received(1).SaveChanges();
        }
        public void ShouldGetShareInfo()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            int testId = 55;

            this.shareTableRepository.ContainsById(Arg.Is(testId)).Returns(true);
            SharesService sharesService = new SharesService(this.shareTableRepository);

            // Act
            var shareInfo = sharesService.GetShare(testId);

            // Assert
            this.shareTableRepository.Received(1).Get(testId);
        }
Example #10
0
        public void ShouldCannotRegisterDuplicateShares()
        {
            var                    sharesTableRepository = Substitute.For <ISharesTableRepository>();
            SharesService          sharesService         = new SharesService(sharesTableRepository);
            SharesRegistrationInfo args = new SharesRegistrationInfo();

            args.Name  = "AAPL";
            args.Price = 201;

            sharesService.RegisterNewShares(args);

            sharesTableRepository.Contains(Arg.Is <SharesEntity>(w => w.Name == args.Name && w.Price == args.Price)).Returns(true);

            sharesService.RegisterNewShares(args);
        }
        public void ShouldChangeShareType()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            int testShareId = 55;

            this.shareTableRepository.ContainsById(Arg.Is(testShareId)).Returns(true);
            SharesService sharesService = new SharesService(this.shareTableRepository);

            // Act
            sharesService.ChangeType(testShareId, this.type);

            // Assert
            this.shareTableRepository.Received(1).SetType(testShareId, this.type);
            this.shareTableRepository.Received(1).SaveChanges();
        }
        public void ShouldChangeCompanyName()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            int testId = 55;

            this.shareTableRepository.ContainsById(Arg.Is(testId)).Returns(true);
            SharesService sharesService  = new SharesService(this.shareTableRepository);
            string        newCompanyName = "Seas and oceans";

            // Act
            sharesService.ChangeCompanyName(testId, newCompanyName);

            // Assert
            this.shareTableRepository.Received(1).SetCompanyName(testId, newCompanyName);
            this.shareTableRepository.Received(1).SaveChanges();
        }
        public void RegisterShareTest()
        {
            // Arrange
            var shareRepositoryMock = Substitute.For <ISharesRepository>();

            var sut = new SharesService(shareRepositoryMock);

            ShareRegistrationData share = new ShareRegistrationData
            {
                ShareType  = "Toyota",
                SharePrice = (decimal)6021023
            };

            // Act
            sut.RegisterShare(share);

            // Asserts
            shareRepositoryMock.Received(1).Insert(Arg.Is <Share>(x => x.ShareType == share.ShareType && x.Price == share.SharePrice));
        }
        public void GetShareIDTest()
        {
            // Arrange
            var shareRepositoryMock = Substitute.For <ISharesRepository>();

            var sut = new SharesService(shareRepositoryMock);

            string shareType = "Nissan";

            shareRepositoryMock
            .DoesShareExists(Arg.Is <string>(shareType))
            .Returns(true);

            // Act
            sut.GetShareIDByType(shareType);

            // Asserts
            shareRepositoryMock.Received(1).GetShareIDByType(Arg.Is <string>(shareType));
        }
        public void GetShareTypeDidntExistTest()
        {
            // Arrange
            var shareRepositoryMock = Substitute.For <ISharesRepository>();

            var sut = new SharesService(shareRepositoryMock);

            int shareID = 12;

            shareRepositoryMock
            .DoesShareExists(Arg.Is <int>(shareID))
            .Returns(false);

            // Act
            sut.GetShareType(shareID);

            // Asserts
            shareRepositoryMock.DidNotReceive().GetShareType(Arg.Is <int>(shareID));
        }
        public void GetSharePriceTest()
        {
            // Arrange
            var shareRepositoryMock = Substitute.For <ISharesRepository>();

            var sut = new SharesService(shareRepositoryMock);

            int shareID = 135;

            shareRepositoryMock
            .DoesShareExists(Arg.Is <int>(shareID))
            .Returns(true);

            // Act
            sut.GetSharePrice(shareID);

            // Asserts
            shareRepositoryMock.Received(1).GetSharePrice(Arg.Is <int>(shareID));
        }
        public void ShouldRegisterNewShare()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            SharesService         sharesService = new SharesService(this.shareTableRepository);
            ShareRegistrationInfo args          = new ShareRegistrationInfo();

            args.CompanyName = "Horns and hooves";
            args.Type        = this.type;
            args.Status      = true;

            // Act
            var shareId = sharesService.RegisterNewShare(args);

            // Assert
            this.shareTableRepository.Received(1).Add(Arg.Is <ShareEntity>(
                                                          s => s.CompanyName == args.CompanyName &&
                                                          s.Type == args.Type &&
                                                          s.Status == args.Status));
            this.shareTableRepository.Received(1).SaveChanges();
        }
Example #18
0
 public TradingStart(
     IUserTableRepository userTableRepository,
     ISharesTableRepository sharesTableRepository,
     IAddingSharesToThUserServiceTableRepository addingSharesToThUserServiceTableRepository,
     ITransactionRepositories transactionRepositories,
     TradingSimulatorDbContext tradingSimulatorDbContext,
     UserService userService,
     SharesService sharesService,
     AddingSharesToThUserService addingSharesToThUserService,
     TransactionService transactionService,
     TradingSimulation tradingSimulation)
 {
     this.userTableRepository   = userTableRepository;
     this.sharesTableRepository = sharesTableRepository;
     this.addingSharesToThUserServiceTableRepository = addingSharesToThUserServiceTableRepository;
     this.transactionRepositories   = transactionRepositories;
     this.tradingSimulatorDbContext = tradingSimulatorDbContext;
     this.userService   = userService;
     this.sharesService = sharesService;
     this.addingSharesToThUserService = addingSharesToThUserService;
     this.transactionService          = transactionService;
     this.tradingSimulation           = tradingSimulation;
 }
        public void ShouldNotRegisterNewShareIfItExists()
        {
            // Arrange
            this.shareTableRepository = Substitute.For <IShareTableRepository>();
            SharesService         sharesService = new SharesService(this.shareTableRepository);
            ShareRegistrationInfo args          = new ShareRegistrationInfo();

            args.CompanyName = "Horns and hooves";
            args.Type        = this.type;
            args.Status      = true;

            // Act
            sharesService.RegisterNewShare(args);

            this.shareTableRepository.Contains(Arg.Is <ShareEntity>( // Now Contains returns true (table contains this share type)
                                                   s => s.CompanyName == args.CompanyName &&
                                                   s.Type == args.Type &&
                                                   s.Status == args.Status)).Returns(true);

            sharesService.RegisterNewShare(args); // Try to reg. same twice and get exception

            // Assert
        }
        public IActionResult Delete(int id)
        {
            SharesService sharesService = new SharesService(db);

            return(Ok(sharesService.Delete(id)));
        }
        public IActionResult Post([FromBody] SharesEntity shares)
        {
            SharesService sharesService = new SharesService(db);

            return(Ok(sharesService.Add(shares)));
        }
        public IEnumerable <SharesEntity> Get()
        {
            SharesService sharesService = new SharesService(db);

            return(sharesService.Get());
        }
 public SharesController(IContextProvider contextProvider, SharesService sharesService)
 {
     this.contextProvider = contextProvider;
     this.sharesService   = sharesService;
 }
 public SharesController(SharesService sharesService, ShareTypesService shareTypesService, ReportsService reportsService)
 {
     this.sharesService     = sharesService;
     this.shareTypesService = shareTypesService;
     this.reportsService    = reportsService;
 }
 public SharesController(SharesService sharesService)
 {
     this.sharesService = sharesService;
 }