Example #1
0
        public void AddManifestSnapshotValidValues()
        {
            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 = "teste_manifest";

            var sessionId           = Guid.NewGuid();
            var registeredServiceId = "teste_service";
            var session             = new ServiceSession
            {
                Id = sessionId,
                RegisteredServiceId = registeredServiceId
            };

            sessionRepoMock
            .Setup(r => r.GetById(It.Is <Guid>(g => g == sessionId)))
            .Returns(new ServiceSession()
            {
                Id = sessionId,
                RegisteredServiceId = registeredServiceId
            }).Verifiable();

            sessionRepoMock
            .Setup(r => r.Update(It.Is <ServiceSession>(s =>
                                                        s.ManifestSnapshots[0].Manifest == manifest &&
                                                        s.Id == sessionId &&
                                                        s.RegisteredServiceId == registeredServiceId)
                                 )).Returns(true)
            .Verifiable();

            mapperMock
            .Setup(m => m.Map <ManifestSnapshot, ManifestSnapshotDTO>(It.Is <ManifestSnapshot>(s =>
                                                                                               s.Manifest == manifest
                                                                                               ))).Returns(new ManifestSnapshotDTO
            {
                Manifest = manifest
            }).Verifiable();

            var result = sessionManager.AddManifestSnapshot(sessionId, manifest);

            Assert.Equal(manifest, result.Manifest);

            sessionRepoMock.Verify();
            mapperMock.Verify();
        }
Example #2
0
        public void AddManifestSnapshotNonExistent()
        {
            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();
            var manifest  = "test_manifest";

            sessionRepoMock
            .Setup(r => r.GetById(It.Is <Guid>(g => g == sessionId)))
            .Returns <ServiceSession>(null)
            .Verifiable();

            Assert.Throws <EntityNotFoundException>(() => sessionManager.AddManifestSnapshot(sessionId, manifest));

            sessionRepoMock.Verify();
        }