Esempio n. 1
0
        public void SideAffectManager_DeleteSideAffect()
        {
            SideAffectManager m = new SideAffectManager(new TreeMonDbContext(connectionKey));
            SideAffect        s = new SideAffect()
            {
                AccountId   = "a",
                Name        = "DELETERECORD",
                CreatedBy   = "TESTUSER",
                DateCreated = DateTime.UtcNow,
            };

            m.Insert(s);

            //Test the delete flag
            Assert.IsTrue(m.DeleteSideAffect(s) > 0);
            m.GetSideAffect("DELETERECORD");
            SideAffect d = m.GetSideAffect("DELETERECORD");

            Assert.IsNotNull(d);
            Assert.IsTrue(d.Deleted == true);


            Assert.IsTrue(m.DeleteSideAffect(s, true) > 0);
            d = m.GetSideAffect("DELETERECORD");
            Assert.IsNull(d);
        }
        public ServiceResult Update(SideAffect s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid SideAffect sent to server."));
            }

            SideAffectManager SideAffectManager = new SideAffectManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var res = SideAffectManager.Get(s.UUID);

            if (res.Code != 200)
            {
                return(res);
            }

            var dbS = (SideAffect)res.Result;

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }
            dbS.Deleted   = s.Deleted;
            dbS.Name      = s.Name;
            dbS.Status    = s.Status;
            dbS.SortOrder = s.SortOrder;

            return(SideAffectManager.Update(dbS));
        }
