public void CanConvertBuildCompletedEventToBuildDto() { //Arrange var mockAdoClient = new Mock <IAdoClient>(); var fakeBuild = new BuildDto() { Id = 1, Project = new ProjectDto() { Id = new System.Guid("3ededfb7-5b60-49d9-9c47-80bbf8f2dcb1") } }; var fakeBuildEvent = new BuildCompletedEvent() { EventType = BuildCompletedEvent.EventIdentifier, Resource = JsonDocument.Parse("{\"id\": 1}").RootElement, ResourceContainers = JsonDocument.Parse("{\"project\": {\"id\": \"3ededfb7-5b60-49d9-9c47-80bbf8f2dcb1\"}}").RootElement, }; mockAdoClient.Setup(m => m.GetBuild(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(fakeBuild)); ITypeConverter <AdoEvent, AdoDto> sut = new AdoEventToAdoDtoConverter(mockAdoClient.Object); //Act var result = sut.Convert(fakeBuildEvent, null, null) as BuildDto; //Assert Assert.NotNull(sut); Assert.NotNull(result); Assert.Equal(result.Id, fakeBuildEvent.Resource?.GetProperty("id").GetInt32()); Assert.Equal(result.Project.Id, fakeBuildEvent.ResourceContainers?.GetProperty("project").GetProperty("id").GetGuid()); Mock.VerifyAll(mockAdoClient); }
public void CanBeConstructed() { //Arrange BuildCompletedEvent sut; //Act sut = new BuildCompletedEvent(); //Assert Assert.NotNull(sut); Assert.Equal("build.complete", BuildCompletedEvent.EventIdentifier); }
private bool ShouldNotify(BuildCompletedEvent buildCompletedEvent, Model.Subscription subscription) { var buildDefinition = buildCompletedEvent.Resource.Definition.Name; var result = buildCompletedEvent.Resource.Status; if (subscription.BuildDefinitionName != "*" && !subscription.BuildDefinitionName.Contains(buildDefinition)) { return(false); } if (subscription.BuildState != "None" && subscription.BuildState != string.Empty && subscription.BuildState.ToLower() != result.ToLower()) { return(false); } return(true); }
public void CanBeSerialized() { //Arrange var sut = new BuildCompletedEvent() { Id = Guid.NewGuid().ToString(), EventType = "MyEventType", PublisherId = "MyPublisherId", Scope = "MyScope" }; //Act var payload = JsonSerializer.Serialize(sut, new JsonSerializerOptions { IgnoreNullValues = true }); //Assert Assert.NotNull(JsonDocument.Parse(payload)); }
public async Task <HttpResponseMessage> Post([FromBody] BuildCompletedEvent buildCompletedEvent) { var subscriptions = dataService.GetSubscriptions(); foreach (var subscription in subscriptions) { if (!ShouldNotify(buildCompletedEvent, subscription)) { continue; } var message = JsonConvert.DeserializeObject <ConversationReference>(subscription.ConversationReference).GetPostToUserMessage(); var client = new ConnectorClient(new Uri(message.ServiceUrl)); using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message)) { var botData = scope.Resolve <IBotData>(); await botData.LoadAsync(CancellationToken.None); // This is the dialog stack. var task = scope.Resolve <IDialogTask>(); var stack = scope.Resolve <IDialogStack>(); if (stack.Frames.Count > 0) { // Create the new dialog and add it to the stack. var dialog = new BuildEventNotificationDialog(buildCompletedEvent); task.Call(dialog.Void <object, IMessageActivity>(), null); await task.PollAsync(CancellationToken.None); // Flush the dialog stack back to its state store. await botData.FlushAsync(CancellationToken.None); } } } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
public BuildEventNotificationDialog(BuildCompletedEvent buildCompletedEvent) { this.buildCompletedEvent = buildCompletedEvent; }