public async Task Entry_FailedToDeliver_MaxRetryReached() { var costUserId = Guid.NewGuid(); var costId = Guid.NewGuid(); var costUser = new CostUser { Email = "*****@*****.**", Id = costUserId }; var data = new Dictionary <string, object>(); data[Constants.ActivityLogData.CostId] = costId; var delivery = new ActivityLogDelivery { RetryCount = MaxRetry, Status = ActivityLogDeliveryStatus.New }; var entry = new ActivityLog { ActivityLogType = ActivityLogType.CostCreated, IpAddress = "127.0.0.1", Data = JsonConvert.SerializeObject(data), Timestamp = DateTime.UtcNow, Created = DateTime.UtcNow, CostUserId = costUserId, CostUser = costUser, ActivityLogDelivery = delivery }; var message = new ActivityLogMessage(); var expected = ActivityLogDeliveryStatus.MaxRetriesReached; await _target.EntryDeliveryFailed(entry, message); entry.ActivityLogDelivery.Status.Should().Be(expected); }
public void ExecuteTest_OneEntryIsSent() { var costUserId = Guid.NewGuid(); var costId = Guid.NewGuid(); var costUser = new CostUser { Email = "*****@*****.**", Id = costUserId }; var message = "{}"; var data = new Dictionary <string, object>(); data[Constants.ActivityLogData.CostId] = costId; var delivery = new ActivityLogDelivery { RetryCount = 0, Status = ActivityLogDeliveryStatus.Processing }; var entry = new ActivityLog { ActivityLogType = ActivityLogType.CostCreated, IpAddress = "127.0.0.1", Data = JsonConvert.SerializeObject(data), Timestamp = DateTime.UtcNow, Created = DateTime.UtcNow, CostUserId = costUserId, CostUser = costUser, ActivityLogDelivery = delivery }; bool first = true; _serviceMock.Setup(x => x.GetProcessingActivityLogs()).ReturnsAsync(() => { if (first) { first = false; return(new[] { entry }); //Return entry for the first loop and null for the second loop (in the Job class). } return(null); }); _serviceMock.Setup(x => x.BuildLogMessage(It.IsAny <ActivityLog>())).Returns(new ActivityLogMessage { Message = message }); _ppServiceMock.Setup(x => x.SendMessage(It.IsAny <object>())).ReturnsAsync(true); //Act _target.Execute(); //Assert _serviceMock.Verify(e => e.GetProcessingActivityLogs(), Times.AtLeastOnce); _ppServiceMock.Verify(e => e.SendMessage(It.IsAny <object>()), Times.Once); }
public void Valid_Entry_BuildLogMessage_ReturnsJson() { //Arrange var costUserId = Guid.NewGuid(); var costId = Guid.NewGuid(); var costUser = new CostUser { Email = "*****@*****.**", Id = costUserId }; var data = new Dictionary <string, object>(); data[Constants.ActivityLogData.CostId] = costId; var delivery = new ActivityLogDelivery { RetryCount = 0, Status = ActivityLogDeliveryStatus.New }; var entry = new ActivityLog { ActivityLogType = ActivityLogType.CostCreated, IpAddress = "127.0.0.1", Data = JsonConvert.SerializeObject(data), Timestamp = DateTime.UtcNow, Created = DateTime.UtcNow, CostUserId = costUserId, CostUser = costUser, ActivityLogDelivery = delivery }; _templates.Add(new ActivityLogMessageTemplate { ActivityLogType = ActivityLogType.CostCreated, Id = 1, Template = "{\"timestamp\":\"{{ timestamp | date: \"yyyy-MM-ddTHH:mm:ss.fffZ\" }}\",\"id\":\"{ { messageId } }\",\"type\":\"costCreated\",\"object\":{\"id\":\"{{ objectId }}\",\"type\":\"activity\", \"message\":\"cost ''{{ costId | escape }}'' has been created\", \"costId\":\"{{ costId || escape }}\"},\"subject\":{\"id\":\"{{ subjectId }}\",\"application\":\"adcosts\"}}" }); //Act var result = _target.BuildLogMessage(entry); //Assert result.Should().NotBeNull(); result.Message.Should().NotBeNull(); var resultJson = JsonConvert.DeserializeObject(result.Message); resultJson.Should().NotBeNull();; }