Код: Выделить всё
Moq.MockException :
Expected invocation on the mock once, but was 0 times: m => m.Position = Vector
Performed invocations:
Mock (m):
IMove.Position
IMove.Velocity
IMove.Position = Vector
Код: Выделить всё
using Moq;
namespace Lab1.Test
{
public class UnitTest1
{
[Fact]
public void Move_from_12_5_to_5_8_with_velocity_N7_3()
{
var move = new Mock();
move.SetupGet(m => m.Position).Returns(new Vector( 12, 5)).Verifiable();
move.SetupGet(m => m.Velocity).Returns(new Vector( -5, 3)).Verifiable();
ICommand moveCommand = new CMove(move.Object);
moveCommand.Execute();
move.VerifySet(m => m.Position = new Vector( 5, 8), Times.Once);
move.VerifyAll();
}
}
}
Код: Выделить всё
public class Vector
{
private int[] coordinates;
private int coord_cont;
public Vector(params int[] coordinates)
{
this.coordinates = coordinates;
this.coord_cont = coordinates.Length;
}
public static Vector operator +(Vector a, Vector b)
{
Vector c = new(new int[a.coord_cont]);
c.coordinates = (a.coordinates.Select((x, index) => x + b.coordinates[index]).ToArray());
return c;
}
public override bool Equals(object? obj)
{
if (obj == null || obj is not Vector)
return false;
else
return coordinates.SequenceEqual(((Vector)obj).coordinates);
}
public override int GetHashCode()
{
return coordinates.GetHashCode();
}
}
public interface IMove
{
public Vector Position { get; set; }
public Vector Velocity { get; }
}
public class CMove : ICommand
{
private readonly IMove move;
public CMove(IMove move)
{
this.move = move;
}
public void Execute()
{
move.Position += move.Velocity;
}
}
Я пытаюсь привести простой пример использования moq.
Я не понимаю, почему вызов макета был 0 раз/Я пытался найти решение в Интернете, но не нашел подобного случая
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-with-moq