public void Does_support_Sql_In_on_int_collections()
        {
            var ids = new[] { 1, 2, 3 };

            Assert.That(expr().Where(q => Sql.In(q.Id, 1, 2, 3)).WhereExpression,
                Is.EqualTo("WHERE \"Id\" IN (@0,@1,@2)"));

            Assert.That(expr().Where(q => Sql.In(q.Id, ids)).WhereExpression,
                Is.EqualTo("WHERE \"Id\" IN (@0,@1,@2)"));

            Assert.That(expr().Where(q => Sql.In(q.Id, ids.ToList())).WhereExpression,
                Is.EqualTo("WHERE \"Id\" IN (@0,@1,@2)"));

            Assert.That(expr().Where(q => Sql.In(q.Id, ids.ToList().Cast<object>())).WhereExpression,
                Is.EqualTo("WHERE \"Id\" IN (@0,@1,@2)"));
        }
        public void RobotTest()
        {
            var commands = new[]
            {
                "Move 2",
                "Turn right",
                "Move 4",
                "Turn left",
                "Move -5",
                "Turn right",
                "Move 10",
                "Turn left",
                "Move -2",
                "Turn left",
                "Turn left",
                "Move 5",
                "Move -2",
                "Turn right",
                "Move 1",
                "Move 0"
            };

            const int expectedX = 13;
            const int expectedY = -8;

            var grid = new Grid();
            var robot = new Robot(grid);
            commands.ToList().ForEach(robot.Command);

            var actualX = robot.PositionX;
            var actualY = robot.PositionY;

            Assert.AreEqual(expectedX, actualX);
            Assert.AreEqual(expectedY, actualY);
        }
        public void Does_support_Sql_In_on_string_collections()
        {
            var ids = new[] { "A", "B", "C" };

            Assert.That(expr().Where(q => Sql.In(q.FirstName, "A", "B", "C")).WhereExpression,
                Is.EqualTo("WHERE \"FirstName\" IN (@0,@1,@2)"));

            Assert.That(expr().Where(q => Sql.In(q.FirstName, ids)).WhereExpression,
                Is.EqualTo("WHERE \"FirstName\" IN (@0,@1,@2)"));

            Assert.That(expr().Where(q => Sql.In(q.FirstName, ids.ToList())).WhereExpression,
                Is.EqualTo("WHERE \"FirstName\" IN (@0,@1,@2)"));

            Assert.That(expr().Where(q => Sql.In(q.FirstName, ids.ToList().Cast<object>())).WhereExpression,
                Is.EqualTo("WHERE \"FirstName\" IN (@0,@1,@2)"));
        }
示例#4
0
        private void EnableConversations()
        {
            var itemstoEngage = new[] 
            {
                By.CssSelector("#yucs-help_button"), 
                By.CssSelector("#yucs-help_button"), // has to be clicked twice to respond
                By.XPath("//a[@data-mad='options']"),
                By.CssSelector("li[data-name='viewing_email'] a"),
                By.CssSelector("#options-enableConv"),
                By.XPath("//div[contains(@class, 'modal-settings')]//button[contains(text(), 'Save')]")
            };

            Delay();
            itemstoEngage.ToList().ForEach(it => 
            {
                Driver.RepeatFindAndExecuteAction
                (
                    () => Driver.FindElements(it).FirstOrDefault(x => x.IsDisplayed()),

                    el =>
                    {
                        el.Click();
                    },

                    () => Delay(),
                    WebDriverDefaults.NumberOfRetriesForStaleExceptions
                );
            });
        }
        public void SendNotificationEmail()
        {
            var sender = CreateSender();
            var reader = new ArticleReader();
            var articles = new[] { reader.Read(new FileResources().Read("http://t/3530")) };

            sender.Send(articles.ToList());
        }
        public void Absent_elements_should_be_included_in_result()
        {
            var source = new[] { 6, 10, 5, 1 };

            var sortedSource = _sort.Sort(source.ToList()).ToArray();
            var filledSource = _filler.Fill(sortedSource);

            Ass.Equal(new[] { 1, 2, 3, 4, 5, 6, 7 ,8, 9, 10 }, filledSource);
        }
        public void Absent_elements_should_be_displayed_in_result()
        {
            var source = new[] { 6, 10, 5, 1, 12 };

            var sortedSource = _sort.Sort(source.ToList()).ToArray();
            var foundResults = _finder.Find(sortedSource);

            Ass.Equal(new[] { "2-4", "7-9", "11" }, foundResults);
        }
 public void GetRangeTest([Values(0, 1)]int version, [Values(0, 1)]int count)
 {
     var aggregate = new EventAggregate();
     var events = new[] { "a", "b", "c" };
     using (var tran = aggregate.BeginTransaction())
     {
         aggregate.PushMany(-1, events);
         tran.Commit();
     }
     CollectionAssert.AreEqual(events.ToList().GetRange(version, count), aggregate.GetRange(version, count));
 }
