Пример #1
0
        public void Updated_Minimal_None_NoneˆFails()
        {
            var payload = GetDataFileMatchingCallerName();

            var request = WorkItemRequest.Parse(payload);

            Assert.IsNotNull(request);
            Assert.IsFalse(request.IsValid);
            Assert.AreEqual("TFS Aggregator requires 'All' for 'Resource details to send'.", request.Error);
        }
Пример #2
0
        public void Restored_All_None_NoneˆSucceeds()
        {
            var payload = GetDataFileMatchingCallerName();

            var request = WorkItemRequest.Parse(payload);

            Assert.IsNotNull(request);
            Assert.IsTrue(request.IsValid);
            Assert.AreEqual(ChangeTypes.Restore, request.ChangeType);
            Assert.AreEqual("70b03e83-e51b-4ba1-8799-ee1ae0f863bb", request.CollectionId);
            Assert.AreEqual("https://win-vjnvouqjmam/DefaultCollection/", request.TfsCollectionUri);
            Assert.AreEqual(1, request.WorkItemId);
            Assert.AreEqual("prova1", request.TeamProject);
        }
Пример #3
0
        public void Updated_All_None_NoneˆSucceeds()
        {
            var payload = GetDataFileMatchingCallerName();

            var request = WorkItemRequest.Parse(payload);

            Assert.IsNotNull(request);
            Assert.IsTrue(request.IsValid);
            Assert.AreEqual(ChangeTypes.Change, request.ChangeType);
            Assert.AreEqual("1fe04a90-6116-437a-a208-f64a7711e8ff", request.CollectionId);
            Assert.AreEqual("https://giuliovaad.visualstudio.com/", request.TfsCollectionUri);
            Assert.AreEqual(12, request.WorkItemId);
            Assert.AreEqual("WorkItemTracking", request.TeamProject);
        }
Пример #4
0
        public void Restored_All_None_NoneˆSucceeds()
        {
            var payload = GetDataFileMatchingCallerName();

            var request = WorkItemRequest.Parse(payload);

            Assert.IsNotNull(request);
            Assert.IsTrue(request.IsValid);
            Assert.AreEqual(ChangeTypes.Restore, request.ChangeType);
            Assert.AreEqual("fcb4f585-afdd-4dc8-bb1b-1d8d5d9d2ff2", request.CollectionId);
            Assert.AreEqual("https://win-ro13gv4kfhq/DefaultCollection/", request.TfsCollectionUri);
            Assert.AreEqual(2, request.WorkItemId);
            Assert.AreEqual("FirstProject", request.TeamProject);
        }
Пример #5
0
        [Authorize]                   // Require some form of authentication
        public HttpResponseMessage Post([FromBody] JObject payload)
        {
            var request = WorkItemRequest.Parse(payload);

            if (!request.IsValid)
            {
                Log(request.Error);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = request.Error
                });
            }

            string policyFilePath = System.Configuration.ConfigurationManager.AppSettings["policyFilePath"];
            // macro expansion to permit multi-tenants
            string policyFile = policyFilePath.WithVar(request);

            // cache requires absolute path
            policyFile = System.Web.Hosting.HostingEnvironment.MapPath(policyFile);
            Debug.Assert(System.IO.File.Exists(policyFile));

            // need a logger to show errors in config file (Catch 22)
            var logger = new AspNetEventLogger(request.EventId, LogLevel.Normal);

            var context = new RequestContext(request.TfsCollectionUri, request.TeamProject);
            var runtime = RuntimeContext.GetContext(
                () => policyFile,
                context,
                logger,
                (runtimeContext) => new Core.Facade.WorkItemRepository(runtimeContext),
                (runtimeContext) => new Core.Script.ScriptLibrary(runtimeContext));

            if (runtime.HasErrors)
            {
                Log(runtime.Errors.Current);
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    ReasonPhrase = runtime.Errors.Current
                });
            }

            try
            {
                using (EventProcessor eventProcessor = new EventProcessor(runtime))
                {
                    context.CurrentWorkItemId = request.WorkItemId;
                    context.CurrentChangeType = request.ChangeType;
                    var notification = context.Notification;

                    logger.StartingProcessing(context, notification);
                    var result = eventProcessor.ProcessEvent(context, notification);
                    logger.ProcessingCompleted(result);

                    if (result.StatusCode == 0)
                    {
                        return(new HttpResponseMessage(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                        {
                            ReasonPhrase = result.StatusMessage
                        });
                    }
                }//using
            }
            catch (Exception e)
            {
                logger.ProcessEventException(e);
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    ReasonPhrase = e.Message
                });
            }//try
        }