示例#1
0
        public void RenameTest()
        {
            //arrange
            var exp1  = new TestExp("exp1");
            var exp2  = new Experiment("exp2");
            var sig11 = new TestSignal("sig1-1"); exp1.TestList.Add("String1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp2).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();

            //act&assert
            //1 rename mistakely。
            var errorRenameEntity = "";

            try
            {
                myCoreService.ReNameAsync(exp1.Id, exp2.Name).Wait();
            }
            catch (Exception e)
            {
                errorRenameEntity = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NameDuplicateError, errorRenameEntity);

            //2 rename properly
            myCoreService.ReNameAsync(exp1.Id, "newExp1").Wait();
            var exp1Result  = myCoreService.GetOneByIdAsync(exp1.Id).Result;
            var sig11Result = myCoreService.GetOneByIdAsync(sig11.Id).Result;

            Assert.AreEqual("newExp1", exp1Result.Name);
            Assert.AreEqual("/newExp1", exp1Result.Path);
            Assert.AreEqual(sig11.Name, sig11Result.Name);
            Assert.AreEqual("/newExp1/sig1-1", sig11Result.Path);
        }
示例#2
0
        public void UpdateTest()
        {
            //arrange
            var exp1  = new TestExp("exp1");
            var sig11 = new TestSignal("sig1-1");

            exp1.TestList.Add("String1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();

            //act&assert
            //1 update mistakenly
            string errorUpdateField = "";
            var    updates          = new Dictionary <string, UpdateEntity>();

            updates.Add("Id", new UpdateEntity {
                Operator = OperatorType.Set, Value = Guid.NewGuid()
            });
            try
            {
                myCoreService.UpDateAsync(exp1.Id, updates).Wait();
            }
            catch (Exception e)
            {
                errorUpdateField = e.InnerException.Message;
                updates.Clear();
            }
            Assert.AreEqual(ErrorMessages.NotValidUpdateFieldError, errorUpdateField);

            //2 update signal properly
            updates.Add("TestString", new UpdateEntity {
                Operator = OperatorType.Set, Value = "NewTestString"
            });
            updates.Add("TestList", new UpdateEntity {
                Operator = OperatorType.Push, Value = new List <string> {
                    "String1", "String2"
                }
            });
            myCoreService.UpDateAsync(sig11.Id, updates).Wait();
            var sig11Result = (TestSignal)myCoreService.GetOneByIdAsync(sig11.Id).Result;

            Assert.AreEqual("NewTestString", sig11Result.TestString);
            Assert.AreEqual(2, sig11Result.TestList.Count);

            updates.Clear();
            //3 update expermient properly
            updates.Add("TestString", new UpdateEntity {
                Operator = OperatorType.Set, Value = "NewTestString"
            });
            updates.Add("TestList", new UpdateEntity {
                Operator = OperatorType.Push, Value = "String2"
            });
            myCoreService.UpDateAsync(exp1.Id, updates).Wait();
            var exp1Result = (TestExp)myCoreService.GetOneByIdAsync(exp1.Id).Result;

            Assert.AreEqual("NewTestString", exp1Result.TestString);
            Assert.AreEqual(2, exp1Result.TestList.Count);
        }
示例#3
0
        public void DuplicateTest()
        {
            //arrange
            //arrange
            var exp1   = new Experiment("exp1");
            var exp2   = new Experiment("exp2");
            var exp11  = new Experiment("exp1-1");
            var exp111 = new TestExp("exp1-1-1");
            var exp12  = new Experiment("exp1-2");
            var sig121 = new Signal("sig1-2-1");
            var sig111 = new TestSignal("sig1-1-1");

            exp111.TestString = "test";
            exp111.TestList   = new List <string> {
                "1", "1", "1"
            };
            sig111.TestString = "test";
            sig111.TestList   = new List <string> {
                "1", "1", "1"
            };

            //add 2 root
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp2).Wait();

            //add child
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp11).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp12).Wait();
            myCoreService.AddJdbcEntityToAsync(exp12.Id, sig121).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, sig111).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, exp111).Wait();

            //old tree                                       new tree

            /*
             * /exp1/exp11/sig111                        /exp1/exp11/sig111
             *          /exp111                                   /exp111
             *    /exp12/sig121                             /exp11c/sig111
             * /exp2                                                 /exp111
             *                                              /exp12/sig121
             *                                         /exp2 /exp12
             */

            // 1 父节点下有同名节点
            var errorSameName = "";

            try
            {
                myCoreService.DuplicateAsync(exp11.Id, exp1.Id, exp11.Name).Wait();
            }
            catch (Exception e)
            {
                errorSameName = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NameDuplicateError, errorSameName);

            myCoreService.DuplicateAsync(exp11.Id, exp1.Id, "exp1-1-c", true).Wait();
            myCoreService.DuplicateAsync(exp12.Id, exp2.Id, exp12.Name).Wait();

            //get for assert
            var childrenNameOfExp1 = myCoreService.GetAllChildrenAsync(exp1.Id).Result.Select(e => e.Name);
            var exp11c             = myCoreService.GetChildByNameAsync(exp1.Id, "exp1-1-c").Result;
            var exp111c            = myCoreService.GetChildByNameAsync(exp11c.Id, "exp1-1-1").Result as TestExp;
            var sig111c            = myCoreService.GetChildByNameAsync(exp11c.Id, "sig1-1-1").Result as TestSignal;
            var childrenOfExp2     = myCoreService.GetAllChildrenAsync(exp2.Id).Result.Single();
            var childOfNewExp12    = myCoreService.GetAllChildrenAsync(childrenOfExp2.Id).Result;

            //assert

            CollectionAssert.AreEquivalent(new List <string> {
                "exp1-1-c", "exp1-1", "exp1-2"
            }, childrenNameOfExp1.ToList());
            Assert.AreEqual(exp111.TestString, exp111c.TestString);
            Assert.AreNotEqual(exp111.Id, exp111c.Id);
            Assert.AreNotEqual(exp111.ParentId, exp111c.ParentId);
            Assert.AreEqual(sig111.TestString, sig111c.TestString);
            CollectionAssert.AreEqual(exp111.TestList, exp111c.TestList);
            CollectionAssert.AreEqual(sig111.TestList, sig111c.TestList);
            Assert.AreEqual(0, childOfNewExp12.Count());
        }