示例#1
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);
        }
示例#2
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();
        }
示例#3
0
        public int RegisterNewShares(SharesRegistrationInfo args)
        {
            var entityToAdd = new SharesEntity()
            {
                Name = args.Name, Price = args.Price
            };

            if (this.sharesTableRepository.Contains(entityToAdd))
            {
                throw new ArgumentException("This shares has been registered. Can't continue");
            }

            this.sharesTableRepository.Add(entityToAdd);

            this.sharesTableRepository.SaveChanges();

            return(entityToAdd.Id);
        }