public void ReturnNotAssignedToTheStore_WhenStoreNotContainsTheEmployee()
        {
            //Arrange
            var validParameters = new List <string>()
            {
                "1", "10"
            };
            var dbMock = new Mock <IDatabase>();

            var storeMock = new Mock <Store>();

            storeMock.Setup(s => s.Employees.Contains(It.IsAny <Employee>())).Returns(false);

            var storeRepositoryMock = new Mock <IStoreRepository>();

            storeRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Store, bool> > >())).Returns(storeMock.Object);

            dbMock.Setup(d => d.Stores).Returns(storeRepositoryMock.Object);

            var employeeMock            = new Mock <Employee>();
            var employeefRepositoryMock = new Mock <IEmployeesRepository>();

            employeefRepositoryMock.Setup(e => e.SingleOrDefault(It.IsAny <Expression <Func <Employee, bool> > >())).Returns(employeeMock.Object);

            dbMock.Setup(d => d.Employees).Returns(employeefRepositoryMock.Object);

            var sut            = new RemoveStoreEmployeeCommand(dbMock.Object);
            var expectedString = "not assigned to the store";

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

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnSuchIdDoesNotExist_WhenEmployeeIsNotInTheRepository()
        {
            //Arrange
            var validParameters = new List <string>()
            {
                "1", "10"
            };
            var dbMock = new Mock <IDatabase>();

            var storeMock           = new Mock <Store>();
            var storeRepositoryMock = new Mock <IStoreRepository>();

            storeRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Store, bool> > >())).Returns(storeMock.Object);

            dbMock.Setup(d => d.Stores).Returns(storeRepositoryMock.Object);

            var employeefRepositoryMock = new Mock <IEmployeesRepository>();

            employeefRepositoryMock.Setup(e => e.SingleOrDefault(It.IsAny <Expression <Func <Employee, bool> > >())).Returns((Employee)null);

            dbMock.Setup(d => d.Employees).Returns(employeefRepositoryMock.Object);

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

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

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnNotValidStoreId_WhenFirstParameterCannotBeParsedToInt(params string[] parameters)
        {
            //Arrange
            var dbMock         = new Mock <IDatabase>();
            var sut            = new RemoveStoreEmployeeCommand(dbMock.Object);
            var expectedString = "Not Valid Store Id";

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

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

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

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

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

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnNotValidEmployeeId_WhenSecondParameterCannotBeParsedToInt(params string[] parameters)
        {
            //Arrange
            var dbMock = new Mock <IDatabase>();

            var storeMock           = new Mock <Store>();
            var storeRepositoryMock = new Mock <IStoreRepository>();

            storeRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Store, bool> > >())).Returns(storeMock.Object);

            dbMock.Setup(d => d.Stores).Returns(storeRepositoryMock.Object);

            var sut            = new RemoveStoreEmployeeCommand(dbMock.Object);
            var expectedString = "Not Valid Employee Id";

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

            //Assert
            StringAssert.Contains(expectedString, result);
        }
        public void ReturnEmployeeRemoved_WhenStoreContainsTheEmployee()
        {
            var validParameters = new List <string>()
            {
                "1", "10"
            };
            var dbMock = new Mock <IDatabase>();

            var storeMock = new Mock <Store>();

            var storeRepositoryMock = new Mock <IStoreRepository>();

            storeRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Store, bool> > >())).Returns(storeMock.Object);

            dbMock.Setup(d => d.Stores).Returns(storeRepositoryMock.Object);

            var employeeMock            = new Mock <Employee>();
            var employeefRepositoryMock = new Mock <IEmployeesRepository>();

            employeefRepositoryMock.Setup(e => e.SingleOrDefault(It.IsAny <Expression <Func <Employee, bool> > >())).Returns(employeeMock.Object);

            dbMock.Setup(d => d.Employees).Returns(employeefRepositoryMock.Object);

            var employeeList = new List <Employee>()
            {
                employeeMock.Object
            };

            storeMock.Setup(s => s.Employees).Returns(employeeList);

            var sut            = new RemoveStoreEmployeeCommand(dbMock.Object);
            var expectedResult = "Employee removed";

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

            //Assert
            StringAssert.Contains(expectedResult, result);
        }
        public void CallDbComplete_WhenTheEmployeeIsRemoved()
        {
            var validParameters = new List <string>()
            {
                "1", "10"
            };
            var dbMock = new Mock <IDatabase>();

            var storeMock = new Mock <Store>();

            var storeRepositoryMock = new Mock <IStoreRepository>();

            storeRepositoryMock.Setup(s => s.SingleOrDefault(It.IsAny <Expression <Func <Store, bool> > >())).Returns(storeMock.Object);

            dbMock.Setup(d => d.Stores).Returns(storeRepositoryMock.Object);

            var employeeMock            = new Mock <Employee>();
            var employeefRepositoryMock = new Mock <IEmployeesRepository>();

            employeefRepositoryMock.Setup(e => e.SingleOrDefault(It.IsAny <Expression <Func <Employee, bool> > >())).Returns(employeeMock.Object);

            dbMock.Setup(d => d.Employees).Returns(employeefRepositoryMock.Object);

            var employeeList = new List <Employee>()
            {
                employeeMock.Object
            };

            storeMock.Setup(s => s.Employees).Returns(employeeList);

            var sut = new RemoveStoreEmployeeCommand(dbMock.Object);

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

            //Assert
            dbMock.Verify(d => d.Complete(), Times.Once);
        }