public void TestTemplateOneOf()
 {
     Random random = new Random();
     var document = new SimpleDocument("The letter is {OneOf(\"a\", \"b\", \"c\", \"d\", null)}.");
     var store = new BuiltinStore();
     store["OneOf"] = new NativeFunction((values) =>
     {
         return values[random.Next(values.Count)];
     });
     store["system"] = "Alrai";
     List<string> results = new List<string>();
     for (int i = 0; i < 1000; i++)
     {
         results.Add(document.Render(store));
     }
     Assert.IsTrue(results.Contains(@"The letter is a."));
     results.RemoveAll(result => result == @"The letter is a.");
     Assert.IsTrue(results.Contains(@"The letter is b."));
     results.RemoveAll(result => result == @"The letter is b.");
     Assert.IsTrue(results.Contains(@"The letter is c."));
     results.RemoveAll(result => result == @"The letter is c.");
     Assert.IsTrue(results.Contains(@"The letter is d."));
     results.RemoveAll(result => result == @"The letter is d.");
     Assert.IsTrue(results.Contains(@"The letter is ."));
     results.RemoveAll(result => result == @"The letter is .");
     Assert.IsTrue(results.Count == 0);
 }
 private TrackController GetController()
 {
     var mockRepository = new Mock<ITracksRepository>();
     List<Track> tracks = new List<Track>();
     tracks.Add(new Track { TrackID = 1, Name = "Test", TypeOfTravel = TravelType.Car });
     mockRepository.Setup(r => r.Tracks).Returns(tracks.AsQueryable());
     mockRepository.Setup(r => r.AddTrack(It.IsAny<Track>())).Callback((Track t) => tracks.Add(t));
     mockRepository.Setup(r => r.DeleteTrack(It.IsAny<int>())).Callback((int i) => tracks.RemoveAll(t => t.TrackID == i));
     return new TrackController(mockRepository.Object);
     //return new TrackController(new TracksRepository(@"Server=localhost;Database=TrackStore;Trusted_Connection=yes;"));
 }
        public void Initialize()
        {
            var categoriesRepository = new Mock<ICategoriesRepository>();
            var categories = new List<Category>
            {
                new Category {Id = 1, Name = "Category1"},
                new Category {Id = 2, Name = "Category2", ParentId = 1},
                new Category {Id = 3, Name = "Category3", ParentId = 2},
                new Category {Id = 4, Name = "Category4", ParentId = 1},
                new Category {Id = 5, Name = "Category5"}
            };

            categoriesRepository.Setup(r => r.Get()).ReturnsAsync(categories);
            categoriesRepository.Setup(r => r.Get(It.IsAny<int>())).Returns((int id) => Task.FromResult(categories.FirstOrDefault(c => c.Id == id)));
            categoriesRepository.Setup(r => r.Create(It.IsAny<Category>())).ReturnsAsync(true);
            categoriesRepository.Setup(r => r.Update(It.IsAny<Category>())).ReturnsAsync(true);
            categoriesRepository.Setup(r => r.GetChildren(It.IsAny<int>())).Returns(
                (int id) => Task.FromResult(categories.Where(c => c.ParentId == id).ToList() as IEnumerable<Category>));
            categoriesRepository.Setup(r => r.GetRoot()).ReturnsAsync(categories.Where(c => c.ParentId == null).ToList());
            categoriesRepository.Setup(r => r.Delete(It.IsAny<int>())).Returns((int id) => Task.FromResult(categories.RemoveAll(c => c.Id == id) > 0));

            _categoriesService = new CategoriesService(categoriesRepository.Object);
        }
