public void GetSessionExistingId() { var loggerMock = new Mock <ILogger <ServiceSessionManager> >(); var sessionRepoMock = new Mock <IServiceSessionRepository>(MockBehavior.Strict); var mapperMock = new Mock <IMapper>(MockBehavior.Strict); var sessionManager = new ServiceSessionManager(loggerMock.Object, sessionRepoMock.Object, mapperMock.Object); var manifest = "test_manifest"; var dateAndTime = DateTime.UtcNow; var manifestSnapshot = new ManifestSnapshot { Manifest = manifest, DateAndTime = dateAndTime }; var sessionId = Guid.NewGuid(); var serviceSession = new ServiceSession() { Id = sessionId, ManifestSnapshots = new List <ManifestSnapshot> { manifestSnapshot } }; sessionRepoMock .Setup(r => r.GetById(sessionId)) .Returns(serviceSession) .Verifiable(); mapperMock .Setup(m => m.Map <ServiceSession, ServiceSessionDTO>(It.Is <ServiceSession>(s => s == serviceSession))) .Returns(new ServiceSessionDTO { Id = sessionId.ToString() }).Verifiable(); mapperMock .Setup(m => m.Map <ManifestSnapshot, ManifestSnapshotDTO>(It.Is <ManifestSnapshot>(s => s == manifestSnapshot))) .Returns(new ManifestSnapshotDTO { Manifest = manifest, DateAndTime = dateAndTime }).Verifiable(); var result = sessionManager.GetById(sessionId); Assert.Equal(serviceSession.Id.ToString(), result.Id); Assert.Equal(manifestSnapshot.Manifest, result.LastManifestSnapshot.Manifest); Assert.Equal(manifestSnapshot.DateAndTime, result.LastManifestSnapshot.DateAndTime); sessionRepoMock.Verify(); mapperMock.Verify(); }
public void GetSessionNonExistingId() { var loggerMock = new Mock <ILogger <ServiceSessionManager> >(); var sessionRepoMock = new Mock <IServiceSessionRepository>(MockBehavior.Strict); var mapperMock = new Mock <IMapper>(MockBehavior.Strict); var sessionManager = new ServiceSessionManager(loggerMock.Object, sessionRepoMock.Object, mapperMock.Object); var sessionId = Guid.NewGuid(); sessionRepoMock .Setup(r => r.GetById(sessionId)) .Returns <ServiceSession>(null) .Verifiable(); var result = sessionManager.GetById(sessionId); Assert.Null(result); sessionRepoMock.Verify(); mapperMock.Verify(); }