Пример #1
0
        public void RepositoryConcurrentInitialize(bool initialized)
        {
            // Mock
            var initLock = new OperationLockTests.MockOperationLock();
            var factory = new Mock<IRepositoryFactory>(MockBehavior.Strict);
            var env = new Mock<IDeploymentEnvironment>();
            var settings = new Mock<IDeploymentSettingsManager>();
            var trace = new Mock<ITraceFactory>();

            var environment = new Mock<IEnvironment>();
            environment.SetupGet(e => e.RepositoryPath)
                       .Returns(String.Empty);
            environment.SetupGet(e => e.SiteRootPath)
                       .Returns(String.Empty);
            environment.SetupGet(e => e.RootPath)
                       .Returns(String.Empty);

            IRepository repository = initialized ? new Mock<IRepository>().Object : null;
            var server = new GitExeServer(environment.Object, initLock, null, factory.Object, env.Object, settings.Object, trace.Object);
            var calls = 0;

            // Setup
            trace.Setup(t => t.GetTracer())
                 .Returns(() => NullTracer.Instance);
            factory.Setup(f => f.GetRepository())
                   .Returns(() => repository);
            factory.Setup(f => f.EnsureRepository(RepositoryType.Git))
                   .Returns(() => 
                    {
                        ++calls;
                        Thread.Sleep(100);
                        Assert.Null(repository);
                        return repository = new Mock<IRepository>().Object;
                    });

            // Test
            Parallel.For(0, 5, i => server.Initialize());

            // Assert
            Assert.NotNull(repository);
            Assert.Equal(initialized ? 0 : 1, calls);
        }
Пример #2
0
        private static IDeploymentManagerFactory GetDeploymentManagerFactory(IEnvironment environment,
                                                                             IOperationLock initLock,
                                                                             IOperationLock deploymentLock,
                                                                             IBuildPropertyProvider propertyProvider,
                                                                             ITraceFactory traceFactory)
        {
            return new DeploymentManagerFactory(() =>
            {
                var serverRepository = new GitExeServer(environment.DeploymentRepositoryPath, initLock, traceFactory);
                var fileSystem = new FileSystem();
                var siteBuilderFactory = new SiteBuilderFactory(propertyProvider, environment);

                var deploymentManager = new DeploymentManager(serverRepository,
                                                              siteBuilderFactory,
                                                              environment,
                                                              fileSystem,
                                                              traceFactory,
                                                              deploymentLock);

                SubscribeForDeploymentEvents(deploymentManager);

                return deploymentManager;
            });
        }