示例#1
0
        public void changing_path_should_clear_filter_and_update_path()
        {
            var rdObj   = new object();
            var dataObj = new object();
            var subject = new FilterState
            {
                Type   = MappingType.Total,
                Params = new Dictionary <string, string> {
                    { "original", "filter-settings" }
                },
                RepeaterData  = rdObj,
                Data          = dataObj,
                RunningTotals = new Dictionary <string, decimal> {
                    { "sample", 100m }
                },
                OriginalPath = new[] { "orig", "path" },
                SourcePath   = new[] { "orig", "path" },
            };

            subject.FilterSet.Add("DifferentFilter", new MappingInfo {
                MappingType       = MappingType.Count,
                DataPath          = new[] { "new", "data" },
                MappingParameters = new Dictionary <string, string> {
                    { "changed", "params" }
                }
            });

            var changed = subject.NewPath(new [] { "different", "path" });

            Assert.That(changed, Is.Not.Null, "re-path failed");

            Assert.That(changed !.Type, Is.EqualTo(MappingType.None), "did not clear type");
            Assert.That(changed.SourcePath?[0], Is.EqualTo("different"), "did not change data path");

            Assert.That(changed.Params["original"], Is.EqualTo("filter-settings"), "did not copy params");
            Assert.That(changed.Data, Is.EqualTo(dataObj), "reference to data was broken");
            Assert.That(changed.RepeaterData, Is.EqualTo(rdObj), "reference to repeater-data was broken");
            Assert.That(changed.OriginalPath?[0], Is.EqualTo("orig"), "original path was not retained");
            Assert.That(changed.RunningTotals?["sample"], Is.EqualTo(100m), "running totals were damaged");
        }