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);
}
}

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lattice.Core.DragDrop\Lattice.Core.DragDrop.csproj" />
</ItemGroup>
</Project>