示例#1
0
        public void CallDbComplete_WhenValidParametersArePassedAndNoErrorOccurs()
        {
            //Arrange
            var dbMock      = new Mock <IDatabase>();
            var storageMock = new Mock <Storage>();
            var quantity    = 5;

            storageMock.Object.Quantity = quantity;
            var storageRepositoryMock = new Mock <IStorageRepository>();

            storageRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Storage, bool> > >())).Returns(storageMock.Object);

            dbMock.Setup(d => d.Storages).Returns(storageRepositoryMock.Object);

            var sut = new RemoveFilmQuantityCommand(dbMock.Object);

            var validParameters = new List <string>()
            {
                "1", quantity.ToString()
            };

            //Act
            var result = sut.Execute(validParameters);

            //Assert
            dbMock.Verify(d => d.Complete(), Times.Once);
        }
示例#2
0
        public void ReturnNotValidQuantity_WhenSecondParameterIsIntButNotEnoughQuantity()
        {
            //Arrange
            var dbMock      = new Mock <IDatabase>();
            var storageMock = new Mock <Storage>();
            var quantity    = 5;

            storageMock.Object.Quantity = quantity - 1;
            var storageRepositoryMock = new Mock <IStorageRepository>();

            storageRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Storage, bool> > >())).Returns(storageMock.Object);

            dbMock.Setup(d => d.Storages).Returns(storageRepositoryMock.Object);

            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "Not Valid Quantity";

            var invalidParameters = new List <string>()
            {
                "1", quantity.ToString()
            };

            //Act
            var result = sut.Execute(invalidParameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
示例#3
0
        public void ReturnNotValidStorageId_WhenFirstParameterCannotBeParsedToInt(params string[] parameters)
        {
            //Arrange
            var dbMock         = new Mock <IDatabase>();
            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "Not Valid Storage Id";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
示例#4
0
        public void ReturnParametersAreEmpty_WhenSomeOfTheParametersIsEmpty(params string[] parameters)
        {
            //Arrange
            var dbMock         = new Mock <IDatabase>();
            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "parameters are empty";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
示例#5
0
        public void ReturnNotValidParameters_WhenParametersAreDifferentOfTwo(params string[] parameters)
        {
            //Arrange
            var dbMock         = new Mock <IDatabase>();
            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "Not valid number";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
示例#6
0
        public void ReturnNotValidQuantity_WhenSecondParameterCannotBeParsedToInt(params string[] parameters)
        {
            //Arrange
            var dbMock                = new Mock <IDatabase>();
            var storageMock           = new Mock <Storage>();
            var storageRepositoryMock = new Mock <IStorageRepository>();

            storageRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Storage, bool> > >())).Returns(storageMock.Object);

            dbMock.Setup(d => d.Storages).Returns(storageRepositoryMock.Object);

            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "Not Valid Quantity";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
示例#7
0
        public void ReturnSuchIdDoesNotExist_WhenStorageIsNotInTheRepository()
        {
            //Arrange
            var validParameters = new List <string>()
            {
                "1", "10"
            };
            var dbMock = new Mock <IDatabase>();
            var storageRepositoryMock = new Mock <IStorageRepository>();

            storageRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Storage, bool> > >())).Returns((Storage)null);

            dbMock.Setup(d => d.Storages).Returns(storageRepositoryMock.Object);

            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "such id doesn't exist";

            //Act
            var result = sut.Execute(validParameters);

            //Assert
            StringAssert.Contains(expectedString, result);
        }
示例#8
0
        public void UpdateTheQuantityWithPassedValueAndReturnQuantityUpdated_WhenSecondParameterIsValidInt(int initial, int expected, params string[] parameters)
        {
            //Arrange
            var dbMock      = new Mock <IDatabase>();
            var storageMock = new Mock <Storage>();

            storageMock.Object.Quantity = initial;

            var storageRepositoryMock = new Mock <IStorageRepository>();

            storageRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Storage, bool> > >())).Returns(storageMock.Object);

            dbMock.Setup(d => d.Storages).Returns(storageRepositoryMock.Object);

            var sut            = new RemoveFilmQuantityCommand(dbMock.Object);
            var expectedString = "Quantity updated";

            //Act
            var result = sut.Execute(parameters);

            //Assert
            Assert.AreEqual(expected, storageMock.Object.Quantity);
            StringAssert.Contains(expectedString, result);
        }