from I select q[0]
from I select q[0]
CC#
Created by from I select q[0] on 8/31/2023 in #help
✅ unit testing ViemModels
I am very new to unit testing, and I have a typical example where I have a constructor with 4 services 3 of which is DI and one concrete generic for navigation E.g public
cs class ViewModel {

Public ViewModel ( IB service, IC service, ID service, E<F> navigation) {

}

}
cs class ViewModel {

Public ViewModel ( IB service, IC service, ID service, E<F> navigation) {

}

}
I have be having problem testing because I need to create a moq of E<F> and because of the way it is setup it's hard to abstract to interface. Does it make sense to create IViewModel And then have Class ViewModel:IViewModel And mock IViewModel instead? Is this the recommended approach? Is this good or bad ?
9 replies
CC#
Created by from I select q[0] on 4/14/2023 in #help
❔ trying to get published events in one project to the other
I have a Solution with two projects 1. Solution 1a. Project ( winUI3) 1b. Project.core 1a references 1b(core project) --- i am trying to publish events in 1b(core projects) and subscribe to the events in 1a(Ui projects viewmodel)
2 replies
CC#
Created by from I select q[0] on 2/17/2023 in #help
❔ unable to send messages using MVVMtoolkit messenger
i am trying to pass messages between two viewmodels employeeviewmode and storeviewmodebut it doesn't work
public class StoreViewModel :BaseViewModel
{


public ICommand NavigateEmployeeCommand { get; }
public StoreViewModel(INavigation storeNav)
{
NavigateEmployeeCommand = new NavigateCommand(storeNav);
}


protected override void OnActivated()
{
Messenger.Register<StoreViewModel, MonthNameMessage>(this, (r, m) => r.MonthMessageReceived= m.Value

);
}

private string _monthMessageReceived;
public string MonthMessageReceived { get => _monthMessageReceived;

set => SetProperty(ref _monthMessageReceived, value); }

}

//employee viemodel
public class EmployeeViewModel:BaseViewModel
{

public ICommand NavigateStoreCommand { get; }

public ICommand SendMessageCommand { get; }
public EmployeeViewModel(INavigation storeNav)
{
NavigateStoreCommand = new NavigateCommand(storeNav);

SendMessageCommand= new RelayCommand(SendMessage);

}


private readonly string _testVariable = "Employee haahahah";
public string TestVariable
{
get => _testVariable;


}

protected override void OnActivated()
{
Messenger.Register<EmployeeViewModel, CurrentMonthRequestMessage>(this, (r,m)=> m.Reply(r._testVariable));
}


public void SendMessage()
{
Messenger.Send(new MonthNameMessage(_testVariable));
}

}

//Message classes
public sealed class MonthNameMessage : ValueChangedMessage<string>
{
public MonthNameMessage(string value) : base(value)
{
}
}
public sealed class CurrentMonthRequestMessage:RequestMessage<string>
{

}
public class StoreViewModel :BaseViewModel
{


public ICommand NavigateEmployeeCommand { get; }
public StoreViewModel(INavigation storeNav)
{
NavigateEmployeeCommand = new NavigateCommand(storeNav);
}


protected override void OnActivated()
{
Messenger.Register<StoreViewModel, MonthNameMessage>(this, (r, m) => r.MonthMessageReceived= m.Value

);
}

private string _monthMessageReceived;
public string MonthMessageReceived { get => _monthMessageReceived;

set => SetProperty(ref _monthMessageReceived, value); }

}

//employee viemodel
public class EmployeeViewModel:BaseViewModel
{

public ICommand NavigateStoreCommand { get; }

public ICommand SendMessageCommand { get; }
public EmployeeViewModel(INavigation storeNav)
{
NavigateStoreCommand = new NavigateCommand(storeNav);

SendMessageCommand= new RelayCommand(SendMessage);

}


private readonly string _testVariable = "Employee haahahah";
public string TestVariable
{
get => _testVariable;


}

protected override void OnActivated()
{
Messenger.Register<EmployeeViewModel, CurrentMonthRequestMessage>(this, (r,m)=> m.Reply(r._testVariable));
}


public void SendMessage()
{
Messenger.Send(new MonthNameMessage(_testVariable));
}

}

//Message classes
public sealed class MonthNameMessage : ValueChangedMessage<string>
{
public MonthNameMessage(string value) : base(value)
{
}
}
public sealed class CurrentMonthRequestMessage:RequestMessage<string>
{

}
2 replies
CC#
Created by from I select q[0] on 10/7/2022 in #help
can anybody recommend where I can learn about file format encoding internals e.g pdf, doc, epubs
can anybody recommend where I can learn about file format encoding internals e.g pdf, doc, epubs
6 replies