Exemplo n.º 4
0
        private string[] getFiles(string path, string pattern)
        {
            // Cause an exception if the path is invalid
            Path.GetFileName(path);

            string pathWithoutTrailingSlash = path.EndsWith("\\") ? path.Substring(0, path.Length - 1) : path;
            //NOTE: the Replace calls below are a very minimal attempt to convert a basic, cmd.exe-style wildcard
            //into something Regex.IsMatch will know how to use.
            string finalPattern = "^" + pattern.Replace(".", "\\.").Replace("*", "[\\w\\W]*") + "$";

            List<string> matches = new List<string>(_defaultTasksFileMap.Keys);
            matches.RemoveAll(
                delegate (string candidate)
                {
                    bool sameFolder = (0 == String.Compare(Path.GetDirectoryName(candidate),
                                                           pathWithoutTrailingSlash,
                                                           StringComparison.OrdinalIgnoreCase));
                    return !sameFolder || !Regex.IsMatch(Path.GetFileName(candidate), finalPattern);
                });
            return matches.ToArray();
        }
Exemplo n.º 5
0
        public void GeneratorChildrenTest() {
            var children = new List<ChildInfo> {
                new ChildInfo("gi_code", null),
                new ChildInfo("gi_frame", null),
                new ChildInfo("gi_running", null),
                new ChildInfo("gi_yieldfrom", null),
                new ChildInfo("Results View", "tuple(a)", "Expanding the Results View will run the iterator")
            };

            if (Version.Version < PythonLanguageVersion.V26) {
                children.RemoveAll(c => c.ChildText == "gi_code");
            }
            if (Version.Version < PythonLanguageVersion.V35) {
                children.RemoveAll(c => c.ChildText == "gi_yieldfrom");
            }

            ChildTest("GeneratorTest.py", 6, "a", 0, children.ToArray());
        }
Exemplo n.º 6
0
        public void testDeleteSkill()
        {
            string[] tablesToFill = { "Volunteer.xlsx", "Group.xlsx", "GroupVol.xlsx", "VolAddress.xlsx",
                                "VolAddr.xlsx", "Skill.xlsx", "VolSkill.xlsx", "VolState.xlsx",
                                "VolEmail.xlsx", "VolPhone.xlsx"};
            cExcel.RemoveAllData();
            cExcel.InsertData(tablesToFill);

            string directory = cExcel.GetHelperFilesDir();
            string hdir = cExcel.GetHelperFilesDir();
            sp_Skill_BLL skillBLL = new sp_Skill_BLL();
            string query = "SELECT * FROM [Sheet1$]";
            DataTable dt = cExcel.QueryExcelFile(hdir + "Skill.xlsx", query);
            List<Tuple<Guid, String, int, Guid?>> rowTree = new List<Tuple<Guid, string, int, Guid?>>();

            foreach (DataRow row in dt.Rows)
            {
                var key = new Guid(row["SkillID"].ToString());
                var mstr = row["MstrSkillID"].ToString() == "" ? new Nullable<Guid>() : (Guid?)(new Guid(row["MstrSkillID"].ToString()));
                var activeFlag = Convert.ToInt32(row["ActiveFlg"]);
                var skillname = row["SkillName"].ToString();
                rowTree.Add(Tuple.Create<Guid, string, int, Guid?>(key, skillname, activeFlag, mstr));
            }
            //this function returns the guid of the parent we deleted
            Func<Guid, List<Tuple<Guid, String, int, Guid?>>> deleteReturnParent = (Guid key) =>
            {
                //Check to make sure this key is still contained in the database based
                //on the description of how it should work.
                var toDeleteRow = rowTree.Find((x) => {
                        return x.Item1.Equals(key);
                });
                rowTree.Remove(toDeleteRow);
                //Find all rows that have the key as their mstrskill
                var updateRows = rowTree.FindAll((x) =>
                {
                    return x.Item4.Equals(key);
                });
                //Remove them
                rowTree.RemoveAll((x) =>
                {
                    return x.Item4.Equals(key);
                });
                var returnList = new List<Tuple<Guid, String, int, Guid?>>();
                foreach (var row in updateRows){
                    //Update them so that their master skill ids point at the master skill of the deleted node
                    var guidTpl = Tuple.Create<Guid, String, int, Guid?>(row.Item1, row.Item2, row.Item3, toDeleteRow.Item4);
                    rowTree.Add(guidTpl);
                    returnList.Add(guidTpl);
                }
                return returnList;
            };

            foreach (DataRow row in dt.Rows)
            {
                sp_Skill_DM dmskill = new sp_Skill_DM();
                dmskill.ActiveFlg = Convert.ToInt32(row["ActiveFlg"]);
                dmskill.MstrSkillID = row["MstrSkillID"].ToString() == "" ? new Nullable<Guid>() : (Guid?)(new Guid(row["MstrSkillID"].ToString()));
                dmskill.SkillID = new Guid(row["SkillID"].ToString());
                dmskill.SkillName = row["SkillName"].ToString();

                //Delete a skill
                int before = cExcel.getNumRecordsFromDB("Vol.tblVolSkill");
                skillBLL.DeleteSkillContext(dmskill);
                var updatedList = deleteReturnParent(dmskill.SkillID);
                int after = cExcel.getNumRecordsFromDB("Vol.tblVolSkill");
                //Did the skill actually get deleted.
                Assert.AreEqual(before - 1, after);
                //Did all the values get properly updated
                foreach (var updatedRow in updatedList){
                    sp_Skill_DM updatedSkill = skillBLL.ListSingleSkill(updatedRow.Item1);
                    Assert.AreEqual(updatedSkill.ActiveFlg, updatedRow.Item3);
                    Assert.AreEqual(updatedSkill.MstrSkillID, updatedRow.Item4);
                    Assert.AreEqual(updatedSkill.SkillName, updatedRow.Item2);
                }
            }
            cExcel.RemoveData(tablesToFill);
        }
