public void GetPersonsReturnsAllFromRepository()
        {
            List<Person> persons = new List<Person>();
            persons.Add(new Person("a", 1, "a"));
            persons.Add(new Person("b", 2, "b"));

            var repositoryMock = new Mock<PersonRepository>();
            repositoryMock.Setup<IEnumerable<Person>>(x => x.GetAll()).Returns(persons.AsEnumerable());

            var facade = new PersonFacade(repositoryMock.Object, null);

            Assert.AreEqual(persons.AsEnumerable(), facade.GetPersons());
        }
        public void Enumerable_FirstOne_Should_Return_First_Item()
        {
            var list = new List<string> { "First", "Second", "Third" };
            var first = list.AsEnumerable().FirstOne();

            Assert.AreEqual(first, "First");
        }
예제 #3
0
        public void AutoFilterExpandsWithTable()
        {
            using (var wb = new XLWorkbook())
            {
                using (IXLWorksheet ws = wb.Worksheets.Add("Sheet1"))
                {
                    ws.FirstCell().SetValue("Categories")
                        .CellBelow().SetValue("1")
                        .CellBelow().SetValue("2");

                    IXLTable table = ws.RangeUsed().CreateTable();

                    var listOfArr = new List<Int32>();
                    listOfArr.Add(3);
                    listOfArr.Add(4);
                    listOfArr.Add(5);
                    listOfArr.Add(6);

                    table.DataRange.InsertRowsBelow(listOfArr.Count - table.DataRange.RowCount());
                    table.DataRange.FirstCell().InsertData(listOfArr.AsEnumerable());

                    Assert.AreEqual("A1:A5", table.AutoFilter.Range.RangeAddress.ToStringRelative());
                }
            }
        }
