Ejemplo n.º 1
0
        public void ShouldDeleteBlockOfShares()
        {
            // 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
            };

            // Act
            sut.Delete(blockOfShareToUpdate);

            // Asserts
            blockOfSharesRepositoryMock
            .Received(1)
            .Remove(blockOfShareToUpdate);
        }
Ejemplo n.º 2
0
        public void ShouldGetClientShares()
        {
            // 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 firstShareID  = 3;
            int secondShareID = 7;

            var blockOfShares = new[]
            {
                new BlockOfShares {
                    ClientID = clientID, ShareID = firstShareID, Amount = 1
                },
                new BlockOfShares {
                    ClientID = clientID, ShareID = secondShareID, Amount = 3
                }
            };

            blockOfSharesRepositoryMock
            .GetClientShares(clientID)
            .Returns(blockOfShares);

            sharesRepositoryMock
            .GetShareType(3)
            .Returns("Umbrella");

            sharesRepositoryMock
            .GetSharePrice(3)
            .Returns(123);

            sharesRepositoryMock
            .GetShareType(7)
            .Returns("Weyland-Yutani");

            sharesRepositoryMock
            .GetSharePrice(7)
            .Returns(321);

            // Act
            var clientSharesResult = sut.GetClientShares(clientID);

            // Asserts
            Assert.AreEqual(clientSharesResult.ShareWithPrice.ElementAt(0).Key, "Umbrella");
            Assert.AreEqual(clientSharesResult.ShareWithPrice.ElementAt(0).Value, 123);

            Assert.AreEqual(clientSharesResult.ShareWithPrice.ElementAt(1).Key, "Weyland-Yutani");
            Assert.AreEqual(clientSharesResult.ShareWithPrice.ElementAt(1).Value, 321);
        }
        public void GetAllBlockOfSharesTest()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var sut = new BlockOfSharesManager(blockOfSharesRepositoryMock);

            // Act
            sut.GetAllBlockOfShares();

            // Asserts
            blockOfSharesRepositoryMock.Received(1).GetAllBlockOfShares();
        }
        public void GetClientShareAmountTest()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var sut      = new BlockOfSharesManager(blockOfSharesRepositoryMock);
            int clientID = 3;
            int shareID  = 5;

            // Act
            sut.GetClientShareAmount(clientID, shareID);

            // Asserts
            blockOfSharesRepositoryMock.Received(1).GetClientShareAmount(Arg.Is <int>(clientID), Arg.Is <int>(shareID));
        }
        public void AddShareTest()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();

            var sut = new BlockOfSharesManager(blockOfSharesRepositoryMock);

            BlockOfShares blockOfShares = new BlockOfShares();

            // Act
            sut.AddShare(blockOfShares);

            // Asserts
            blockOfSharesRepositoryMock.Received(1).Insert(Arg.Is <BlockOfShares>(blockOfShares));
        }
        public void IsClientHasStockTypeTest()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();

            var sut = new BlockOfSharesManager(blockOfSharesRepositoryMock);

            int clientID = 2;
            int shareID  = 3;

            // Act
            sut.IsClientHasStockType(clientID, shareID);

            // Asserts
            blockOfSharesRepositoryMock.Received(1).IsClientHasShareType(Arg.Is <int>(clientID), Arg.Is <int>(shareID));
        }
        public void ChangeShareAmountForClientTest()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();

            var sut = new BlockOfSharesManager(blockOfSharesRepositoryMock);

            BlockOfShares blockOfShares = new BlockOfShares {
                ClientID = 3, ShareID = 6, Amount = 10
            };

            // Act
            sut.ChangeShareAmountForClient(blockOfShares);

            // Asserts
            blockOfSharesRepositoryMock.Received(1).ChangeShareAmountForClient(Arg.Is <BlockOfShares>(blockOfShares));
        }
Ejemplo n.º 8
0
        public void ShouldGetAllBlockOfShares()
        {
            // Arrange
            var blockOfSharesRepositoryMock = Substitute.For <IBlockOfSharesRepository>();
            var clientRepositoryMock        = Substitute.For <IClientRepository>();
            var sharesRepositoryMock        = Substitute.For <ISharesRepository>();

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

            // Act
            sut.GetAllBlockOfShares();

            // Asserts
            blockOfSharesRepositoryMock.Received(1).GetAllBlockOfShares();
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }