public void CantUpdateNonExistingPosition()
        {
            var    position              = new DTOPosition(3, "1", "1");
            var    positionListStub      = new PositionListStub();
            var    positionListValidator = new PositionListValidator(positionListStub);
            string error = null;
            EventHandler <PositionListChangedEventArgs> handler = (sender, e) => error = e.Error;

            positionListValidator.PositionListChanged += handler;
            positionListValidator.LoadPositionList();
            positionListValidator.UpdatePosition(position);
            Assert.AreEqual("Position 1 cannot be found", error);
        }
        public void PositionsPropertyReturnsPositionsFromDependency()
        {
            var positionListStub      = new PositionListStub();
            var positionListValidator = new PositionListValidator(positionListStub);

            positionListValidator.LoadPositionList();
            var expected = positionListStub.Positions;
            var actual   = positionListValidator.Positions;

            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected.Count, actual.Count);
        }
        public void CantRepeatPositionName_withAddMethod()
        {
            var    position              = new DTOPosition(3, "1", "1");
            var    positionListStub      = new PositionListStub();
            var    positionListValidator = new PositionListValidator(positionListStub);
            string error = null;
            EventHandler <PositionListChangedEventArgs> handler = (sender, e) => error = e.Error;

            positionListValidator.PositionListChanged += handler;
            positionListValidator.LoadPositionList();
            positionListValidator.AddPosition(position);
            Assert.AreEqual("Name 1 is already taken", error);
        }
        public void CanUpdateCategoryOnly()
        {
            var    position              = new DTOPosition(2, "2", "1");
            var    positionListStub      = new PositionListStub();
            var    positionListValidator = new PositionListValidator(positionListStub);
            string error = null;
            EventHandler <PositionListChangedEventArgs> handler = (sender, e) => error = e.Error;

            positionListValidator.PositionListChanged += handler;
            positionListValidator.LoadPositionList();
            positionListValidator.UpdatePosition(position);
            Assert.IsNull(error);
        }
        public void CantUpdateToExistingName()
        {
            var    position              = new DTOPosition(2, "1", "1");
            var    positionListStub      = new PositionListStub();
            var    positionListValidator = new PositionListValidator(positionListStub);
            string error = null;
            EventHandler <PositionListChangedEventArgs> handler = (sender, e) => error = e.Error;

            positionListValidator.PositionListChanged += handler;
            positionListValidator.LoadPositionList();
            positionListValidator.UpdatePosition(position);
            Assert.AreEqual("Name 1 is already taken", error);
        }
        public void UpdatePositionMethod_InvokesDependencyAddPositionMethod_IfPositionPassesValidation()
        {
            var  position         = new DTOPosition(1, "1", "1");
            var  positionListStub = new PositionListStub();
            bool invoked          = false;
            EventHandler <PositionListChangedEventArgs> handler = (sender, e) => invoked = true;

            positionListStub.PositionListChanged += handler;
            var positionListValidator = new PositionListValidator(positionListStub);

            positionListValidator.LoadPositionList();
            positionListValidator.UpdatePosition(position);
            Assert.IsTrue(invoked);
        }