Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build
output
.gradle
.tmp
packages

# User-specific files
*.suo
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using JetBrains.ReSharper.FeaturesTestFramework.Intentions;
using JetBrains.ReSharper.TestFramework;
using NUnit.Framework;
using ReSharperPlugin.AutoMapper.FindUsage.Navigation;

namespace ReSharperPlugin.AutoMapper.FindUsage.Tests.Navigation;

[TestFixture]
[TestPackages("AutoMapper")]
public class AutoMapperNavigationActionAvailabilityTest
: CSharpContextActionAvailabilityTestBase<AutoMapperNavigationAction>
{
protected override string RelativeTestDataPath => "Navigation";
protected override string ExtraPath => "";

[Test] public void TestAvailableOnSetter() => DoNamedTest();

[Test] public void TestAvailableOnInit() => DoNamedTest();

[Test] public void TestReverseMap() => DoNamedTest();

[Test] public void TestReverseMapChain() => DoNamedTest();

[Test] public void TestMultipleMappings() => DoNamedTest();

[Test] public void TestConfigurationExpression() => DoNamedTest();

[Test] public void TestNotAvailableOnGetter() => DoNamedTest();

[Test] public void TestNotAvailableWithoutMapping() => DoNamedTest();

[Test] public void TestNotAvailableOnUnmappedType() => DoNamedTest();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using JetBrains.ReSharper.FeaturesTestFramework.Intentions;
using JetBrains.ReSharper.TestFramework;
using NUnit.Framework;
using ReSharperPlugin.AutoMapper.FindUsage.Navigation;

namespace ReSharperPlugin.AutoMapper.FindUsage.Tests.Navigation;

[TestFixture]
public class AutoMapperNavigationActionWithoutAutoMapperAvailabilityTest
: CSharpContextActionAvailabilityTestBase<AutoMapperNavigationAction>
{
protected override string RelativeTestDataPath => "Navigation";
protected override string ExtraPath => "";

[Test] public void TestNotAvailableWithoutAutoMapper() => DoNamedTest();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="JetBrains.ReSharper.SDK.Tests" Version="$(SdkVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;

namespace TestProject;

public class SourceDto
{
public string Name { get; set; }
}

public class DestinationDto
{
public string Name { get; init{on}; }
}

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<SourceDto, DestinationDto>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;

namespace TestProject;

public class SourceDto
{
public string Name { get; set; }
}

public class DestinationDto
{
public string Name { get; set{on}; }
}

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<SourceDto, DestinationDto>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using AutoMapper;

namespace TestProject;

public class SourceDto { public string Name { get; set; } }
public class DestinationDto { public string Name { get; set{on}; } }

public class Startup
{
public void Configure()
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SourceDto, DestinationDto>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using AutoMapper;

namespace TestProject;

public class Source1Dto { public string Name { get; set; } }
public class Source2Dto { public string Name { get; set; } }

public class DestinationDto
{
public string Name { get; set{on}; }
}

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<Source1Dto, DestinationDto>();
CreateMap<Source2Dto, DestinationDto>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;

namespace TestProject;

public class SourceDto
{
public string Name { get; set; }
}

public class DestinationDto
{
public string Name { get{off}; set; }
}

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<SourceDto, DestinationDto>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using AutoMapper;

namespace TestProject;

public class SourceDto { public string Name { get; set; } }
public class DestinationDto { public string Name { get; set; } }

public class UnmappedDto
{
public string Name { get; set{off}; }
}

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<SourceDto, DestinationDto>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace TestProject;

public class SourceDto
{
public string Name { get; set; }
}

public class DestinationDto
{
public string Name { get; set{off}; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;

namespace TestProject;

public class SourceDto
{
public string Name { get; set; }
}

public class DestinationDto
{
public string Name { get; set{off}; }
}

public class TestProfile : Profile
{
public TestProfile()
{
// No CreateMap here
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;

namespace TestProject;

public class SourceDto
{
public string Name { get; set{on}; }
}

public class DestinationDto
{
public string Name { get; set; }
}

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<SourceDto, DestinationDto>().ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using AutoMapper;

namespace TestProject;

public class SourceDto { public string Name { get; set{on}; } }
public class DestinationDto { public string Name { get; set; } }

public class TestProfile : Profile
{
public TestProfile()
{
CreateMap<SourceDto, DestinationDto>().MaxDepth(5).ReverseMap();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Please commit this file, it's crucial for tests stability. Even if you believe it's not yours, it still needs to be committed.
# Input (NuGetFramework=net9.0):
# JetBrains.Annotations [2025.2.0]
# Microsoft.NETCore.App.Ref [9.0.0]
JetBrains.Annotations 2025.2.0
Microsoft.NETCore.App.Ref 9.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Please commit this file, it's crucial for tests stability. Even if you believe it's not yours, it still needs to be committed.
# Input (NuGetFramework=net9.0):
# AutoMapper (, )
# Microsoft.NETCore.App.Ref [9.0.0]
AutoMapper 16.1.1
Microsoft.Extensions.DependencyInjection.Abstractions 10.0.0
Microsoft.Extensions.Logging.Abstractions 10.0.0
Microsoft.Extensions.Options 10.0.0
Microsoft.Extensions.Primitives 10.0.0
Microsoft.IdentityModel.Abstractions 8.14.0
Microsoft.IdentityModel.JsonWebTokens 8.14.0
Microsoft.IdentityModel.Logging 8.14.0
Microsoft.IdentityModel.Tokens 8.14.0
Microsoft.NETCore.App.Ref 9.0.0
System.Diagnostics.DiagnosticSource 10.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Please commit this file, it's crucial for tests stability. Even if you believe it's not yours, it still needs to be committed.
# Input (NuGetFramework=net9.0):
# Microsoft.NETCore.App.Ref [9.0.0]
Microsoft.NETCore.App.Ref 9.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using JetBrains.ReSharper.Feature.Services.Navigation;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.Modules;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.TextControl;
using JetBrains.ReSharper.Psi.Resources;
Expand Down Expand Up @@ -83,18 +84,26 @@ private IEnumerable<IntentionAction> CreateBulbItemsInternal()

public bool IsAvailable(IUserDataHolder cache)
{
if (!IsAutoMapperAvailable(_dataProvider.PsiModule))
return false;

var property = GetSelectedProperty();
if (property == null) return false;
if (property == null)
return false;

// To avoid heavy computation in IsAvailable, we just return true if it's a property.
// The actual search will happen in CreateBulbItems.
return true;
}

private static bool IsAutoMapperAvailable(IPsiModule module)
{
return TypeFactory.CreateTypeByCLRName("AutoMapper.Profile", module).GetTypeElement() != null;
}

private IProperty GetSelectedProperty()
{
var node = _dataProvider.GetSelectedTreeNode<ITreeNode>();
if (node == null) return null;
if (node == null)
return null;

var accessorDeclaration = node.GetContainingNode<IAccessorDeclaration>(true);
if (accessorDeclaration is { Kind: AccessorKind.SETTER })
Expand All @@ -109,9 +118,8 @@ private IProperty GetSelectedProperty()
private static IProperty FindCorrespondingProperty(IType type, string propertyName)
{
var typeElement = (type as IDeclaredType)?.GetTypeElement();
if (typeElement == null) return null;

return typeElement.GetMembers().OfType<IProperty>().FirstOrDefault(p => p.ShortName == propertyName);
return typeElement?.Properties.FirstOrDefault(p => p.ShortName == propertyName);
}

private static string GetFullName(IType type, PsiLanguageType language)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Tree;

namespace ReSharperPlugin.AutoMapper.FindUsage.Registrations;

public sealed class AutoMapperMapping
{
public IType Source { get; }
public IType Destination { get; }
public ITreeNode Registration { get; }

public AutoMapperMapping(IType source, IType destination, ITreeNode registration)
{
Source = source;
Destination = destination;
Registration = registration;
}
}
Loading
Loading