Esempio n. 1
0
        public void Initialize(XmlElement config, IEventManager eventManager, IProfile profile)
        {
            var bugzillaConfig = new BugzillaServiceConfiguration();

            ConfigurationReader.ReadConfigurationValues(bugzillaConfig, config);

            ConfigurationReader.ProcessMappingSettings(bugzillaConfig.ProjectMappings, config[ProjectMappingsNode], BugzillaProjectNode, VersionOneProjectNode);
            ConfigurationReader.ProcessMappingSettings(bugzillaConfig.PriorityMappings, config[PriorityMappingsNode], BugzillaPriorityNode, VersionOnePriorityNode);

            sourceFieldValue = config["SourceFieldValue"].InnerText;

            this.eventManager = eventManager;
            logger            = new Logger(eventManager);
            var bugzillaClientConfiguration = new BugzillaClientConfiguration {
                UserName = bugzillaConfig.UserName, Password = bugzillaConfig.Password, Url = bugzillaConfig.Url, IgnoreSSLCert = bugzillaConfig.IgnoreCert
            };

            bugzillaClientFactory = new BugzillaClientFactory(bugzillaClientConfiguration, logger);

            var readerUpdater = new BugzillaReaderUpdater(bugzillaConfig, bugzillaClientFactory, logger);

            bugzillaReader  = readerUpdater;
            bugzillaUpdater = readerUpdater;

            this.eventManager.Subscribe(typeof(IntervalSync), OnInterval);
            this.eventManager.Subscribe(typeof(WorkitemCreationResult), OnDefectCreated);
            this.eventManager.Subscribe(typeof(WorkitemStateChangeCollection), OnDefectStateChanged);
        }
		private void GetBugs(BugzillaServiceConfiguration config)
		{
			BugzillaMocks mocks = new BugzillaMocks();

			List<Bug> expectedBugs = CreateSomeBogusRemoteBugs(5);
			List<int> expectedIds = new List<int>();

			Product expectedProduct = Product.Create(new GetProductResult(productId, productName, "Expected Descr"));
			User expectedOwner = User.Create(new GetUserResult(ownerId, "Fred", "FredsLogin"));

			foreach (Bug bug in expectedBugs)
			{
				expectedIds.Add(bug.ID);
			}

			SetupResult.For(mocks.ServiceFactory.CreateNew(config.Url)).Return(mocks.Client);

            Expect.Call(mocks.Client.Login(config.UserName, config.Password, true, false)).Return(expectedUserId);
			//Expect.Call(mocks.Client.GetBugs(config.OpenIssueFilterId)).Return(expectedIds);

			for (int i = 0; i < expectedBugs.Count; i++)
			{
				Bug bug = expectedBugs[i];
				Expect.Call(mocks.Client.GetBug(bug.ID)).Return(bug);
				Expect.Call(mocks.Client.GetProduct(bug.ProductID)).Return(expectedProduct);
				Expect.Call(mocks.Client.GetUser(bug.AssignedToID)).Return(expectedOwner);
			}

			mocks.Client.Logout();

			mocks.Repository.ReplayAll();

			BugzillaReaderUpdater reader = new BugzillaReaderUpdater(config, mocks.ServiceFactory, mocks.Logger);

			List<Defect> returnedBugs = reader.GetBugs();

			Assert.AreEqual(expectedBugs.Count, returnedBugs.Count, "Did not get back the right number of defects.");

			foreach (Defect defect in returnedBugs)
			{
				Assert.AreEqual(defect.ProjectId, v1ProjectId);
				Assert.AreEqual(defect.Owners, expectedOwner.Login);
                Assert.AreEqual(defect.Priority, v1PriorityId);

				if (! string.IsNullOrEmpty(config.UrlTemplateToIssue) && ! string.IsNullOrEmpty(config.UrlTitleToIssue))
				{
					Assert.AreEqual(config.UrlTemplateToIssue.Replace("#key#", defect.ExternalId), defect.ExternalLink.Url);
					Assert.AreEqual(config.UrlTitleToIssue, defect.ExternalLink.Title);
				}
			}

			mocks.Repository.VerifyAll();
		}
        public void Initialize(XmlElement config, IEventManager eventManager, IProfile profile) {
            var bugzillaConfig = new BugzillaServiceConfiguration();

            ConfigurationReader.ReadConfigurationValues(bugzillaConfig, config);

            ConfigurationReader.ProcessMappingSettings(bugzillaConfig.ProjectMappings, config[ProjectMappingsNode], BugzillaProjectNode, VersionOneProjectNode);
            ConfigurationReader.ProcessMappingSettings(bugzillaConfig.PriorityMappings, config[PriorityMappingsNode], BugzillaPriorityNode, VersionOnePriorityNode);

            sourceFieldValue = config["SourceFieldValue"].InnerText;

            this.eventManager = eventManager;
            logger = new Logger(eventManager);

            var readerUpdater = new BugzillaReaderUpdater(bugzillaConfig, new BugzillaClientFactory(), logger);
            bugzillaReader = readerUpdater;
            bugzillaUpdater = readerUpdater;

            this.eventManager.Subscribe(typeof(IntervalSync), OnInterval);
            this.eventManager.Subscribe(typeof(WorkitemCreationResult), OnDefectCreated);
            this.eventManager.Subscribe(typeof(WorkitemStateChangeCollection), OnDefectStateChanged);
        }
 public BugzillaReaderUpdater(BugzillaServiceConfiguration configuration, IBugzillaClientFactory bugzillaClientFactory, ILogger logger)
 {
     this.configuration         = configuration;
     this.bugzillaClientFactory = bugzillaClientFactory;
     this.logger = logger;
 }
		private BugzillaServiceConfiguration GetStockConfig()
		{
			BugzillaServiceConfiguration config = new BugzillaServiceConfiguration();
			config.UserName = userName;
			config.Password = password;
			config.Url = expectedUrl;
			config.OpenIssueFilterId = expectedFilterId;

            MappingInfo zillaProject = new MappingInfo(productId.ToString(), productName);
            MappingInfo v1Project = new MappingInfo(v1ProjectId, null);
            config.ProjectMappings.Add(zillaProject, v1Project);
    
            MappingInfo zillaPriority = new MappingInfo(null, expectedPriority);
            MappingInfo v1Priority = new MappingInfo(v1PriorityId, null);
            config.PriorityMappings.Add(zillaPriority, v1Priority);

			return config;
		}
		private void OnDefectCreated(BugzillaServiceConfiguration config)
		{
			BugzillaMocks mocks = new BugzillaMocks();

			Defect defect = GetStockBug();
			int expectedExternalId = 1234;
			string expectedDefectLinkValue = "http://localhost/VersionOne.Web/assetdetail.v1?Oid=Defect:1000";

			defect.ExternalId = expectedExternalId.ToString();
			WorkitemCreationResult workitemCreationResult = new WorkitemCreationResult(defect);
			workitemCreationResult.Messages.Add("Message1");
			workitemCreationResult.Permalink = expectedDefectLinkValue;

			SetupResult.For(mocks.ServiceFactory.CreateNew(config.Url)).Return(mocks.Client);

			Expect.Call(mocks.Client.Login(config.UserName, config.Password, true, false)).Return(expectedUserId);
			
			if (!string.IsNullOrEmpty(config.OnCreateFieldName))
			{
				Expect.Call(mocks.Client.UpdateBug(expectedExternalId, config.OnCreateFieldName, config.OnCreateFieldValue)).Return(true);
			}

			if (!string.IsNullOrEmpty(config.DefectLinkFieldName))
			{
				Expect.Call(mocks.Client.UpdateBug(expectedExternalId, config.DefectLinkFieldName, expectedDefectLinkValue)).Return(true);
			}

			if (!string.IsNullOrEmpty(config.OnCreateReassignValue))
			{
				Expect.Call(mocks.Client.ReassignBug(expectedExternalId, config.OnCreateReassignValue)).Return(true);
			}

			if (!string.IsNullOrEmpty(config.OnCreateResolveValue))
			{
				Expect.Call(mocks.Client.ResolveBug(expectedExternalId, config.OnCreateResolveValue, string.Empty)).Return(true);
			}

			mocks.Client.Logout();

			mocks.Repository.ReplayAll();

			BugzillaReaderUpdater updater = new BugzillaReaderUpdater(config, mocks.ServiceFactory, mocks.Logger);

			updater.OnDefectCreated(workitemCreationResult);

			mocks.Repository.VerifyAll();

		}
		public BugzillaReaderUpdater(BugzillaServiceConfiguration configuration, IBugzillaClientFactory bugzillaClientFactory, ILogger logger) 
        {
			this.configuration = configuration;
            this.bugzillaClientFactory = bugzillaClientFactory;
            this.logger = logger;
		}