Пример #1
0
        public GetSingleToggleTagsTests()
        {
            _mediator   = Substitute.For <IMediator>();
            _controller = new ToggleTagsController(_mediator);

            _validLocator   = ToggleLocator.Create("i exist");
            _invalidLocator = ToggleLocator.Create("i dont exist");

            var toggleView = new ToggleView
            {
                ID          = ToggleID.CreateNew(),
                Name        = "toggle-1",
                Description = "the first toggle",
                Tags        = { "first", "dev" }
            };

            var response = new GetToggleResponse
            {
                Toggle = toggleView
            };

            _mediator
            .Send(Arg.Any <GetToggleRequest>())
            .Returns(new GetToggleResponse());
            _mediator
            .Send(Arg.Is <GetToggleRequest>(req => req.Locator == _validLocator))
            .Returns(response);
        }
        public async Task When_the_requested_toggle_doesnt_exist_by_name()
        {
            var toggleName = ToggleID.CreateNew().ToString();

            var result = await _handler.Handle(new GetToggleRequest(ToggleLocator.Create(toggleName)), CancellationToken.None);

            result.Toggle.ShouldBeNull();
        }
Пример #3
0
        public async Task When_fetching_a_single_toggle_by_name()
        {
            var locator  = ToggleLocator.Create("toggle-name");
            var response = (JsonResult)await _controller.Get(locator);

            await _mediator.Received().Send(Arg.Is <GetToggleRequest>(req => req.Locator == locator));

            response.Value.ShouldBeOfType <ToggleView>();
        }
        public async Task When_the_requested_toggle_exists_by_name()
        {
            var toggleName = "name";

            _view.Add(new ToggleView {
                ID = ToggleID.CreateNew(), Name = toggleName, Description = "desc"
            });

            var result = await _handler.Handle(new GetToggleRequest(ToggleLocator.Create(toggleName)), CancellationToken.None);

            result.Toggle.Name.ShouldBe(toggleName);
        }
Пример #5
0
        protected HandlerTest()
        {
            Events = new PendingEventsStore();

            Storage = new InMemoryStorage(Events);
            Storage.RegisterAggregate <ToggleID, Toggle>();
            Storage.RegisterProjection <ToggleView>();

            Toggle  = Toggle.CreateNew(EditorID.Parse("editor"), "name", "desc");
            Locator = ToggleLocator.Create(Toggle.ID);
            Editor  = EditorID.Parse("Editor:" + Guid.NewGuid());
        }
        public async Task When_adding_a_condition()
        {
            var toggle = Toggle.CreateNew(Editor, "Toggle", "original");

            using (var session = Storage.CreateSession())
                await session.Save(toggle);

            _props["type"] = "enabled";

            await Send(new AddToggleConditionRequest(Editor, ToggleLocator.Create(toggle.ID), _props));

            Response
            .Condition
            .ShouldBeOfType <EnabledCondition>();
        }
Пример #7
0
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(ToggleLocator))
            {
                return(Task.CompletedTask);
            }

            var value = bindingContext.ValueProvider.GetValue(bindingContext.FieldName);
            var guid  = Guid.Empty;

            var locator = Guid.TryParse(value.FirstValue, out guid)
                                ? ToggleLocator.Create(ToggleID.Parse(guid))
                                : ToggleLocator.Create(value.FirstValue);

            bindingContext.Result = ModelBindingResult.Success(locator);

            return(Task.CompletedTask);
        }
 private Task <ICollection <string> > ValidateMessage() => _validator.Validate(
     new AddToggleConditionRequest(
         EditorID.Parse("test"),
         ToggleLocator.Create("wat"),
         _props
         ));
Пример #9
0
        protected override async Task <GetToggleRequest> When()
        {
            await CreateToggle();

            return(new GetToggleRequest(ToggleLocator.Create(ToggleID.CreateNew())));
        }
Пример #10
0
 public void When_removing_tags_and_the_toggle_doesnt_exist()
 {
     Should.Throw <AggregateNotFoundException>(async() => await Handler.Handle(
                                                   new RemoveToggleTagRequest(Editor, ToggleLocator.Create(ToggleID.CreateNew()), "wat"), CancellationToken.None)
                                               );
 }