示例#1
0
        public async Task CreatePipeline(Boolean successfullMediatorResult)
        {
            Random random        = new Random();
            String name          = random.GetAlphanumericString();
            String description   = random.GetAlphanumericString();
            String triggerName   = random.GetAlphanumericString();
            String conditionName = random.GetAlphanumericString();
            IDictionary <String, String> conditionProperties = new Dictionary <string, string>();
            String actorName = random.GetAlphanumericString();
            IDictionary <String, String> actorProperties = new Dictionary <string, string>();

            Guid?pipelineId = successfullMediatorResult == true?random.NextGuid() : new Guid?();

            NonStrictDictionaryComparer <String, String> dictionaryComparer = new NonStrictDictionaryComparer <string, string>();

            Mock <IMediator> mediatorMock = new Mock <IMediator>(MockBehavior.Strict);

            mediatorMock.Setup(x => x.Send(It.Is <CreateNotificationPipelineCommand>(y =>
                                                                                     y.Name == name &&
                                                                                     y.Description == description &&
                                                                                     y.TriggerName == triggerName &&
                                                                                     y.CondtionName == conditionName &&
                                                                                     dictionaryComparer.Equals(y.ConditionProperties, conditionProperties) == true &&
                                                                                     y.ActorName == actorName &&
                                                                                     dictionaryComparer.Equals(y.ActorProperties, actorProperties) == true
                                                                                     ), It.IsAny <CancellationToken>())).ReturnsAsync(pipelineId).Verifiable();

            var controller = new NotificationsController(
                Mock.Of <INotificationEngine>(MockBehavior.Strict), mediatorMock.Object,
                Mock.Of <ILogger <NotificationsController> >());

            var actionResult = await controller.CreatePipeline(new CreateNotifcationPipelineRequest
            {
                Name                = name,
                Description         = description,
                TriggerName         = triggerName,
                CondtionName        = conditionName,
                ConditionProperties = conditionProperties,
                ActorName           = actorName,
                ActorProperties     = actorProperties,
            });

            if (successfullMediatorResult == true)
            {
                Guid actual = actionResult.EnsureOkObjectResult <Guid>(true);
                Assert.Equal(pipelineId.Value, actual);
            }
            else
            {
                actionResult.EnsureBadRequestObjectResult("unable to create pipeline");
            }

            mediatorMock.Verify();
        }