Пример #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);
        }
Пример #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>();
 }
Пример #3
0
 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;
 }
Пример #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);
        }
Пример #5
0
        public void GetAllSharesTest()
        {
            // Arrange
            var shareRepositoryMock = Substitute.For <ISharesRepository>();

            var sut = new SharesService(shareRepositoryMock);

            // Act
            sut.GetAllShares();

            // Asserts
            shareRepositoryMock.Received(1).GetAllShares();
        }
Пример #6
0
        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();
        }
Пример #7
0
        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
        }
Пример #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();
        }
Пример #9
0
        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);
        }
Пример #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);
        }
Пример #11
0
        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();
        }
Пример #12
0
        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();
        }
Пример #13
0
        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));
        }
Пример #14
0
        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));
        }
Пример #15
0
        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));
        }
Пример #16
0
        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));
        }
Пример #17
0
        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();
        }
Пример #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;
 }
Пример #19
0
        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
        }
Пример #20
0
        public IActionResult Delete(int id)
        {
            SharesService sharesService = new SharesService(db);

            return(Ok(sharesService.Delete(id)));
        }
Пример #21
0
        public IActionResult Post([FromBody] SharesEntity shares)
        {
            SharesService sharesService = new SharesService(db);

            return(Ok(sharesService.Add(shares)));
        }
Пример #22
0
        public IEnumerable <SharesEntity> Get()
        {
            SharesService sharesService = new SharesService(db);

            return(sharesService.Get());
        }
Пример #23
0
 public SharesController(IContextProvider contextProvider, SharesService sharesService)
 {
     this.contextProvider = contextProvider;
     this.sharesService   = sharesService;
 }
Пример #24
0
 public SharesController(SharesService sharesService, ShareTypesService shareTypesService, ReportsService reportsService)
 {
     this.sharesService     = sharesService;
     this.shareTypesService = shareTypesService;
     this.reportsService    = reportsService;
 }
Пример #25
0
 public SharesController(SharesService sharesService)
 {
     this.sharesService = sharesService;
 }