示例#9
0
 public void ParseFileTest()
 {
     // arrange 
     var columns = new[] { "Column1", "Column2", "Column3" };
     // act
     var line = CsvUtil.ParseFile("TestData\\parsefile.csv", true).First();
     // assert            
     columns.ToList().ForEach(
         col =>
         {
             Assert.IsTrue(line.Any(l => l.Key == col));
         });
 }
示例#10
0
        private void LoadQuestions()
        {
            var questions = new[]
            {
                new Question
                {
                    QuestionText = "Who didn't engineer the Apple Computer 1?",
                    Statements = new[] {"Bill Gates", "Steve Jobs", "Steve Wozniak", ""},
                    CorrectIndex = 2
                }
            };

            var qd = new QuestionDatabase { Questions = questions.ToList() };
            XML.Serialize(qd, "Data/questions.xml");

            database = XML.Deserialize<QuestionDatabase>("Data/questions.xml");
        }
示例#11
0
    public void TestReactΔ()
    {
      var f = new MapFunction<int, int>(x => x + 1);

      var numbers = new[] {10, 7, 12, 13, 6};

      var value = f[numbers];

      Assert.That(f.React(value, numbers.ToList().ToLog(Δ1.Empty)).Δ, Is.EqualTo(Δ1.Empty));
      Assert.That(f.React(value, numbers.ToList().Mutate(Expressions.Numbers(4).ToIns(), (key, i) => 26)).Δ, Is.EqualTo(Expressions.Numbers(4).ToIns()));
      Assert.That(f.React(value, numbers.ToList().Mutate(Expressions.Numbers(4).ToIns(), (key, i) => 13)).Δ, Is.EqualTo(Expressions.Numbers(4).ToIns()));
      Assert.That(f.React(value, numbers.ToList().Mutate(Expressions.Numbers(5).ToIns(), (key, i) => 26)).Δ, Is.EqualTo(Expressions.Numbers(5).ToIns()));
      Assert.That(f.React(value, numbers.ToList().Mutate(Expressions.Numbers(5).ToIns(), (key, i) => 7)).Δ, Is.EqualTo(Expressions.Numbers(5).ToIns()));
      Assert.That(f.React(value, numbers.ToList().Mutate(Expressions.Numbers(1).ToDel(), (key, i) => 26)).Δ, Is.EqualTo(Expressions.Numbers(1).ToDel()));
      Assert.That(f.React(value, numbers.ToList().Mutate(Expressions.Numbers(3).ToDel(), (key, i) => 26)).Δ, Is.EqualTo(Expressions.Numbers(3).ToDel()));
    }
        public void TestWithOneSetContainingUniverse()
        {
            var universe = new[] { 1, 2, 3, 4, 5 };
            var sets = new[]
            {
                new[] { 1, 2, 3, 4, 5 },
                new[] { 2, 3, 4, 5 },
                new[] { 5 },
                new[] { 3 }
            };

            var selectedSets = SetCover.ChooseSets(sets.ToList(), universe.ToList());

            var expectedResult = new[]
            {
                sets[0]
            };

            CollectionAssert.AreEqual(expectedResult, selectedSets);
        }
        public void TestWithAllSetsNeeded()
        {
            var universe = new[] { 1, 2, 3, 4, 5 };
            var sets = new[]
            {
                new[] { 1, 3, 5 },
                new[] { 1, 2 },
                new[] { 3, 4 }
            };

            var selectedSets = SetCover.ChooseSets(sets.ToList(), universe.ToList());

            var expectedResult = new[]
            {
                sets[0],
                sets[1],
                sets[2]
            };

            CollectionAssert.AreEqual(expectedResult, selectedSets);
        }
        public void TestWithNoRedundantElements()
        {
            var universe = new[] { 1, 2, 3, 4, 5 };
            var sets = new[]
            {
                new[] { 1 },
                new[] { 2, 4 },
                new[] { 5 },
                new[] { 3 }
            };

            var selectedSets = SetCover.ChooseSets(sets.ToList(), universe.ToList());

            var expectedResult = new[]
            {
                sets[1],
                sets[0],
                sets[2],
                sets[3]
            };

            CollectionAssert.AreEqual(expectedResult, selectedSets);
        }
        public void TestWithSeveralRedundantSets()
        {
            var universe = new[] { 1, 2, 3, 4, 5, 6 };
            var sets = new[]
            {
                new[] { 1, 2, 5 },
                new[] { 2, 3, 5 },
                new[] { 3, 4, 5 },
                new[] { 4, 5 },
                new[] { 1, 3, 4, 6 }
            };

            var selectedSets = SetCover.ChooseSets(sets.ToList(), universe.ToList());

            var expectedResult = new[]
            {
                sets[4],
                sets[0]
            };

            CollectionAssert.AreEqual(expectedResult, selectedSets);
        }
        /// <summary>
        /// Registers the modules type bindings
        /// </summary>
        /// <param name="builder">
        /// The builder.
        /// </param>
        protected override void Load(ContainerBuilder builder)
        {
            // Logging
            #if DEBUG
            var logger = new TraceLogger(this.logCategoryName, this.logCategoryName, true);     // Logger with debug output
            builder.RegisterInstance<ILogger>(logger);
            #else
            var logger = new TraceLogger(this.logCategoryName, this.logCategoryName, false);    // Logger without debug output
            builder.RegisterInstance<ILogger>(logger);
            #endif

            // Binding
            builder.RegisterType<EntitySchemaFactory>().Named<IEntitySchemaFactory>("decorated");
            builder.RegisterDecorator<IEntitySchemaFactory>((c, inner) => new CachedEntitySchemaFactory(inner, c.Resolve<ILogger>()), fromKey: "decorated");
            builder.RegisterType<SharePointEntityBinder>().As<ISharePointEntityBinder>().InstancePerSite();  // Singleton-per-site entity binder

            builder.RegisterType<FieldValueWriter>().As<IFieldValueWriter>();
            var writers = new[]
            {
                typeof(StringValueWriter),
                typeof(BooleanValueWriter),
                typeof(IntegerValueWriter),
                typeof(DoubleValueWriter),
                typeof(DateTimeValueWriter),
                typeof(GuidValueWriter),
                typeof(TaxonomyValueWriter),
                typeof(TaxonomyValueCollectionWriter),
                typeof(LookupValueWriter),
                typeof(LookupValueCollectionWriter),
                typeof(PrincipalValueWriter),
                typeof(UserValueWriter),
                typeof(UserValueCollectionWriter),
                typeof(UrlValueWriter),
                typeof(ImageValueWriter),
                typeof(MediaValueWriter)
            };
            writers.ToList().ForEach(w => builder.RegisterType(w).As<IBaseValueWriter>().SingleInstance());

            builder.RegisterType<FieldValueReader>().As<IFieldValueReader>();
            var readers = new[]
            {
                typeof(StringValueReader),
                typeof(BooleanValueReader),
                typeof(IntegerValueReader),
                typeof(DoubleValueReader),
                typeof(DateTimeValueReader),
                typeof(GuidValueReader),
                typeof(TaxonomyValueReader),
                typeof(TaxonomyValueCollectionReader),
                typeof(LookupValueReader),
                typeof(LookupValueCollectionReader),
                typeof(PrincipalValueReader),
                typeof(UserValueReader),
                typeof(UserValueCollectionReader),
                typeof(UrlValueReader),
                typeof(ImageValueReader),
                typeof(MediaValueReader)
            };
            readers.ToList().ForEach(r => builder.RegisterType(r).As<IBaseValueReader>().SingleInstance());

            // Branding
            builder.RegisterType<MasterPageHelper>().As<IMasterPageHelper>();
            builder.RegisterType<ExtraMasterPageBodyCssClasses>().As<IExtraMasterPageBodyCssClasses>();
            builder.RegisterType<ComposedLookRepository>().As<IComposedLookRepository>();
            builder.RegisterType<DisplayTemplateHelper>().As<IDisplayTemplateHelper>();
            builder.RegisterType<ImageRenditionHelper>().As<IImageRenditionHelper>();

            // Cache
            builder.RegisterType<CacheHelper>().As<ICacheHelper>();

            // CAML query builder and utilities
            builder.RegisterType<CamlBuilder>().As<ICamlBuilder>();
            builder.RegisterType<CamlUtils>().As<ICamlUtils>();
            builder.RegisterType<QueryHelper>().As<IQueryHelper>();

            // Catalogs
            builder.RegisterType<CatalogHelper>().As<ICatalogHelper>();

            // Configuration
            builder.RegisterType<PropertyBagHelper>().As<IPropertyBagHelper>();
            builder.RegisterType<PropertyBagConfiguration>().As<IConfiguration>();
            builder.RegisterType<WebConfigModificationHelper>().As<IWebConfigModificationHelper>();

            // ContentTypes
            builder.RegisterType<ContentTypeHelper>().As<IContentTypeHelper>();

            // Documents
            builder.RegisterType<ContentOrganizerHelper>().As<IContentOrganizerHelper>();

            // Events
            builder.RegisterType<EventReceiverHelper>().As<IEventReceiverHelper>();

            // Fields
            builder.RegisterType<FieldHelper>().As<IFieldHelper>();
            builder.RegisterType<FieldLocator>().As<IFieldLocator>();
            builder.RegisterType<FieldSchemaHelper>().As<IFieldSchemaHelper>();
            builder.RegisterType<FieldLookupHelper>().As<IFieldLookupHelper>();

            // Folders
            builder.RegisterType<FolderHelper>().As<IFolderHelper>();

            // Files
            builder.RegisterType<FileHelper>().As<IFileHelper>();

            // Globalization + Variations (with default en-CA as source + fr-CA as destination implementation)
            builder.RegisterType<ResourceLocator>().As<IResourceLocator>();

            // It's the container user's responsibility to register a IResourceLocatorConfig implementation
            builder.RegisterType<DefaultResourceLocatorConfig>().As<IResourceLocatorConfig>();
            builder.RegisterType<MuiHelper>().As<IMuiHelper>();

            builder.RegisterType<VariationExpert>().As<IVariationExpert>();
            builder.RegisterType<VariationHelper>().As<IVariationHelper>();
            builder.RegisterType<VariationSyncHelper>().As<IVariationSyncHelper>();

            // Lists
            builder.RegisterType<ListHelper>().As<IListHelper>();
            builder.RegisterType<ListLocator>().As<IListLocator>();
            builder.RegisterType<ListSecurityHelper>().As<IListSecurityHelper>();
            builder.RegisterType<PublishedLinksEditor>().As<IPublishedLinksEditor>();

            // Monitoring
            builder.RegisterType<AggregateTimeTracker>().As<IAggregateTimeTracker>().InstancePerSite();

            // Navigation
            builder.RegisterType<NavigationService>().As<INavigationService>();
            builder.RegisterType<NavigationHelper>().As<INavigationHelper>();
            builder.RegisterType<VariationNavigationHelper>().As<IVariationNavigationHelper>();

            // Pages
            builder.RegisterType<PageHelper>().As<IPageHelper>();

            // Repositories
            builder.RegisterType<ItemLocator>().As<IItemLocator>();

            // Search
            builder.RegisterType<SearchHelper>().As<ISearchHelper>();
            builder.RegisterType<QueryRuleHelper>().As<IQueryRuleHelper>();

            // Security
            builder.RegisterType<SecurityHelper>().As<ISecurityHelper>();
            builder.RegisterType<UserHelper>().As<IUserHelper>();

            // Serializers
            builder.RegisterType<XmlHelper>().As<IXmlHelper>();
            builder.RegisterType<JsonNetSerializer>().As<ISerializer>().SingleInstance();

            // Taxonomy
            builder.RegisterType<PerRequestSiteTaxonomyCacheManager>().As<ISiteTaxonomyCacheManager>();
            builder.RegisterType<TaxonomyService>().As<ITaxonomyService>();

            //// Example of monitored (profiled) instance - a typical decorator pattern use case:
            ////builder.RegisterType<TaxonomyService>().Named<ITaxonomyService>("decorated").InstancePerSite();
            ////builder.RegisterDecorator<ITaxonomyService>((c, inner) => new MonitoredTaxonomyService(inner, c.Resolve<IAggregateTimeTracker>()), fromKey: "decorated");

            builder.RegisterType<TaxonomyHelper>().As<ITaxonomyHelper>();

            // Timer Jobs
            builder.RegisterType<TimerJobHelper>().As<ITimerJobHelper>();

            // Utils
            builder.RegisterType<CustomActionHelper>().As<ICustomActionHelper>();
            builder.RegisterType<CatchallExceptionHandler>().As<ICatchallExceptionHandler>();

            // Web Parts
            builder.RegisterType<WebPartHelper>().As<IWebPartHelper>();

            // Features
            builder.RegisterType<FeatureDependencyActivator>().As<IFeatureDependencyActivator>();
        }
        public void TestWithProvidedExample()
        {
            var universe = new[] { 1, 3, 5, 7, 9, 11, 20, 30, 40 };
            var sets = new[]
            {
                new[] { 20 },
                new[] { 1, 5, 20, 30 },
                new[] { 3, 7, 20, 30, 40 },
                new[] { 9, 30 },
                new[] { 11, 20, 30, 40 },
                new[] { 3, 7, 40 }
            };

            var selectedSets = SetCover.ChooseSets(sets.ToList(), universe.ToList());

            var expectedResult = new[]
            {
                sets[2],
                sets[1],
                sets[3],
                sets[4]
            };

            CollectionAssert.AreEqual(expectedResult, selectedSets);
        }
示例#18
0
		private bool ParseWaitFlag(string waitFlag)
		{
			var validFlags = new[] {"0", "no", "false", "1", "yes", "true"};
			if (!validFlags.Contains(waitFlag))
			{
				Error = ArgsError.InvalidWaitFlag;
				return false;
			}

			WaitForTermination = validFlags.ToList().FindIndex(x => x == waitFlag) > 2;

			return true;
		}
 public void GetByIntIds()
 {
     var googleFounderIds = new[] { 2, 3 };
     var customers = provider.GetByIds<Customer>(googleFounderIds);
     Assert.That(customers.ToList().ConvertAll(x => x.Id), Is.EquivalentTo(googleFounderIds.ToList().ConvertAll(x => (long)x)));
 }