Exemplo n.º 7
0
        //[TestMethod]
        public void TestUTF8Encode()
        {
            Z3Provider solver = new Z3Provider();
            var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/UTF8Encode.bek");
            var tmp = stb.ToST();
            var sft = stb.Explore();
            var sft1 = sft.ToST();
            //sft.ShowGraph();
            //sft1.SaveAsDot("C:/tmp/dot/utf8encode.dot");

            #region data for the popl paper
            var st = sft.ToST();
            int n = st.StateCount;
            var moves = new List<Move<Rule<Expr>>>(st.GetMoves());
            moves.RemoveAll(x => x.Label.IsFinal);
            int m = moves.Count;
            int t = System.Environment.TickCount;
            var st_o_st = st + st;
            int n1 = st_o_st.StateCount;
            var moves1 = new List<Move<Rule<Expr>>>(st_o_st.GetMoves());
            moves1.RemoveAll(y => y.Label.IsFinal);
            int m1 = moves1.Count;
            bool diff = st.Eq1(st_o_st);
            t = System.Environment.TickCount - t;
            #endregion

            var restr = sft.ToST().RestrictDomain(".+");
            restr.AssertTheory();

            Expr inputConst = solver.MkFreshConst("input", restr.InputListSort);
            Expr outputConst = solver.MkFreshConst("output", restr.OutputListSort);

            solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));

            //validate correctness for some values against the actual UTF8Encode
            //TBD: validate also exceptional behavior, when the generated code throws an exception
            //the builtin one must contain the character 0xFFFD
            int K = 50;
            for (int i = 0; i < K; i++)
            {
                var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
                string input = model[inputConst].StringValue;
                string output = model[outputConst].StringValue;

                Assert.IsFalse(string.IsNullOrEmpty(input));
                Assert.IsFalse(string.IsNullOrEmpty(output));

                byte[] encoding = Encoding.UTF8.GetBytes(input);
                char[] chars = Array.ConvertAll(encoding, b => (char)b);
                string output_expected = new String(chars);
                string output_generated = UTF8Encode_F.Apply(input);
                string output_generated2 = UTF8Encode.Apply(input);
                string output_generated3 = UTF8Encode_B.Apply(input);

                Assert.AreEqual<string>(output_expected, output_generated);

                Assert.AreEqual<string>(output_expected, output_generated2);

                Assert.AreEqual<string>(output_expected, output_generated3);

                Assert.AreEqual<string>(output_expected, output);

                //exclude this solution, before picking the next one
                solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
            }
        }
        public void TestDeleteComplex()
        {
            var testData = TestDataGenerator.GetKeysAndValues(treeCount);
            var treeHead = new StdNode<int, string>();

            List<int> existingKeys = new List<int>(testData.Item1);
            List<int> deletedKeys = new List<int>();

            Random rnd = new Random();

            for (int i = 0; i < treeCount; i++)
                treeHead.Insert(testData.Item1[i], testData.Item2[i]);

            while (existingKeys.Count > 0)
            {
                foreach (int key in existingKeys)
                    Assert.AreEqual(Convert.ToString(key), treeHead.Find(key));

                int keyToDelete = existingKeys[rnd.Next(0, existingKeys.Count - 1)];

                treeHead.Delete(keyToDelete);
                deletedKeys.Add(keyToDelete);
                existingKeys.RemoveAll(x => x == keyToDelete);

                int deletedKeyToFind = deletedKeys[rnd.Next(0, deletedKeys.Count - 1)];

                Assert.AreEqual(null, treeHead.Find(deletedKeyToFind));
            }
        }
