EF 4.1 :: Testing with Moq & NUnit
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I've been using the EF Code First + Repositories pattern from http://efmvc.codeplex.com which has a couple differences from the way you've constructed yours First thing I noticed is your Unit of Work is tied to EF. EFMVC's Unit of Work is simply public interface IUnitOfWork
{
void Commit();
}
public interface IRepository<T> where T : class
{
void Add(T entity);
void Update(T entity);
void Delete(T entity);
void Delete(Expression<Func<T, bool>> where);
T GetById(long Id);
T GetById(string Id);
T Get(Expression<Func<T, bool>> where);
IQueryable<T> GetAll();
IQueryable<T> GetMany(Expression<Func<T, bool>> where);
}
public class Uploader : IUploader
{
private readonly IReportRepository _reportRepository;
private readonly IUnitOfWork _unitOfWork;
public Uploader(IReportRepository reportRepository, IUnitOfWork unitOfWork)
{
_reportRepository = reportRepository;
_unitOfWork = unitOfWork;
}
public void Upload(Report report)
{
_reportRepository.Add(report);
_unitOfWork.Commit();
}
}
|
Nunit - testing exe
Date : March 29 2020, 07:55 AM
To fix this issue Check is the accessibility of the classes you want to test. They have to be marked as public otherwise your test project won't be able to see them to load them up. Another alternative to making your classes public is to use the InternalsVisibleTo attribute in your EXE and grant access to your test project DLL. Instead of public, you would just need to mark them as internal. [assembly: InternalsVisibleTo( "Project.Tests" )]
|
Testing Nancy module with nUnit fails assert when testing HttpStatusCode
Date : March 29 2020, 07:55 AM
I hope this helps . Argggh.... I've been ReShafted.. I just found this at the top of the file which I'm certain I didn't put there myself. using HttpStatusCode = System.Net.HttpStatusCode;
|
Testing with MEF and Moq and NUnit
Date : March 29 2020, 07:55 AM
may help you . It's not really clear what exactly you're trying to test, looking on a code you've provided, but I'll try to address your question. The main problem with Dependency class is that it's static (or probably its Resolve<> method). You should try to abstract it via introducing IDependency interface public interface IDependency
{
T Resolve<T>();
}
[ImportingConstructor]
public FzrteMonitoringService(
IEventAggregator inEventAggregator,
IDependency dependency)
{
_eventAggregator = inEventAggregator;
_dependency = dependency;
_monitoringRequestExecutor = dependency.Resolve<IFzrteMonitoringRequestResponseHandler>();
WatchedPorts = new List<string>();
_monitoringRequests = new ConcurrentQueue<FzrteMonitoringRequest>();
//subsription for monitoring requests on the UI thread to limit the user
//from generating meaningless requests
_eventAggregator.GetEvent<MonitoringRequestGenerated>()
.Subscribe(this.FilterEventType, ThreadOption.UIThread, true);
}
[Test]
[Category("Simple Basic Tests")]
public void SubscribesToMonitoringRequets_requestPublished_FilterEventTypeCalled()
{
//mock of event aggregator and the request event dependencies of monitoring service
var mockEventAggregator = new Mock<IEventAggregator>();
var mockMonitoringRequestedEvent = new Mock<MonitoringRequestGenerated>();
var mockDependecy = new Mock<IDependency>();
mockEventAggregator.Setup(x => x.GetEvent<MonitoringRequestGenerated>())
.Returns(mockMonitoringRequestedEvent.Object);
Action<List<MonitoringRequest>> callbackMethod = null;
mockMonitoringRequestedEvent
.Setup(
x => x.Subscribe(
It.IsAny<Action<List<MonitoringRequest>>>(),
It.IsAny<ThreadOption>(),
It.IsAny<bool>(),
It.IsAny<Predicate<List<MonitoringRequest>>>()))
.Callback<Action<List<MonitoringRequest>>, ThreadOption, bool, Predicate<List<MonitoringRequest>>>(
(a, t, b, p) => callbackMethod = a);
var testFzrteMonitoringService = new FzrteMonitoringService(
mockEventAggregator.Object, mockDependecy.Object);
//use the actual event aggregator to publish
var mockMonitoringRequestEventPayload = new Mock<List<MonitoringRequest>>();
mockEventAggregator.Object
.GetEvent<MonitoringRequestGenerated>()
.Publish(mockMonitoringRequestEventPayload.Object);
mockMonitoringRequestedEvent.Verify(
x => x.Subscribe(testFzrteMonitoringService.FilterEventType));
}
|
Can NUNIT, a unit-testing framework, be used for integration testing?
Tag : vb.net , By : Aki Björklund
Date : March 29 2020, 07:55 AM
|