DragAndDrop core

This commit is contained in:
FrigaT
2026-01-18 16:33:35 +03:00
parent 9ea82af329
commit 79bdd8bc62
229 changed files with 21214 additions and 2494 deletions

View File

@@ -0,0 +1,115 @@
using Lattice.Core.DragDrop.Abstractions;
using Lattice.Core.DragDrop.Enums;
using Lattice.Core.DragDrop.Models;
using Lattice.Core.DragDrop.Services;
using Lattice.Core.Geometry;
using Moq;
using Xunit;
namespace Lattice.Core.DragDrop.Tests;
public class DragDropServiceTests
{
[Fact]
public void StartDrag_WithValidSource_StartsDragOperation()
{
// Arrange
var service = new DragDropService();
var mockSource = new Mock<IDragSource>();
var dragInfo = new DragInfo("test", DragDropEffects.Copy, new Point(0, 0));
mockSource.Setup(s => s.CanStartDrag(out dragInfo)).Returns(true);
mockSource.Setup(s => s.StartDrag(It.IsAny<DragInfo>())).Returns(true);
// Act
var result = service.StartDrag(mockSource.Object, new Point(0, 0));
// Assert
Assert.True(result);
Assert.True(service.IsDragActive);
Assert.NotNull(service.CurrentDragInfo);
}
[Fact]
public void RegisterDropTarget_ReturnsValidId()
{
// Arrange
var service = new DragDropService();
var mockTarget = new Mock<IDropTarget>();
var bounds = new Rect(0, 0, 100, 100);
// Act
var id = service.RegisterDropTarget(mockTarget.Object, bounds);
// Assert
Assert.NotNull(id);
Assert.NotEmpty(id);
}
[Fact]
public void UpdateDrag_WithValidDropTarget_CallsDragOver()
{
// Arrange
var service = new DragDropService();
var mockSource = new Mock<IDragSource>();
var mockTarget = new Mock<IDropTarget>();
var dragInfo = new DragInfo("test", DragDropEffects.Copy, new Point(0, 0));
mockSource.Setup(s => s.CanStartDrag(out dragInfo)).Returns(true);
mockSource.Setup(s => s.StartDrag(It.IsAny<DragInfo>())).Returns(true);
var targetId = service.RegisterDropTarget(mockTarget.Object, new Rect(0, 0, 100, 100));
service.StartDrag(mockSource.Object, new Point(0, 0));
// Act
service.UpdateDrag(new Point(50, 50));
// Assert
mockTarget.Verify(t => t.DragOver(It.IsAny<DropInfo>()), Times.AtLeastOnce());
}
[Fact]
public void EndDrag_WithValidDrop_CallsDrop()
{
// Arrange
var service = new DragDropService();
var mockSource = new Mock<IDragSource>();
var mockTarget = new Mock<IDropTarget>();
var dragInfo = new DragInfo("test", DragDropEffects.Copy, new Point(0, 0));
mockSource.Setup(s => s.CanStartDrag(out dragInfo)).Returns(true);
mockSource.Setup(s => s.StartDrag(It.IsAny<DragInfo>())).Returns(true);
service.RegisterDropTarget(mockTarget.Object, new Rect(0, 0, 100, 100));
service.StartDrag(mockSource.Object, new Point(0, 0));
service.UpdateDrag(new Point(50, 50));
// Act
var effects = service.EndDrag(new Point(50, 50));
// Assert
mockTarget.Verify(t => t.Drop(It.IsAny<DropInfo>()), Times.Once());
Assert.False(service.IsDragActive);
}
[Fact]
public void CancelDrag_WithActiveDrag_CallsDragCancelled()
{
// Arrange
var service = new DragDropService();
var mockSource = new Mock<IDragSource>();
var dragInfo = new DragInfo("test", DragDropEffects.Copy, new Point(0, 0));
mockSource.Setup(s => s.CanStartDrag(out dragInfo)).Returns(true);
mockSource.Setup(s => s.StartDrag(It.IsAny<DragInfo>())).Returns(true);
service.StartDrag(mockSource.Object, new Point(0, 0));
// Act
service.CancelDrag();
// Assert
mockSource.Verify(s => s.DragCancelled(It.IsAny<DragInfo>()), Times.Once());
Assert.False(service.IsDragActive);
}
}