Пример #1
0
 public DummyModel(IModelThreads threads = null, Settings.IGlobalSettingsAccessor settings = null)
 {
     this.threads               = threads ?? new ModelThreads();
     this.dummySource           = new DummySource();
     this.hlFilters             = new FiltersList(FilterAction.Exclude, FiltersListPurpose.Highlighting);
     hlFilters.FilteringEnabled = false;
 }
Пример #2
0
        public void ExecuteAsync()
        {
            foreach (var item in TestCases())
            {
                var filter = new DerivedSequenceFilter(item.shortCircuiting);
                var source = new DummySource[] {
                    new DummySource(),
                    new DummySource(),
                };
                var context     = new DummyContext();
                var invokedNext = false;
                SequenceFilterFunc <DummySource> next = _ => {
                    invokedNext = true;
                    return(Task.FromResult(_));
                };

                new TestCaseRunner($"No.{item.testNumber}")
                .Run(() => filter.ExecuteAsync(source, context, next))
                .Verify((actual, desc) => {
                    Assert.AreEqual(source, actual, $"{desc}: 入力シーケンスが出力に素通しされていません。");
                    Assert.AreEqual(context, filter.ActualContext, $"{desc}: フィルター時のコンテキストが同一インスタンスではありません。");
                    Assert.AreEqual(item.shortCircuiting, !invokedNext, $"{desc}: ショートサーキットの有無が期待値と一致しません。");
                }, (Type)null);
            }

            (int testNumber, bool shortCircuiting)[] TestCases() => new[] {
Пример #3
0
        public void Build()
        {
            var pipeline    = new PipelineBuilder <DummySource, DummyContext>();
            var factoryLogs = new List <int?>();
            var filterLogs  = new List <int?>();

            {
                Func <SequenceFilterFunc <DummySource, DummyContext>, SequenceFilterFunc <DummySource, DummyContext> > FilterFactory(int id)
                {
                    return(next => {
                        factoryLogs.Add(id);
                        return (source, context) => {
                            filterLogs.Add(id);
                            return next(source, context);
                        };
                    });
                }

                pipeline.Add(FilterFactory(0));
                pipeline.Add(FilterFactory(1));
                pipeline.Add(FilterFactory(2));
            }

            new TestCaseRunner()
            .Run(() => pipeline.Build())
            .Verify((actual, _) => {
                var source       = new DummySource[] { new DummySource(), new DummySource() };
                var context      = new DummyContext();
                var actualSource = actual(source, context).GetAwaiter().GetResult();

                CollectionAssert.AreEqual(new int[] { 2, 1, 0 }, factoryLogs, "フィルターファクトリーの呼び出し順序が一致しません。");
                CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, filterLogs, "フィルターの適用順序が一致しません。");
                Assert.AreEqual(source, actualSource, "入力シーケンスが出力に素通しされていません。");
            }, (Type)null);
        }
            public void Should_map_null_enum_to_nullable_base_type()
            {
                DummySource src = new DummySource() { Dummy = null };

                var destination = Mapper.Map<DummySource, DummyDestination>(src);

                destination.Dummy.ShouldBeNull();
            }
Пример #5
0
 public void SetMessages(IEnumerable <IMessage> msgs)
 {
     dummySource = new DummySource();
     foreach (var m in msgs)
     {
         dummySource.messages.Add(m);
     }
     OnSourcesChanged?.Invoke(this, EventArgs.Empty);
 }
        public void Should_map_enum_to_nullable()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap<DummySource, DummyDestination>());
            config.AssertConfigurationIsValid();
            DummySource src = new DummySource() { Dummy = DummyTypes.Bar };

            var destination = config.CreateMapper().Map<DummySource, DummyDestination>(src);

            destination.Dummy.ShouldEqual((int)DummyTypes.Bar);
        }
        public void Should_map_enum_to_nullable()
        {
            Mapper.CreateMap<DummySource, DummyDestination>();
            Mapper.AssertConfigurationIsValid();
            DummySource src = new DummySource() { Dummy = DummyTypes.Bar };

            var destination = Mapper.Map<DummySource, DummyDestination>(src);

            destination.Dummy.ShouldEqual((int)DummyTypes.Bar);
        }
Пример #8
0
            public void Should_map_null_enum_to_nullable_base_type()
            {
                DummySource src = new DummySource()
                {
                    Dummy = null
                };

                var destination = Mapper.Map <DummySource, DummyDestination>(src);

                Assert.IsNull(destination.Dummy);
            }