Exemplo n.º 9
0
        public void RemoveElemetFromListStrings()
        {
            List<string> list1 = new List<string>() { "meat", "falafel", "cafe", "meat" };

            //Act
            list1.RemoveAll(c => c == "meat");
            var result1 = list1.Any(c => c == "meat");

            //Assert
            Assert.IsFalse(result1);
        }
Exemplo n.º 10
0
        public void TestRooms()
        {
            List<Int32> list1 = new List<int>();
            list1.Add(1);
            list1.Add(2);
            list1.Add(3);
            list1.Add(4);
            int k = list1.Count;

            List<Int32> list2 = new List<int>(list1);

            list2.Add(5);
            list2.Add(6);

            int k2 = list2.Count;
            Assert.AreEqual(k + 2, k2);

            list2.RemoveAll(delegate(int i) { return list1.Contains(i); });
            int p = list2.Count;
            Assert.AreEqual(2, p);
        }
Exemplo n.º 11
0
        ///// <summary>
        /////A test for DeleteRoom
        /////</summary>
        //// TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        //// http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        //// whether you are testing a page, web service, or a WCF service.
        //[TestMethod()]
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\Users\\Tipsee\\Documents\\Visual Studio 2010\\Projects\\GR-Calcul\\GR-Calcul", "/")]
        //[UrlToTest("http://localhost:49893/")]
        //public void DeleteRoomTest()
        //{
        //    RoomModel target = new RoomModel(); // TODO: Initialize to an appropriate value
        //    int id = 0; // TODO: Initialize to an appropriate value
        //    target.DeleteRoom(id);
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}
        ///// <summary>
        /////A test for GetRoom
        /////</summary>
        //// TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        //// http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        //// whether you are testing a page, web service, or a WCF service.
        //[TestMethod()]
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\Users\\Tipsee\\Documents\\Visual Studio 2010\\Projects\\GR-Calcul\\GR-Calcul", "/")]
        //[UrlToTest("http://localhost:49893/")]
        //public void GetRoomTest()
        //{
        //    RoomModel target = new RoomModel(); // TODO: Initialize to an appropriate value
        //    int id = 0; // TODO: Initialize to an appropriate value
        //    Room expected = null; // TODO: Initialize to an appropriate value
        //    Room actual;
        //    actual = target.GetRoom(id);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}
        ///// <summary>
        /////A test for ListRooms
        /////</summary>
        //// TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        //// http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        //// whether you are testing a page, web service, or a WCF service.
        //[TestMethod()]
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\Users\\Tipsee\\Documents\\Visual Studio 2010\\Projects\\GR-Calcul\\GR-Calcul", "/")]
        //[UrlToTest("http://localhost:49893/")]
        //public void ListRoomsTest()
        //{
        //    RoomModel target = new RoomModel(); // TODO: Initialize to an appropriate value
        //    List<Room> expected = null; // TODO: Initialize to an appropriate value
        //    List<Room> actual;
        //    actual = target.ListRooms();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}
        ///// <summary>
        /////A test for CreateRoom
        /////</summary>
        //// TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        //// http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        //// whether you are testing a page, web service, or a WCF service.
        //[TestMethod()]
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\Users\\Tipsee\\Documents\\Visual Studio 2010\\Projects\\GR-Calcul\\GR-Calcul", "/")]
        //[UrlToTest("http://localhost:49893/")]
        //public void CreateRoomTest()
        //{
        //    RoomModel target = new RoomModel(); // TODO: Initialize to an appropriate value
        //    Room room = null; // TODO: Initialize to an appropriate value
        //    target.CreateRoom(room);
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}
        /// <summary>
        ///A test for CreateRoom
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        //[AspNetDevelopmentServerHost("C:\\Users\\Tipsee\\Documents\\Visual Studio 2010\\Projects\\GR-Calcul\\GR-Calcul", "/")]
        //[UrlToTest("http://localhost:49893/")]
        //[HostType("ASP.NET")]
        //[TestMethod()]
        public void TestGeneral()
        {
            RoomModel target = new RoomModel();
            List<Room> rooms = RoomModel.ListRooms();
            int k = rooms.Count;
            List<Int32> initialIds = new List<int>();
            foreach(var r in rooms)
                initialIds.Add(r.ID);

            RoomModel.CreateRoom(new Room());
            RoomModel.CreateRoom(new Room());

            int k2 = RoomModel.ListRooms().Count;
            Assert.AreEqual(k + 2, k2);

            List<Room> rooms2 = RoomModel.ListRooms();
            List<Int32> newIds = new List<int>();
            foreach (var r in rooms2)
                newIds.Add(r.ID);

            newIds.RemoveAll(delegate(int i){ return initialIds.Contains(i); });

            foreach (int i in newIds)
                RoomModel.DeleteRoom(i, RoomModel.GetRoom(i));
            int p = RoomModel.ListRooms().Count;
            Assert.AreEqual(k, p);
        }
        public void FactHierarchy_CrossLeaf_UnbalancedTest()
        {
            for (short i = 4; i <= 7; i++)
                for (short j = 4; j <= 7; j++)
                {
                    facts.Add(new ConcreteFact() { ProductId = i, GeographyId = j, SalesComponentId = 1, TimeId = 1, Value = 1 });
                    facts.Add(new ConcreteFact() { ProductId = i, GeographyId = j, SalesComponentId = 2, TimeId = 1, Value = 1 });
                }

            // we remove item 7 from the geo hierarchy
            var geo = new List<Relation>(this.hierarchy);
            geo.RemoveAll(r => r.Child == 7);

            var lookup = new ConcreteFactLookup(this.facts, this.prod, new Hierarchy(geo), this.causal, this.period);

            // this is a 4x3 graph, so 12
            Assert.AreEqual(12, lookup.SumChildren(1, 1, 1, 1));
            // including both causals will double
            Assert.AreEqual(24, lookup.SumChildren(1, 1, null, 1));
            // null will still include geog 7, so 4x4x2
            Assert.AreEqual(32, lookup.SumChildren(null, null, null, null));

            // each product will have 3 leaf items (the 3 geogs)
            Assert.AreEqual(3, lookup.SumChildren(4, 1, 1, 1));
            // both causals
            Assert.AreEqual(6, lookup.SumChildren(4, 1, null, 1));
            // null includes geog 7
            Assert.AreEqual(8, lookup.SumChildren(4, null, null, 1));

            // each geog will have 4 leaf items (the 4 prods)
            Assert.AreEqual(4, lookup.SumChildren(1, 4, 1, 1));
            // both causals
            Assert.AreEqual(8, lookup.SumChildren(1, 4, null, 1));
            Assert.AreEqual(8, lookup.SumChildren(null, 4, null, 1));

            // the real leaf level
            Assert.AreEqual(1, lookup.SumChildren(6, 6, 1, 1));
            Assert.AreEqual(2, lookup.SumChildren(6, 6, null, 1));

            // we can still query 7 - it exists, just not part of other hierarchy
            Assert.AreEqual(1, lookup.SumChildren(5, 7, 2, 1));
            Assert.AreEqual(4, lookup.SumChildren(null, 7, 2, 1));
            Assert.AreEqual(8, lookup.SumChildren(null, 7, null, 1));
        }