Esempio n. 3
0
        public ServiceResult Insert(INode n)
        {
            if (!this.DataAccessAuthorized(n, "post", false))
            {
                return(ServiceResponse.Error("You are not authorized this action."));
            }

            n.Initialize(this._requestingUser.UUID, this._requestingUser.AccountUUID, this._requestingUser.RoleWeight);

            var s = (SideAffect)n;

            using (var context = new GreenWerxDbContext(this._connectionKey))
            {
                SideAffect dbU = context.GetAll <SideAffect>()?.FirstOrDefault(wu => wu.Name.EqualsIgnoreCase(s.Name) && wu.AccountUUID == s.AccountUUID);

                if (dbU != null)
                {
                    return(ServiceResponse.Error("SideAffect already exists."));
                }

                if (context.Insert <SideAffect>(s))
                {
                    return(ServiceResponse.OK("", s));
                }
            }
            return(ServiceResponse.Error("An error occurred inserting SideAffect " + s.Name));
        }
        public ServiceResult Insert(SideAffect n)
        {
            if (n == null)
            {
                return(ServiceResponse.Error("Invalid form data sent."));
            }

            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            if (string.IsNullOrWhiteSpace(n.AccountUUID) || n.AccountUUID == SystemFlag.Default.Account)
            {
                n.AccountUUID = CurrentUser.AccountUUID;
            }

            if (string.IsNullOrWhiteSpace(n.CreatedBy))
            {
                n.CreatedBy = CurrentUser.UUID;
            }

            if (n.DateCreated == DateTime.MinValue)
            {
                n.DateCreated = DateTime.UtcNow;
            }

            SideAffectManager SideAffectManager = new SideAffectManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            return(SideAffectManager.Insert(n));
        }
        public ServiceResult Update(SideAffect s)
        {
            if (s == null)
            {
                return(ServiceResponse.Error("Invalid SideAffect sent to server."));
            }

            SideAffectManager SideAffectManager = new SideAffectManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            var dbS = (SideAffect)SideAffectManager.GetBy(s.UUID);

            if (dbS == null)
            {
                return(ServiceResponse.Error("SideAffect was not found."));
            }


            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }
            dbS.Deleted   = s.Deleted;
            dbS.Name      = s.Name;
            dbS.Status    = s.Status;
            dbS.SortOrder = s.SortOrder;


            return(SideAffectManager.Update(dbS));
        }
        public void Api_SideAffectController_UpdateSideAffect()
        {
            TreeMonDbContext context = new TreeMonDbContext(connectionKey);
            SideAffect       mdl     = new SideAffect();

            mdl.AccountUUID = SystemFlag.Default.Account;
            mdl.Name        = Guid.NewGuid().ToString("N");
            mdl.UUID        = Guid.NewGuid().ToString("N");
            mdl.DateCreated = DateTime.Now;
            Assert.IsTrue(context.Insert <SideAffect>(mdl));

            mdl = context.GetAll <SideAffect>().Where(w => w.Name == mdl.Name).FirstOrDefault();
            SideAffect pv = new SideAffect();

            pv.Id          = mdl.Id;
            pv.UUID        = mdl.UUID;
            pv.AccountUUID = mdl.AccountUUID;
            pv.Name        = mdl.Name;
            pv.DateCreated = DateTime.Now;
            //~~~ Updatable fields ~~~

            string postData = JsonConvert.SerializeObject(pv);

            Task.Run(async() =>
            {
                ServiceResult res = await TestHelper.SentHttpRequest("POST", "api/SideAffects/Update", postData, _ownerAuthToken);
                Assert.IsNotNull(res);
                Assert.AreEqual(res.Code, 200);

                SideAffect dbSideAffect = context.GetAll <SideAffect>().Where(w => w.Name == mdl.Name).FirstOrDefault();
                Assert.IsNotNull(dbSideAffect);
            }).GetAwaiter().GetResult();
        }
        public void Api_SideAffectController_GetChildSideAffects()
        {
            string parentId = Guid.NewGuid().ToString("N");

            TreeMonDbContext context = new TreeMonDbContext(connectionKey);

            DoseLog dose = new DoseLog()
            {
                UUID         = Guid.NewGuid().ToString("N"),
                DateCreated  = DateTime.UtcNow,
                DoseDateTime = DateTime.UtcNow
            };

            Assert.IsTrue(context.Insert <DoseLog>(dose));

            SideAffect mdl = new SideAffect();

            mdl.AccountUUID = SystemFlag.Default.Account;
            mdl.Name        = Guid.NewGuid().ToString("N");
            mdl.UUParentID  = parentId;
            mdl.DoseUUID    = dose.UUID;
            mdl.DateCreated = DateTime.Now;
            Assert.IsTrue(context.Insert <SideAffect>(mdl));

            SideAffect mdl2 = new SideAffect();

            mdl2.AccountUUID = SystemFlag.Default.Account;
            mdl2.Name        = Guid.NewGuid().ToString("N");
            mdl2.UUParentID  = parentId;
            mdl2.DoseUUID    = dose.UUID;
            mdl2.DateCreated = DateTime.Now;
            Assert.IsTrue(context.Insert <SideAffect>(mdl2));

            Task.Run(async() =>
            {
                ServiceResult res = await TestHelper.SentHttpRequest("POST", "api/Doses/" + dose.UUID + "/SideAffects/History/" + mdl.UUParentID, "", _ownerAuthToken);

                Assert.IsNotNull(res);
                Assert.AreEqual(res.Code, 200);

                List <SideAffect> SideAffects = JsonConvert.DeserializeObject <List <SideAffect> >(res.Result.ToString());
                Assert.IsNotNull(SideAffects);
                Assert.IsTrue(SideAffects.Count >= 2);

                int foundSideAffects = 0;
                foreach (SideAffect p in SideAffects)
                {
                    if (p.Name == mdl.Name || p.Name == mdl2.Name)
                    {
                        foundSideAffects++;
                    }
                }

                Assert.AreEqual(foundSideAffects, 2);
            }).GetAwaiter().GetResult();
        }
        public ServiceResult Delete(SideAffect n)
        {
            if (n == null || string.IsNullOrWhiteSpace(n.UUID))
            {
                return(ServiceResponse.Error("Invalid account was sent."));
            }

            SideAffectManager SideAffectManager = new SideAffectManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            return(SideAffectManager.Delete(n));
        }
        public ServiceResult Delete(SideAffect n)
        {
            if (n == null || string.IsNullOrWhiteSpace(n.UUID))
            {
                return(ServiceResponse.Error("Invalid account was sent."));
            }

            SideAffectManager SideAffectManager = new SideAffectManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            return(SideAffectManager.Delete(n));
        }
