I want to test a Xamarin view model with xUnit. When the code is build using command line on Mac, the following error are show:
/usr/local/share/dotnet/sdk/3.1.300/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App.WPF' was not recognized
If <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
is used on .csproj, the project compiles, but the following error are reported when I try to run the test.
System.BadImageFormatException : Duplicate type with name 'App.<>PropertyChangedEventArgs'
The view model are show below (part of the class). Fody and PropertyChanged.Fody are used to automate the implementation of INotifyPropertyChanged.
[AddINotifyPropertyChangedInterface]
public class ListaTarefasViewModel : ViewModelBase, IHandleViewAppearing, IHandleViewDisappearing
{
public ListaTarefasViewModel(
ITarefaService tarefaService,
ITarefaRepository tarefaRepository,
ITarefaRetornoItensRepository tarefaRetornoItensRepository,
INotificationService notificationService,
IUsuarioRepository usuarioRepository,
IProdutoRepository produtoRepository)
{
this.tarefaService = tarefaService;
this.tarefaRepository = tarefaRepository;
this.notificationService = notificationService;
this.usuarioRepository = usuarioRepository;
this.tarefaRetornoItensRepository = tarefaRetornoItensRepository;
this.produtoRepository = produtoRepository;
}
// ...
}
The test class:
public class ListaTarefasViewModelTest : IDisposable
{
private readonly Mock<ListaTarefasViewModel> listaTarefasViewModelMock;
public ListaTarefasViewModelTest()
{
listaTarefasViewModelMock = new Mock<ListaTarefasViewModel>();
}
public void Dispose()
{
}
[Fact]
public async Task ShouldConfigureTipoTarefaWhenInitializeAsync()
{
object tipoTarefa = TipoTarefaEnum.Inventario;
await listaTarefasViewModelMock.Object.InitializeAsync(tipoTarefa);
Assert.Equal(TipoTarefaEnum.Inventario, listaTarefasViewModelMock.Object.TipoTarefa);
}
}