Пример #9
0
            public void Should_map_null_enum_to_nullable_base_type()
            {
                var src = new DummySource()
                {
                    Dummy = null
                };

                var destination = Mapper.Map <DummySource, DummyDestination>(src);

                destination.Dummy.ShouldBeNull();
            }
Пример #10
0
    public void WillThisWork()
    {
        var source = new DummySource[0];
        var values = from value in source
                     select new DummyInterfaceImplementor()
        {
            A = value.A,
            B = value.C + "_" + value.D
        };

        DoSomethingWithDummyInterface(values.Cast <IDummyInterface>());
    }
Пример #11
0
        public bool AutoCompleteSearch(object value1, object value2)
        {
            var string1 = value1.ToString().ToLower();
            var string2 = value2.ToString().ToLower();

            if (string1.Length > 0 && string2.Length > 0)
            {
                if (string1[0] != string2[0])
                {
                    return(false);
                }
            }
            var originalString1 = string.Empty;
            var originalString2 = string.Empty;

            if (string1.Length < string2.Length)
            {
                originalString2 = string2.Remove(string1.Length);
                originalString1 = string1;
            }

            if (string2.Length < string1.Length)
            {
                return(false);
            }
            if (string2.Length == string1.Length)
            {
                originalString1 = string1;
                originalString2 = string2;
            }

            bool IsMatchSoundex = helper.ProcessOnSoundexAlgorithmn(originalString1) == helper.ProcessOnSoundexAlgorithmn(originalString2);
            int  Distance       = helper.GetDamerauLevenshteinDistance(originalString1, originalString2);

            if (IsMatchSoundex || Distance <= 4)
            {
                var searchData = new SearchData()
                {
                    Item = value2.ToString(), Distance = Distance
                };
                if (!stringDummySource.Contains(value2.ToString()))
                {
                    DummySource.Add(searchData);
                    stringDummySource.Add(value2.ToString());
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void Should_map_enum_to_nullable()
        {
            Mapper.CreateMap <DummySource, DummyDestination>();
            Mapper.AssertConfigurationIsValid();
            var src = new DummySource()
            {
                Dummy = DummyTypes.Bar
            };

            var destination = Mapper.Map <DummySource, DummyDestination>(src);

            destination.Dummy.ShouldBe((int)DummyTypes.Bar);
        }
Пример #13
0
        public void Should_map_enum_to_nullable()
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <DummySource, DummyDestination>());

            config.AssertConfigurationIsValid();
            DummySource src = new DummySource()
            {
                Dummy = DummyTypes.Bar
            };

            var destination = config.CreateMapper().Map <DummySource, DummyDestination>(src);

            destination.Dummy.ShouldBe((int)DummyTypes.Bar);
        }
        public void Should_project_icollection_to_aggregate_sum_destination()
        {
            // arrange
            var config = new MapperConfiguration(cfg => cfg.CreateProjection <DummySource, DummyDestination>());
            var source = new DummySource()
            {
                DummyCollection = new[] { 1, 4, 5 }
            };

            // act
            var destination = new[] { source }.AsQueryable()
            .ProjectTo <DummyDestination>(config)
            .Single();

            // assert
            destination.DummyCollectionSum.ShouldBe(10);
        }
        public void Add_IFilter()
        {
            var pipeline = new PipelineBuilder <DummySource, DummyContext>();
            var filter   = new SpySequenceFilter();

            new TestCaseRunner()
            .Run(() => PipelineBuilderExtensions.Add(pipeline, filter))
            .Verify((actual, _) => {
                var source       = new DummySource[] { new DummySource(), new DummySource() };
                var context      = new DummyContext();
                var actualSource = actual.Build()(source, context).GetAwaiter().GetResult();

                Assert.AreEqual(pipeline, actual, "戻り値の PipelineBuilder が同一インスタンスではありません。");
                Assert.IsTrue(filter.Invoked, "フィルターが呼ばれていません。");
                Assert.AreEqual(context, filter.ActualContext, "フィルター時のコンテキストが同一インスタンスではありません。");
                Assert.AreEqual(source, actualSource, "入力シーケンスが出力に素通しされていません。");
            }, (Type)null);
        }
Пример #16
0
        public void Should_project_string_to_nullable_enum()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <string, DummyTypes?>().ConvertUsing(s => (DummyTypes)System.Enum.Parse(typeof(DummyTypes), s));
                cfg.CreateMap <DummySource, DummyDestination>();
            });

            config.AssertConfigurationIsValid();

            var src = new DummySource[] { new DummySource {
                                              Dummy = "Foo"
                                          } };

            var destination = src.AsQueryable().ProjectTo <DummyDestination>(config).First();

            destination.Dummy.ShouldBe(DummyTypes.Foo);
        }
        public void Should_project_ienumerable_to_aggregate_destinations()
        {
            // arrange
            var config = new MapperConfiguration(cfg => cfg.CreateProjection <DummySource, DummyDestination>());
            var source = new DummySource()
            {
                DummyEnumerable = new[] { 1, 4, 5 }
            };

            // act
            var destination = new[] { source }.AsQueryable()
            .ProjectTo <DummyDestination>(config)
            .Single();

            // assert
            destination.DummyEnumerableCount.ShouldBe(3);
            destination.DummyEnumerableSum.ShouldBe(10);
            destination.DummyEnumerableMin.ShouldBe(1);
            destination.DummyEnumerableMax.ShouldBe(5);
        }
