示例#1
0
        public void ShouldUpdateClientShares()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var clientRepositoryMock        = Substitute.For <IClientRepository>();
            var sharesRepositoryMock        = Substitute.For <ISharesRepository>();

            var sut = new BlockOfSharesManager(
                blockOfSharesRepositoryMock,
                clientRepositoryMock,
                sharesRepositoryMock);

            int clientID             = 1;
            int shareID              = 3;
            int amount               = 13;
            var blockOfShareToUpdate =
                new BlockOfShares
            {
                ClientID = clientID,
                ShareID  = shareID,
                Amount   = amount
            };

            blockOfSharesRepositoryMock
            .IsClientHasShareType(
                blockOfShareToUpdate.ClientID,
                blockOfShareToUpdate.ShareID)
            .Returns(true);

            // Act
            sut.UpdateClientShares(blockOfShareToUpdate);

            // Asserts
            blockOfSharesRepositoryMock
            .Received(1)
            .ChangeShareAmountForClient(blockOfShareToUpdate);
        }
示例#2
0
        public void ShouldCreateClientSharesInsteadOfUpdatingClientSharesThatDidntExist()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var clientRepositoryMock        = Substitute.For <IClientRepository>();
            var sharesRepositoryMock        = Substitute.For <ISharesRepository>();

            var sut = new BlockOfSharesManager(
                blockOfSharesRepositoryMock,
                clientRepositoryMock,
                sharesRepositoryMock);

            int clientID             = 1;
            int shareID              = 3;
            int amount               = 13;
            var blockOfShareToUpdate =
                new BlockOfShares
            {
                ClientID = clientID,
                ShareID  = shareID,
                Amount   = amount
            };

            blockOfSharesRepositoryMock
            .IsClientHasShareType(
                blockOfShareToUpdate.ClientID,
                blockOfShareToUpdate.ShareID)
            .Returns(false);

            // Act
            sut.UpdateClientShares(blockOfShareToUpdate);

            // Asserts
            blockOfSharesRepositoryMock
            .Received(1)
            .Insert(blockOfShareToUpdate);
        }