Esempio n. 10
0
        public void SideAffectManager_GetSideAffect()
        {
            SideAffectManager m  = new SideAffectManager(new TreeMonDbContext(connectionKey));
            ServiceResult     sr = m.Insert(new SideAffect()
            {
                AccountId   = "a",
                Name        = "ALPHA",
                DateCreated = DateTime.UtcNow
            }, false);

            Assert.AreEqual(sr.Code, 200, sr.Message);
            SideAffect s = m.GetSideAffect("ALPHA");

            Assert.IsNotNull(s);
        }
Esempio n. 11
0
        public void SideAffectManager_UpdateSideAffect()
        {
            SideAffectManager m = new SideAffectManager(new TreeMonDbContext(connectionKey));

            m.Insert(new SideAffect()
            {
                AccountId = "a",
                Name      = "TESTRECORD",
            });
            SideAffect s = m.GetSideAffect("TESTRECORD");

            s.Name = "UPDATEDRECORD";

            Assert.AreEqual(m.UpdateSideAffect(s).Code, 200);
            SideAffect u = m.GetSideAffect("UPDATEDRECORD");

            Assert.IsNotNull(u);
        }
        public ServiceResult GetBy(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("You must provide a name for the SideAffect."));
            }

            SideAffectManager SideAffectManager = new SideAffectManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            SideAffect s = (SideAffect)SideAffectManager.GetBy(uuid);

            if (s == null)
            {
                return(ServiceResponse.Error("SideAffect could not be located for the uuid " + uuid));
            }

            return(ServiceResponse.OK("", s));
        }
Esempio n. 13
0
        public void SideAffectManager_GetSideAffectBy()
        {
            SideAffectManager m = new SideAffectManager(new TreeMonDbContext(connectionKey));

            Assert.AreEqual(
                m.Insert(new SideAffect()
            {
                AccountId   = "a",
                Name        = "TESTRECORD",
                DateCreated = DateTime.UtcNow
            }, false)
                .Code, 200);
            SideAffect s = m.GetSideAffect("TESTRECORD");

            Assert.IsNotNull(s);
            SideAffect suid = m.GetSideAffectBy(s.UUID);

            Assert.IsNotNull(suid);
        }
        public void Api_SideAffectController_GetSideAffect()
        {
            TreeMonDbContext context = new TreeMonDbContext(connectionKey);
            SideAffect       mdl     = new SideAffect();

            mdl.UUID        = Guid.NewGuid().ToString("N");
            mdl.AccountUUID = SystemFlag.Default.Account;
            mdl.Name        = Guid.NewGuid().ToString("N");
            mdl.DateCreated = DateTime.Now;
            Assert.IsTrue(context.Insert <SideAffect>(mdl));

            Task.Run(async() =>
            {
                ServiceResult res = await TestHelper.SentHttpRequest("GET", "api/SideAffect/" + mdl.Name, "", _ownerAuthToken);

                Assert.IsNotNull(res);
                Assert.AreEqual(res.Code, 200);

                SideAffect p = JsonConvert.DeserializeObject <SideAffect>(res.Result.ToString());
                Assert.IsNotNull(p);
                Assert.AreEqual(mdl.Name, p.Name);
            }).GetAwaiter().GetResult();
        }
        public void Api_SideAffectController_AddSideAffect()
        {
            SideAffect mdl = new SideAffect();

            mdl.AccountUUID = SystemFlag.Default.Account;
            mdl.Name        = Guid.NewGuid().ToString("N");
            mdl.UUID        = Guid.NewGuid().ToString("N");

            string postData = JsonConvert.SerializeObject(mdl);

            Task.Run(async() =>
            {
                ServiceResult res = await TestHelper.SentHttpRequest("POST", "api/SideAffects/Add", postData, _ownerAuthToken);
                Assert.IsNotNull(res);
                Assert.AreEqual(res.Code, 200);

                SideAffect p = JsonConvert.DeserializeObject <SideAffect>(res.Result.ToString());
                Assert.IsNotNull(p);
                TreeMonDbContext context = new TreeMonDbContext(connectionKey);
                SideAffect dbSideAffect  = context.GetAll <SideAffect>().Where(w => w.UUID == p.UUID).FirstOrDefault();
                Assert.IsNotNull(dbSideAffect);
                Assert.AreEqual(mdl.Name, dbSideAffect.Name);
            }).GetAwaiter().GetResult();
        }