public void AndPayloadIsNotProvidedThenValidationFails()
        {
            var command = new CreateGenericEventCommand {
                Type = "ABC"
            };

            Assert.ThrowsAsync <ValidationException>(() => Handler.Handle(command));
        }
        public void AndTypeIsNotProvidedThenValidationFails()
        {
            var command = new CreateGenericEventCommand {
                Payload = "dlfkjgndfgfd"
            };

            Assert.ThrowsAsync <ValidationException>(() => Handler.Handle(command));
        }
        public void AndTheEventCreationFailsThenTheExceptionIsLogged()
        {
            var command = new CreateGenericEventCommand {
                Payload = "dfljihldfkmgfdg", Type = "EventType"
            };
            var expectedException = new Exception("Test");

            Repository.Setup(x => x.Create(It.Is <GenericEvent>(e => e.Payload == command.Payload && e.Type == command.Type))).Throws(expectedException);

            Assert.ThrowsAsync <Exception>(() => Handler.Handle(command));

            EventsLogger.Verify(x => x.Error(expectedException, "Error storing generic event in database", null, null, null), Times.Once);
        }
        public async Task ThenTheEventIsCreated()
        {
            var command = new CreateGenericEventCommand {
                Payload = "dfljihldfkmgfdg", Type = "EventType", ResourceId = "Id", ResourceType = "Type"
            };

            await Handler.Handle(command);

            EventsLogger.Verify(x => x.Info($"Creating Generic Event of type {command.Type}", null, null, null), Times.Once);
            Repository.Verify(
                x =>
                x.Create(
                    It.Is <GenericEvent>(
                        e =>
                        e.Payload == command.Payload && e.Type == command.Type && e.ResourceId == command.ResourceId &&
                        e.ResourceType == command.ResourceType)));
        }