Пример #18
0
        public void CreateFilter()
        {
            var filterLogs = new List <int?>();
            var filters    = new ISequenceFilter <DummySource, DummyContext>[] {
                new SpySequenceFilter(() => filterLogs.Add(0)),
                new SpySequenceFilter(() => filterLogs.Add(1)),
                new SpySequenceFilter(() => filterLogs.Add(2)),
            };

            new TestCaseRunner()
            .Run(() => Pipeline.CreateFilter(filters))
            .Verify((actual, _) => {
                var source       = new DummySource[] { new DummySource(), new DummySource() };
                var context      = new DummyContext();
                var actualSource = actual(source, context).GetAwaiter().GetResult();

                CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, filterLogs, "フィルターの適用順序が一致しません。");
                Assert.AreEqual(source, actualSource, "入力シーケンスが出力に素通しされていません。");
            }, (Type)null);
        }
Пример #19
0
 public DummyModel()
 {
     this.dummySource = new DummySource();
 }
        public bool AutoCompleteSearch(object value1, object value2)
        {
            var string1 = value1.ToString().ToLower();
            var string2 = value2.ToString().ToLower();

            if (string1.Length > 0 && string2.Length > 0)
            {
                if (string1[0] != string2[0])
                {
                    return(false);
                }
            }
            var originalString1 = string.Empty;
            var originalString2 = string.Empty;

            if (string1.Length < string2.Length)
            {
                originalString2 = string2.Remove(string1.Length);
                originalString1 = string1;
            }

            if (string2.Length < string1.Length)
            {
                return(false);
            }
            if (string2.Length == string1.Length)
            {
                originalString1 = string1;
                originalString2 = string2;
            }

            bool IsMatchSoundex = helper.ProcessOnSoundexAlgorithmn(originalString1) == helper.ProcessOnSoundexAlgorithmn(originalString2);
            int  Distance       = helper.GetDamerauLevenshteinDistance(originalString1, originalString2);

            if (IsMatchSoundex || Distance <= 4)
            {
                var searchData = new SearchData()
                {
                    Item = value2.ToString(), Distance = Distance
                };
                if (!stringDummySource.Contains(value2.ToString()))
                {
                    DummySource.Add(searchData);
                    stringDummySource.Add(value2.ToString());
                }
                return(true);
            }
            else
            {
                return(false);
            }

            int matchValue = 0;

            var allWords = value2.ToString().ToLower().Split(' ');
            var keys     = value1.ToString().ToLower().Split(' ');

            foreach (var item in allWords)
            {
                foreach (var key in keys)
                {
                    var itemValue = item;
                    if (item.Length > key.Length)
                    {
                        itemValue = item.Remove(key.Length);
                    }
                    if (key == "" || item == "")
                    {
                        continue;
                    }
                    if ((helper.ProcessOnSoundexAlgorithmn(key) == helper.ProcessOnSoundexAlgorithmn(itemValue)))
                    {
                        matchValue++;
                    }
                    if ((helper.ProcessOnSoundexAlgorithmn(key) == helper.ProcessOnSoundexAlgorithmn(item)))
                    {
                        matchValue++;
                    }
                }
            }

            int keysCount = 0;

            if (matchValue >= keysCount)
            {
                return(true);
            }
            return(false);
        }