Exemplo n.º 1
0
        public void UpdateWebhookCommand_Validation_Failures_2()
        {
            // Arrange
            var mediator = GetService <IMediator>();
            var uow      = GetService <IAmiUnitOfWork>();
            var ct       = new CancellationToken();
            var result   = Create(mediator, ct);
            var entity   = uow.WebhookRepository.GetFirstOrDefault(e => e.Id == new Guid(result.Id));
            var command  = new UpdateWebhookCommand()
            {
                Id            = result.Id,
                ApiVersion    = "1.0.0",
                EnabledEvents = new HashSet <string>()
                {
                    "Test"
                },
                Secret = "1234",
                Url    = "http://localhost/webhook"
            };

            // Act & Assert
            var ex = Assert.ThrowsAsync <ValidationException>(() => mediator.Send(command, ct));

            Assert.AreEqual("One or more validation failures have occurred.", ex.Message);
            Assert.IsNotNull(ex.Failures);
            Assert.AreEqual(1, ex.Failures.Count);
            var firstEntry = ex.Failures.FirstOrDefault().Value;

            Assert.AreEqual(1, firstEntry.Length);
            Assert.IsTrue(firstEntry[0].StartsWith("'Enabled Events' must be one of these values: Unknown, TaskCr"));

            uow.WebhookRepository.Remove(entity);
            uow.SaveChanges();
        }
Exemplo n.º 2
0
        public void UpdateWebhookCommand_Validation_Failures_3()
        {
            // Arrange
            var mediator = GetService <IMediator>();
            var uow      = GetService <IAmiUnitOfWork>();
            var ct       = new CancellationToken();
            var result   = Create(mediator, ct);
            var entity   = uow.WebhookRepository.GetFirstOrDefault(e => e.Id == new Guid(result.Id));
            var command  = new UpdateWebhookCommand()
            {
                Id            = result.Id,
                ApiVersion    = "1.0.0",
                EnabledEvents = new HashSet <string>()
                {
                    "Unknown"
                },
                Secret = "1234",
                Url    = "localhost/webhook"
            };

            // Act & Assert
            var ex = Assert.ThrowsAsync <ValidationException>(() => mediator.Send(command, ct));

            Assert.AreEqual("One or more validation failures have occurred.", ex.Message);
            Assert.IsNotNull(ex.Failures);
            Assert.AreEqual(1, ex.Failures.Count);
            var firstEntry = ex.Failures[nameof(command.Url)];

            Assert.AreEqual(1, firstEntry.Length);
            Assert.AreEqual("The specified 'Url' is not valid.", firstEntry[0]);
        }
        public async Task <IActionResult> Update(string id, [FromBody] UpdateWebhookCommand command)
        {
            if (!id.Equals(command.Id))
            {
                throw new AmiException("The specified identifiers do not match.");
            }

            return(Ok(await Mediator.Send(command, CancellationToken)));
        }
Exemplo n.º 4
0
        public void UpdateWebhookCommand_Validation_Failures_1()
        {
            // Arrange
            var mediator = GetService <IMediator>();
            var ct       = new CancellationToken();
            var command  = new UpdateWebhookCommand();

            // Act & Assert
            var ex = Assert.ThrowsAsync <ValidationException>(() => mediator.Send(command, ct));

            Assert.AreEqual("One or more validation failures have occurred.", ex.Message);
            Assert.IsNotNull(ex.Failures);
            Assert.AreEqual(3, ex.Failures.Count);
            var firstEntry = ex.Failures[nameof(command.Url)];

            Assert.AreEqual("'Url' must not be empty.", firstEntry[0]);
            Assert.AreEqual("The specified 'Url' is not valid.", firstEntry[1]);
        }
Exemplo n.º 5
0
        public void UpdateWebhookCommand()
        {
            // Arrange
            var mediator = GetService <IMediator>();
            var uow      = GetService <IAmiUnitOfWork>();
            var ct       = new CancellationToken();
            var result1  = Create(mediator, ct);

            // Act
            var command2 = new UpdateWebhookCommand()
            {
                Id            = result1.Id,
                ApiVersion    = "2.0.0",
                EnabledEvents = new HashSet <string>()
                {
                    "TaskUpdated",
                    "TaskCreated",
                    "TaskDeleted"
                },
                Secret = "4321",
                Url    = "http://localhost/webhook/v2"
            };
            var result2 = mediator.Send(command2, ct).Result;
            var entity  = uow.WebhookRepository.GetFirstOrDefault(e => e.Id == new Guid(result1.Id));

            // Assert
            Assert.IsNotNull(result2);
            Assert.AreEqual(command2.ApiVersion, result2.ApiVersion);
            Assert.AreEqual(3, result2.EnabledEvents.Length);
            Assert.AreEqual("TaskUpdated", result2.EnabledEvents[0]);
            Assert.AreEqual("TaskCreated", result2.EnabledEvents[1]);
            Assert.AreEqual("TaskDeleted", result2.EnabledEvents[2]);
            Assert.AreEqual(command2.Url, result2.Url);

            Assert.IsNotNull(entity);
            Assert.AreEqual("#TaskUpdated#,#TaskCreated#,#TaskDeleted#", entity.EnabledEvents);

            uow.WebhookRepository.Remove(entity);
            uow.SaveChanges();
        }