Ejemplo n.º 1
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 void ShouldThrowExceptionIfCantFindShareType()
        {
            // Arrange
            var shareTypeTableRepository = Substitute.For <IShareTypeTableRepository>();

            shareTypeTableRepository.ContainsById(Arg.Is(55)).Returns(false); // Now Contains returns false (table don't contains share type with this Id)
            ShareTypesService shareTypesService = new ShareTypesService(shareTypeTableRepository);

            // Act
            shareTypesService.ContainsById(55); // Try to get share type and get exception

            // Assert
        }
        public void ShouldGetShareTypeInfo()
        {
            // Arrange
            var shareTypeTableRepository = Substitute.For <IShareTypeTableRepository>();

            shareTypeTableRepository.ContainsById(Arg.Is(55)).Returns(true);
            ShareTypesService shareTypesService = new ShareTypesService(shareTypeTableRepository);

            // Act
            var shareTypeInfo = shareTypesService.GetShareType(55);

            // Assert
            shareTypeTableRepository.Received(1).Get(55);
        }
        public void ShouldChangeTypeName()
        {
            // Arrange
            var shareTypeTableRepository = Substitute.For <IShareTypeTableRepository>();

            shareTypeTableRepository.ContainsById(Arg.Is(55)).Returns(true);
            ShareTypesService shareTypesService = new ShareTypesService(shareTypeTableRepository);
            string            newName           = "Test new name of share type";

            // Act
            shareTypesService.ChangeName(55, newName);

            // Assert
            shareTypeTableRepository.Received(1).SetName(55, newName);
            shareTypeTableRepository.Received(1).SaveChanges();
        }
        public void ShouldChangeCost()
        {
            // Arrange
            var shareTypeTableRepository = Substitute.For <IShareTypeTableRepository>();

            shareTypeTableRepository.ContainsById(Arg.Is(55)).Returns(true);
            ShareTypesService shareTypesService = new ShareTypesService(shareTypeTableRepository);
            decimal           newCost           = 1000.00M;

            // Act
            shareTypesService.ChangeCost(55, newCost);

            // Assert
            shareTypeTableRepository.Received(1).SetCost(55, newCost);
            shareTypeTableRepository.Received(1).SaveChanges();
        }
        public void ShouldRegisterNewShareType()
        {
            // Arrange
            var shareTypeTableRepository = Substitute.For <IShareTypeTableRepository>();
            ShareTypesService         shareTypesService = new ShareTypesService(shareTypeTableRepository);
            ShareTypeRegistrationInfo args = new ShareTypeRegistrationInfo();

            args.Name   = "Cheap";
            args.Cost   = 1000.00M;
            args.Status = true;

            // Act
            var shareTypeId = shareTypesService.RegisterNewShareType(args);

            // Assert
            shareTypeTableRepository.Received(1).Add(Arg.Is <ShareTypeEntity>(
                                                         s => s.Name == args.Name &&
                                                         s.Cost == args.Cost &&
                                                         s.Status == args.Status));
            shareTypeTableRepository.Received(1).SaveChanges();
        }
        public void ShouldNotRegisterNewShareTypeIfItExists()
        {
            // Arrange
            var shareTypeTableRepository = Substitute.For <IShareTypeTableRepository>();
            ShareTypesService         shareTypesService = new ShareTypesService(shareTypeTableRepository);
            ShareTypeRegistrationInfo args = new ShareTypeRegistrationInfo();

            args.Name   = "Cheap";
            args.Cost   = 1000.00M;
            args.Status = true;

            // Act
            shareTypesService.RegisterNewShareType(args);

            shareTypeTableRepository.Contains(Arg.Is <ShareTypeEntity>( // Now Contains returns true (table contains this share type)
                                                  s => s.Name == args.Name &&
                                                  s.Cost == args.Cost &&
                                                  s.Status == args.Status)).Returns(true);

            shareTypesService.RegisterNewShareType(args); // Try to reg. same twice and get exception

            // Assert
        }
Ejemplo n.º 8
0
 public SharesController(SharesService sharesService, ShareTypesService shareTypesService, ReportsService reportsService)
 {
     this.sharesService     = sharesService;
     this.shareTypesService = shareTypesService;
     this.reportsService    = reportsService;
 }