예제 #1
0
        public void ItemsAdded()
        {
            var list = new RxList<string>();
            string[] items = null;
            list.ItemsAdded.Subscribe(x => items = x.ToArray());

            list.AddRange(new[] { "1", "2" });
            Assert.AreEqual("1", items[0]);
            Assert.AreEqual("1", list[0]);
            Assert.AreEqual("2", items[1]);
            Assert.AreEqual("2", list[1]);
        }
예제 #2
0
        public ApiModel(MainWindowModel mainWindow, ApiCollectionModel parent, Api api) : base(mainWindow, parent, api)
        {
            Inputs  = new RxList <ApiInputModel>();
            Outputs = new RxList <ApiOutputModel>();
            Headers = new RxList <ApiHeaderModel>();

            SubscribeForInputs(this.ObservePropertyChange(x => x.Model.Url), () => Model.Url, ApiInputType.Url);
            SubscribeForInputs(this.ObservePropertyChange(x => x.Model.Body).Where(x => ContentTypes.IsText(ContentType)), () => Model.Body, ApiInputType.Body);
            SubscribeForInputs(this.ObservePropertyChange(x => x.Headers).SelectMany(x => x.ObserveElementProperty(y => y.Name)).Merge(this.ObservePropertyChange(x => x.Headers).SelectMany(x => x.ObserveElementProperty(y => y.Value))), () => string.Join("\n", Headers.Select(x => x.Name + "=" + x.Value)), ApiInputType.Header);

            Model = api;
            if (api.Inputs != null)
            {
                Inputs.AddRange(api.Inputs.Select(x => new ApiInputModel
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    DefaultValue = x.DefaultValue,
                    InputType    = x.InputType
                }));
            }
            if (api.Outputs != null)
            {
                Outputs.AddRange(api.Outputs.Select(x => new ApiOutputModel
                {
                    Id         = x.Id,
                    Name       = x.Name,
                    Expression = x.Expression,
                    Type       = x.Type
                }));
            }
            if (api.Headers != null)
            {
                Headers.AddRange(api.Headers.Select(x => new ApiHeaderModel
                {
                    Id    = x.Id,
                    Name  = x.Name,
                    Value = x.Value
                }));
            }
            Send  = RxCommand.CreateAsync(OnSend);
            Reset = RxCommand.Create(OnReset);

            Inputs.SetUpSync(
                MainWindow.Repository,
                Model.Inputs,
                x => new ApiInput {
                Name = x.Name, DefaultValue = "", InputType = x.InputType
            });
            Outputs.SetUpSync(
                MainWindow.Repository,
                Model.Outputs,
                x => new ApiOutput {
                Name = x.Name, Expression = ""
            });
            Headers.SetUpSync(
                MainWindow.Repository,
                Model.Headers,
                _ => new ApiHeader {
                Name = "", Value = ""
            });
        }
예제 #3
0
        public void RangeAdded()
        {
            var list = new RxList<string>();
            RxListItem<string>[] items = null;
            list.RangeAdded.Subscribe(x => items = x.ToArray());

            list.AddRange(new[] { "1", "2" });
            Assert.AreEqual(0, items[0].Index);
            Assert.AreEqual("1", items[0].Value);
            Assert.AreEqual("1", list[0]);
            Assert.AreEqual(1, items[1].Index);
            Assert.AreEqual("2", items[1].Value);
            Assert.AreEqual("2", list[1]);
        }