예제 #4
0
        public void PagedList_BuildPagingLastPage_Valid()
        {
            const int page = 3;
            const int pageSize = 1;
            const int shownEitherSide = 1;
            const string url = "url";

            List<string> source = new List<string> { "one", "two", "three" };

            var pagedList = new PagedList<string>(source.AsEnumerable(), page, pageSize);

            var actual = pagedList.BuildPagingLinks(shownEitherSide, url);

            const string expected = "<div class=\"pagination\">" +
                                        "<span class=\"page\"></span>" +
                                        "<ul>" +
                                            "<li><a href=\"url?page=1\">First</a></li>" +
                                            "<li><a href=\"url?page=2\">Prev</a></li>" +
                                            "<li><a href=\"url?page=1\">... </a></li>" +
                                            "<li><a href=\"url?page=2\">2</a></li>" +
                                            "<li class=\"current\"><a href=\"url?page=3\">3</a></li>" +
                                            "<li><a href=\"url?page=3\">Next</a></li>" +
                                            "<li><a href=\"url?page=3\">Last</a></li>" +
                                        "</ul>" +
                                    "</div>";

            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        public void TestCSharpInputDStream()
        {
            // test create CSharpInputDStream
            var sc = new SparkContext("", "");
            var ssc = new StreamingContext(sc, 1000L);
            Func<double, int, IEnumerable<string>> func =
                (double time, int pid) =>
                {
                    var list = new List<string>() { string.Format("PluggableInputDStream-{0}-{1}", pid, time) };
                    return list.AsEnumerable();
                };
            const int numPartitions = 5;
            var inputDStream = CSharpInputDStreamUtils.CreateStream<string>(
                ssc,
                numPartitions,
                func);
            Assert.IsNotNull(inputDStream);
            Assert.AreEqual(ssc, inputDStream.streamingContext);

            // test CSharpInputDStreamMapPartitionWithIndexHelper
            int[] array = new int[numPartitions];
            int partitionIndex = 0;
            new CSharpInputDStreamMapPartitionWithIndexHelper<string>(0.0, func).Execute(partitionIndex, array.AsEnumerable());

            // test CSharpInputDStreamGenerateRDDHelper
            new CSharpInputDStreamGenerateRDDHelper<string>(numPartitions, func).Execute(0.0);
        }
        protected virtual IEnumerable<Claim> GetApplicationSpecificClaims()
        {
            var result = new List<Claim>();

            if( IncludeTargetedUserLEAIds())
                result.Add(new Claim(EdFiClaimTypes._OrgClaimNamespace, string.Format(localEducationAgencyIdClaimJsonFormatString, administerLeaId, administerLeaName)));

            return result.AsEnumerable();
        }
        public void ConstructorGivenAnEnumerableCopiesIt()
        {
            var list = new List<int> { 1, 2, 3 };
            var observableList = new ObservableList<int>(list.AsEnumerable()) { 4 };
            list.Remove(1);

            Assert.AreEqual(4, observableList.Count);
            Assert.AreEqual(2, list.Count);
        }
        public void ForEach_WithCollectionOfOneItem_ShouldIterateOneTime()
        {
            var collection = new List<int> { 1 };
            var iterations = 0;

            collection.AsEnumerable().ForEach(num => iterations++);

            Assert.That(iterations, Is.EqualTo(1));
        }
예제 #9
0
        public void Double_NaN_is_a_string()
        {
            IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
            IXLCell cell = ws.Cell("A1");
            var doubleList = new List<Double> {0.0/0.0};

            cell.Value = doubleList.AsEnumerable();
            Assert.AreNotEqual(XLCellValues.Number, cell.DataType);
        }
예제 #10
0
        public void ForEach_WithEmptyCollection_ShouldIterateZeroTimes()
        {
            var collection = new List<int>();
            var iterations = 0;

            collection.AsEnumerable().ForEach(num => iterations++);

            Assert.That(iterations, Is.EqualTo(0));
        }
예제 #11
0
        public void ForEach_WithCollectionOfTenItems_ShouldIterateTenTimes()
        {
            var collection = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var iterations = 0;

            collection.AsEnumerable().ForEach(num => iterations++);

            Assert.That(iterations, Is.EqualTo(10));
        }
예제 #12
0
        public async Task GetAllComponentReturnsAllItems_Test()
        {
            var createdComponents = new List<Component> {CreateComponent(), CreateComponent(), CreateComponent()};

            _storageMock.Setup(x => x.GetItems()).Returns(() => Task.FromResult(createdComponents.AsEnumerable()));

            var components = await _model.GetAllComponentsAsync();
            _storageMock.Verify(x => x.GetItems(), Times.Exactly(1));
            Assert.AreEqual(createdComponents, components);
        }
예제 #13
0
 public IEnumerable<Report> ReportListGenerator()
 {
     int iCount = 5;
     var x = new List<Report>();
     while (iCount > 0)
     {
         x.Insert(0, new Report() { ID = iCount, Name = "Report #" + iCount });
         iCount--;
     }
     return x.AsEnumerable();
 }
        protected virtual IEnumerable<Claim> GetImpersonatorClaims()
        {
            var result = new List<Claim>();

            if( IncludeAdministerStateId())
                result.Add(new Claim(EdFiClaimTypes.AdministerDashboard, string.Format(stateAgencyClaimJsonFormatString, administerStateId, administerStateName)));

            if (IncludeAdministerLeaID())
                result.Add(new Claim(EdFiClaimTypes.AdministerDashboard, string.Format(localEducationAgencyIdClaimJsonFormatString, administerLeaId, administerLeaName)));

            return result.AsEnumerable();
        }
		PackageItemListViewModel CreatePackageItemListViewModel ()
		{
			packageVersions = new List<VersionInfo> ();
			packageItemListViewModel = new PackageItemListViewModel {
				Id = "TestPackage",
				Version = new NuGetVersion ("1.2.3"),
				Versions = AsyncLazy.New (() => {
					return Task.FromResult (packageVersions.AsEnumerable ());
				})
			};
			return packageItemListViewModel;
		}
        public void ShouldNotCreateErrorMessageForCorrectFacultyName()
        {
            var departaments = new List<Departament>();
            var d = new Departament {Name = "Department"};
            departaments.Add(d);
            _newFaculty.FacultyName = "Kierunek";
            _newFaculty.Departaments = departaments.AsEnumerable();
            bool result = _newFaculty.IsValid;

            Assert.IsNotNull(_newFaculty);
            Assert.IsTrue(result);
            Assert.IsNull(_newFaculty.Errors);
        }
        public void SetUp()
        {
            _persons = new List<Person>();
            _persons.Add(new Person() { Id = 1, Name = "FirstUser" });
            _persons.Add(new Person() { Id = 2, Name = "AnotherUser" });
            _persons.Add(new Person() { Id = 3, Name = "ThirdUser" });

            var repository = new Mock<IPersonRepository>();
            repository.Setup(x => x.GetAll()).Returns(_persons.AsEnumerable());
            var builder = new Mock<IPersonDtoBuilder>();
            builder.Setup(x => x.BuildDto(It.IsAny<Person>())).Returns((Person p) => new PersonDto() { Name = p.Name });
            _facade = new PersonFacade(repository.Object, builder.Object);
        }
        public void PersonModelGetsDataFromFacadeOnGet()
        {
            var facade = new Mock<IPersonFacade>();
            var persons = new List<Person>();
            persons.Add(new Person("Test", 1, "Test"));
            facade.Setup<IEnumerable<Person>>(x => x.GetPersons()).Returns(persons.AsEnumerable());
            var xy = facade.Object;
            HomeController controller = new HomeController(facade.Object);

            var result = controller.Index();
            var viewModel = result.Model as PersonViewModel;

            Assert.AreEqual(persons, viewModel.Result);
        }
예제 #19
0
        public void TestExecute(string command, string commandName, string[] allCommands)
        {   
            var args = new List<Argument>
            {
                new Argument {Name = command, Value = commandName}
            };

            _mockCommandProvider.Setup(m => m.GetAllCommands())
                .Returns(allCommands.Select(com => MockUtils.GetCommandMock(com).Object).ToList());

            var commandExecutor = GetInstance();
            
            commandExecutor.Execute(args.AsEnumerable());

            var firstCommandInList =_mockCommandProvider.Object.GetAllCommands().First(p => p.CommandArgValue == commandName);
            Mock.Get(firstCommandInList).Verify(p => p.Clone());
            Mock.Get(firstCommandInList).Verify(p => p.Execute(It.IsAny<IEnumerable<Argument>>()), Times.Never());
        }
예제 #20
0
        public void CreateInstance_InsideInstance_HasGeometry()
        {
            // Regression test for defect http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-5165
            // To verify when some geometry nodes are converted to custom node,
            // their render packages shouldn't be carried over to custom work
            // space.
            var model = ViewModel.Model;

            OpenVisualizationTest("visualize_line_incustom.dyn");

            Assert.AreEqual(1, BackgroundPreviewGeometry.TotalCurves());

            // Convert a DSFunction node Line.ByPointDirectionLength to custom node.
            var workspace = model.CurrentWorkspace;
            var node = workspace.Nodes.OfType<DSFunction>().First();

            List<NodeModel> selectionSet = new List<NodeModel>() { node };
            var customWorkspace = model.CustomNodeManager.Collapse(
                selectionSet.AsEnumerable(),
                Enumerable.Empty<Dynamo.Graph.Notes.NoteModel>(),
                model.CurrentWorkspace,
                true,
                new FunctionNamePromptEventArgs
                {
                    Category = "Testing",
                    Description = "",
                    Name = "__VisualizationTest__",
                    Success = true
                }) as CustomNodeWorkspaceModel;
            ViewModel.HomeSpace.Run();

            // Switch to custom workspace
            model.OpenCustomNodeWorkspace(customWorkspace.CustomNodeId);
            var customSpace = ViewModel.Model.CurrentWorkspace;

            // Select that node
            DynamoSelection.Instance.Selection.Add(node);

            // No preview in the background
            Assert.AreEqual(1, BackgroundPreviewGeometry.TotalPoints());
            Assert.AreEqual(1, BackgroundPreviewGeometry.TotalCurves());
            Assert.AreEqual(0, BackgroundPreviewGeometry.TotalMeshes());
        }
예제 #21
0
        protected virtual ReadOnlyCollection<String> InputWannabes()
        {
            var unit_test = UnitTest.CurrentTest.AssertNotNull();
            var test_fixture = UnitTest.CurrentFixture.AssertNotNull();

            var fnameWannabes = new List<String>();
            var cs_opt = ToCSharpOptions.Informative;
            cs_opt.EmitCtorNameAsClassName = true;
            var s_name = unit_test.IsConstructor ? unit_test.DeclaringType.GetCSharpRef(cs_opt).Replace("<", "[").Replace(">", "]").Replace("&", "!").Replace("*", "!") : unit_test.Name;
            var s_sig = unit_test.Params().Select(p => p.GetCSharpRef(cs_opt).Replace("<", "[").Replace(">", "]").Replace("&", "!").Replace("*", "!")).StringJoin("_");
            var s_declt = test_fixture.GetCSharpRef(cs_opt).Replace("<", "[").Replace(">", "]").Replace("&", "!").Replace("*", "!");
            fnameWannabes.Add(s_name);
            fnameWannabes.Add(s_name + "_" + s_sig);
            fnameWannabes.Add(s_declt + "_" + s_name);
            fnameWannabes.Add(s_declt + "_" + s_name + "_" + s_sig);
            fnameWannabes.AsEnumerable().ForEach(wb => fnameWannabes.Add(wb + ".in"));

            return fnameWannabes.ToReadOnly();
        }
예제 #22
0
        public void PagedList_HasPreviousPage_True_Valid()
        {
            const int page = 1;
            const int pageSize = 1;

            List<string> source = new List<string> { "one", "two", "three" };

            var pagedList = new PagedList<string>(source.AsEnumerable(), page, pageSize);

            Assert.IsTrue(pagedList.HasPreviousPage);
        }
예제 #23
0
        public void PagedList_HasNextPage_False_Valid()
        {
            const int page = 0;
            const int pageSize = 3;

            List<string> source = new List<string> { "one", "two", "three" };

            var pagedList = new PagedList<string>(source.AsEnumerable(), page, pageSize);

            Assert.IsFalse(pagedList.HasNextPage);
        }
예제 #24
0
        public void PagedList_ForcedTotalEnumerableConstructor_Valid()
        {
            const int page = 1;
            const int pageSize = 1;
            const int totalSize = 10;

            List<string> source = new List<string> { "one", "two", "three" };

            var pagedList = new PagedList<string>(source.AsEnumerable(), page, pageSize, totalSize);

            Assert.IsNotNull(pagedList);
            Assert.AreEqual(totalSize, pagedList.TotalCount);
            Assert.AreEqual(source.Count, pagedList.Count); // Because it adds all items in the source.
            Assert.AreEqual(page, pagedList.PageIndex);
            Assert.AreEqual(pageSize, pagedList.PageSize);
        }
예제 #25
0
        public void PagedList_EnumerableConstructor_ZeroPage_Valid()
        {
            const int page = 0;
            const int pageSize = 1;

            List<string> source = new List<string> { "one", "two", "three" };

            var pagedList = new PagedList<string>(source.AsEnumerable(), page, pageSize);

            Assert.IsNotNull(pagedList);
            Assert.AreEqual(source.Count, pagedList.TotalCount);
            Assert.AreEqual(pageSize, pagedList.Count);
            Assert.AreEqual(page, pagedList.PageIndex);
            Assert.AreEqual(pageSize, pagedList.PageSize);
        }
예제 #26
0
        internal static void DStreamCSharpInputSample()
        {
            const int numPartitions = 5;

            var sc = SparkCLRSamples.SparkContext;
            var ssc = new StreamingContext(sc, 2000L); // batch interval is in milliseconds

            var inputDStream = CSharpInputDStreamUtils.CreateStream<string>(
                ssc,
                numPartitions,
                (double time, int pid) =>
                {
                    var list = new List<string>() { string.Format("PluggableInputDStream-{0}-{1}", pid, time) };
                    return list.AsEnumerable();
                });

            inputDStream.ForeachRDD((time, rdd) =>
            {
                var taken = rdd.Collect();
                int partitions = rdd.GetNumPartitions();

                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Time: {0}", time);
                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Count: " + taken.Length);
                Console.WriteLine("Partitions: " + partitions);

                foreach (object record in taken)
                {
                    Console.WriteLine(record);
                }
            });

            ssc.Start();
            ssc.AwaitTermination();
        }
예제 #27
0
        public void UpdateCourseUsersEmptyEnumerableOfGuid()
        {
            var guids = new List<Guid>();
            this.Storage.UpdateCourseUsers(1, guids.AsEnumerable());

            Assert.AreEqual(0, this.Storage.GetCourseUsers(1).Count()); // Expected: 0 But was: 3
        }
예제 #28
0
        public void UpdateCourseUsersNewCourse()
        {
            var guids = new List<Guid>();

            // valid Guids
            guids.Add(new Guid("55345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            guids.Add(new Guid("66345200-abe8-4f60-90c8-0d43c5f6c0f6"));

            // Invalid Guids
            guids.Add(new Guid("77345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            guids.Add(new Guid("88345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            this.Storage.UpdateCourseUsers(100, guids.AsEnumerable());

            Assert.AreEqual(2, this.Storage.GetCourseUsers(100).Count()); // Expected: 4 But was: 3
        }
예제 #29
0
        public void UpdateCourseUsersEmptyEnumerableOfGuid()
        {
            List<Guid> guids = new List<Guid>();
            _Storage.UpdateCourseUsers(1, guids.AsEnumerable());

            Assert.AreEqual(0, _Storage.GetCourseUsers(1).Count());
        }
예제 #30
0
        public void UpdateCourseUsersNewCourse()
        {
            List<Guid> guids = new List<Guid>();
            //valid Guids
            guids.Add(new Guid("55345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            guids.Add(new Guid("66345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            //Invalid Guids
            guids.Add(new Guid("77345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            guids.Add(new Guid("88345200-abe8-4f60-90c8-0d43c5f6c0f6"));
            _Storage.UpdateCourseUsers(100, guids.AsEnumerable());

            Assert.AreEqual(4, _Storage.GetCourseUsers(1).Count());
        }