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 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 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); }