public void UnexpectedAssignDestinationTest()
        {
            // Arrange
            var snapshot                  = Mock.Of <ISnapshot>();
            var dest                      = Mock.Of <ICSharpExpression>();
            var assignmentExpression      = Mock.Of <IAssignmentExpression>(t => t.Dest == dest);
            var eater                     = Mock.Of <IEater>();
            var eatExpressionHelper       = Mock.Of <EatExpressionHelper>();
            var expressionKindHelper      = Mock.Of <ExpressionKindHelper>();
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Assert
            Assert.Throws <UnexpectedAssignDestinationException>(() => assignmentExpressionEater.Eat(snapshot, assignmentExpression));
        }
        public void EatVariableAssignmentTest()
        {
            // Arrange
            var snapshot = Mock.Of<ISnapshot>();
            var source = Mock.Of<ICSharpExpression>();
            var dest = Mock.Of<IReferenceExpression>();
            var assignmentExpression = Mock.Of<IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater = Mock.Of<IEater>(t => t.Eat(snapshot, source) == ExpressionKind.StubCandidate);
            var eatExpressionHelper = Mock.Of<EatExpressionHelper>(t => t.GetReferenceElement(dest) == Mock.Of<IVariableDeclarationAndIDeclaredElement>());
            var expressionKindHelper = Mock.Of<ExpressionKindHelper>(t => t.KindOfAssignment(ExpressionKind.StubCandidate) == ExpressionKind.Stub);
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Act
            var kind = assignmentExpressionEater.Eat(snapshot, assignmentExpression);

            // Assert
            Assert.That(kind, Is.EqualTo(ExpressionKind.Stub));
        }
        public void EatAssignmentSourceExpressionTest()
        {
            // Arrange
            var snapshot = Mock.Of<ISnapshot>();
            var source = Mock.Of<ICSharpExpression>();
            var dest = Mock.Of<IReferenceExpression>();
            var assignmentExpression = Mock.Of<IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater = new Mock<IEater>();
            var eatExpressionHelper = Mock.Of<EatExpressionHelper>(t => t.GetReferenceElement(dest) == Mock.Of<IVariableDeclarationAndIDeclaredElement>());
            var expressionKindHelper = Mock.Of<ExpressionKindHelper>();
            var assignmentExpressionEater = new AssignmentExpressionEater(eater.Object, eatExpressionHelper, expressionKindHelper);

            // Act
            assignmentExpressionEater.Eat(snapshot, assignmentExpression);

            // Assert
            eater.Verify(t => t.Eat(snapshot, source));
        }
        public void EatVariableAssignmentTest()
        {
            // Arrange
            var snapshot                  = Mock.Of <ISnapshot>();
            var source                    = Mock.Of <ICSharpExpression>();
            var dest                      = Mock.Of <IReferenceExpression>();
            var assignmentExpression      = Mock.Of <IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater                     = Mock.Of <IEater>(t => t.Eat(snapshot, source) == ExpressionKind.StubCandidate);
            var eatExpressionHelper       = Mock.Of <EatExpressionHelper>(t => t.GetReferenceElement(dest) == Mock.Of <IVariableDeclarationAndIDeclaredElement>());
            var expressionKindHelper      = Mock.Of <ExpressionKindHelper>(t => t.KindOfAssignment(ExpressionKind.StubCandidate) == ExpressionKind.Stub);
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Act
            var kind = assignmentExpressionEater.Eat(snapshot, assignmentExpression);

            // Assert
            Assert.That(kind, Is.EqualTo(ExpressionKind.Stub));
        }
        public void ReturnNoneForEventAssigmentDestTest()
        {
            // Arrange
            var snapshot                  = Mock.Of <ISnapshot>();
            var source                    = Mock.Of <ICSharpExpression>();
            var dest                      = Mock.Of <IReferenceExpression>();
            var assignmentExpression      = Mock.Of <IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater                     = Mock.Of <IEater>();
            var eatExpressionHelper       = Mock.Of <EatExpressionHelper>(t => t.GetReferenceElement(dest) == Mock.Of <IEventDeclarationAndIDeclaredElement>());
            var expressionKindHelper      = Mock.Of <ExpressionKindHelper>();
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Act
            var kind = assignmentExpressionEater.Eat(snapshot, assignmentExpression);

            // Assert
            Assert.That(kind, Is.EqualTo(ExpressionKind.None));
        }
        public void EatAssignmentSourceExpressionTest()
        {
            // Arrange
            var snapshot                  = Mock.Of <ISnapshot>();
            var source                    = Mock.Of <ICSharpExpression>();
            var dest                      = Mock.Of <IReferenceExpression>();
            var assignmentExpression      = Mock.Of <IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater                     = new Mock <IEater>();
            var eatExpressionHelper       = Mock.Of <EatExpressionHelper>(t => t.GetReferenceElement(dest) == Mock.Of <IVariableDeclarationAndIDeclaredElement>());
            var expressionKindHelper      = Mock.Of <ExpressionKindHelper>();
            var assignmentExpressionEater = new AssignmentExpressionEater(eater.Object, eatExpressionHelper, expressionKindHelper);

            // Act
            assignmentExpressionEater.Eat(snapshot, assignmentExpression);

            // Assert
            eater.Verify(t => t.Eat(snapshot, source));
        }
        public void AddAssigningVariableToSnapshotTest()
        {
            // Arrange
            var snapshot = new Mock<ISnapshot>();
            var source = Mock.Of<ICSharpExpression>();
            var dest = Mock.Of<IReferenceExpression>();
            var assignmentExpression = Mock.Of<IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater = Mock.Of<IEater>(t => t.Eat(snapshot.Object, source) == ExpressionKind.StubCandidate);
            var variableDeclaration = Mock.Of<IVariableDeclarationAndIDeclaredElement>();
            var eatExpressionHelper = Mock.Of<EatExpressionHelper>(t => t.GetReferenceElement(dest) == variableDeclaration);
            var expressionKindHelper = Mock.Of<ExpressionKindHelper>(t => t.KindOfAssignment(ExpressionKind.StubCandidate) == ExpressionKind.Stub);
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Act
            assignmentExpressionEater.Eat(snapshot.Object, assignmentExpression);

            // Assert
            snapshot.Verify(t => t.Add(ExpressionKind.Stub, variableDeclaration), Times.Once);
        }
        public void AddAssigningVariableToSnapshotTest()
        {
            // Arrange
            var snapshot                  = new Mock <ISnapshot>();
            var source                    = Mock.Of <ICSharpExpression>();
            var dest                      = Mock.Of <IReferenceExpression>();
            var assignmentExpression      = Mock.Of <IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater                     = Mock.Of <IEater>(t => t.Eat(snapshot.Object, source) == ExpressionKind.StubCandidate);
            var variableDeclaration       = Mock.Of <IVariableDeclarationAndIDeclaredElement>();
            var eatExpressionHelper       = Mock.Of <EatExpressionHelper>(t => t.GetReferenceElement(dest) == variableDeclaration);
            var expressionKindHelper      = Mock.Of <ExpressionKindHelper>(t => t.KindOfAssignment(ExpressionKind.StubCandidate) == ExpressionKind.Stub);
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Act
            assignmentExpressionEater.Eat(snapshot.Object, assignmentExpression);

            // Assert
            snapshot.Verify(t => t.Add(ExpressionKind.Stub, variableDeclaration), Times.Once);
        }
        public void UnexpectedAssignDestinationTest()
        {
            // Arrange
            var snapshot = Mock.Of<ISnapshot>();
            var dest = Mock.Of<ICSharpExpression>();
            var assignmentExpression = Mock.Of<IAssignmentExpression>(t => t.Dest == dest);
            var eater = Mock.Of<IEater>();
            var eatExpressionHelper = Mock.Of<EatExpressionHelper>();
            var expressionKindHelper = Mock.Of<ExpressionKindHelper>();
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Assert
            Assert.Throws<UnexpectedAssignDestinationException>(() => assignmentExpressionEater.Eat(snapshot, assignmentExpression));
        }
        public void ReturnNoneForEventAssigmentDestTest()
        {
            // Arrange
            var snapshot = Mock.Of<ISnapshot>();
            var source = Mock.Of<ICSharpExpression>();
            var dest = Mock.Of<IReferenceExpression>();
            var assignmentExpression = Mock.Of<IAssignmentExpression>(t => t.Dest == dest && t.Source == source);
            var eater = Mock.Of<IEater>();
            var eatExpressionHelper = Mock.Of<EatExpressionHelper>(t => t.GetReferenceElement(dest) == Mock.Of<IEventDeclarationAndIDeclaredElement>());
            var expressionKindHelper = Mock.Of<ExpressionKindHelper>();
            var assignmentExpressionEater = new AssignmentExpressionEater(eater, eatExpressionHelper, expressionKindHelper);

            // Act
               var kind = assignmentExpressionEater.Eat(snapshot, assignmentExpression);

            // Assert
            Assert.That(kind, Is.EqualTo(ExpressionKind.None));
        }
 public UnexpectedAssignDestinationException(ICSharpExpression destination, AssignmentExpressionEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected assign destination. Expected IReferenceExpression, but was [{0}]", destination.GetType()), eater, node)
 {
     Destination = destination;
 }