Пример #1
0
        public void DeleteTest()
        {
            //arrange
            //arrange
            var exp1   = new Experiment("exp1");
            var exp2   = new Experiment("exp2");
            var exp11  = new Experiment("exp1-1");
            var exp111 = new Experiment("exp1-1-1");
            var exp12  = new Experiment("exp1-2");
            var sig121 = new Signal("sig1-2-1");
            var sig111 = new Signal("sig1-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();
            var data = generateDummyData();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    var oneDim = new List <double>(8);
                    for (int k = 0; k < 8; k++)
                    {
                        oneDim.Add(data[i, j, k]);
                    }
                    //notice that this has only 2 interations for 3 dimention arry
                    mongoEngine.AppendSampleAsync(sig111.Id, new List <long> {
                        i, j
                    }, oneDim).Wait();
                }
            }
            //old tree

            /*
             * /exp1/exp11/sig111/payload1-1-1-1
             *          /exp111
             *    /exp12/sig121
             * /exp2
             *
             */

            //act
            //try delet exp12 error expetced
            var errorDelete = "";

            try
            {
                myCoreService.DeleteAsync(exp12.Id).Wait();
            }
            catch (Exception e)
            {
                errorDelete = e.InnerException.Message;
            }
            myCoreService.DeleteAsync(exp12.Id, true).Wait();
            myCoreService.DeleteAsync(exp2.Id).Wait();
            //the deleted entity is  non exist, error expected
            string errorDeleteNonExist = "";

            try
            {
                myCoreService.DeleteAsync(exp2.Id).Wait();
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorDeleteNonExist = e.InnerException.Message;
            }

            //get for assert
            var root    = myCoreService.GetAllChildrenAsync().Result;
            var nSig121 = myCoreService.GetOneByIdAsync(sig121.Id).Result;
            var nExp12  = myCoreService.GetChildIdByNameAsync(exp1.Id, exp12.Name).Result;

            //assert
            Assert.AreEqual(ErrorMessages.DeleteEntityWithChildError, errorDelete);
            Assert.AreEqual(ErrorMessages.EntityNotFoundError, errorDeleteNonExist);
            CollectionAssert.AreEquivalent(new List <Guid> {
                exp1.Id
            }, root.Select(r => r.Id).ToList());
            Assert.IsNull(nSig121);
            Assert.AreEqual(Guid.Empty, nExp12);

            var payloads = mongoEngine.GetPayloadIdsByParentIdAsync(sig111.Id).Result;

            Assert.AreEqual(64, payloads.Count());
            myCoreService.DeleteAsync(sig111.Id, true).Wait();
            var payloadZero = mongoEngine.GetPayloadIdsByParentIdAsync(sig111.Id).Result;

            Assert.AreEqual(0, payloadZero.Count());
        }
Пример #2
0
        public void QueryByNameTest()
        {
            //arrange
            var exp1    = new Experiment("exp1");
            var exp2    = new Experiment("exp2");
            var exp2c   = new Experiment("exp2");
            var exp11   = new Experiment("exp1-1");
            var exp12   = new Experiment("exp1-2");
            var sig121  = new Signal("sig1-2-1");
            var sig121c = new Signal("sig1-2-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();

            /*
             * /exp1/exp11/
             *   /exp12/sig121
             */

            //act
            //1. query by name
            var root1Id = myCoreService.GetChildIdByNameAsync(Guid.Empty, exp1.Name).Result;

            Assert.AreEqual(exp1.Id, root1Id);

            var secLev11Id = myCoreService.GetChildIdByNameAsync(exp1.Id, exp11.Name).Result;

            Assert.AreEqual(exp11.Id, secLev11Id);

            var secLev12Id = myCoreService.GetChildIdByNameAsync(exp1.Id, exp12.Name).Result;

            Assert.AreEqual(exp12.Id, secLev12Id);

            var nothing = myCoreService.GetChildIdByNameAsync(exp1.Id, "ass").Result;

            Assert.AreEqual(Guid.Empty, nothing);

            var trdLevId = myCoreService.GetChildIdByNameAsync(exp12.Id, sig121c.Name).Result;

            Assert.AreEqual(sig121.Id, trdLevId);

            //2 the parent is  non exist, error expected
            string errorParentNonExist = "";

            try
            {
                var tNothing = myCoreService.GetChildIdByNameAsync(Guid.NewGuid(), sig121c.Name).Result;
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorParentNonExist = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.ParentNotExistError, errorParentNonExist);
        }