Exemplo n.º 1
0
        private AppErrLog GetFilledRandomAppErrLog(string OmitPropName)
        {
            AppErrLog appErrLog = new AppErrLog();

            if (OmitPropName != "Tag")
            {
                appErrLog.Tag = GetRandomString("", 5);
            }
            if (OmitPropName != "LineNumber")
            {
                appErrLog.LineNumber = GetRandomInt(1, 11);
            }
            if (OmitPropName != "Source")
            {
                appErrLog.Source = GetRandomString("", 20);
            }
            if (OmitPropName != "Message")
            {
                appErrLog.Message = GetRandomString("", 20);
            }
            if (OmitPropName != "DateTime_UTC")
            {
                appErrLog.DateTime_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateDate_UTC")
            {
                appErrLog.LastUpdateDate_UTC = new DateTime(2005, 3, 6);
            }
            if (OmitPropName != "LastUpdateContactTVItemID")
            {
                appErrLog.LastUpdateContactTVItemID = 2;
            }

            return(appErrLog);
        }
Exemplo n.º 2
0
        public AppErrLog GetAppErrLogWithAppErrLogIDDB(int AppErrLogID)
        {
            AppErrLog appErrLog = (from c in db.AppErrLogs
                                   where c.AppErrLogID == AppErrLogID
                                   select c).FirstOrDefault <AppErrLog>();

            return(appErrLog);
        }
        public void AppErrLog_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    AppErrLogController appErrLogController = new AppErrLogController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(appErrLogController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, appErrLogController.DatabaseType);

                    AppErrLog appErrLogLast = new AppErrLog();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        AppErrLogService appErrLogService = new AppErrLogService(query, db, ContactID);
                        appErrLogLast = (from c in db.AppErrLogs select c).FirstOrDefault();
                    }

                    // ok with AppErrLog info
                    IHttpActionResult jsonRet = appErrLogController.GetAppErrLogWithID(appErrLogLast.AppErrLogID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <AppErrLog> Ret = jsonRet as OkNegotiatedContentResult <AppErrLog>;
                    AppErrLog appErrLogRet = Ret.Content;
                    Assert.AreEqual(appErrLogLast.AppErrLogID, appErrLogRet.AppErrLogID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = appErrLogController.Put(appErrLogRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <AppErrLog> appErrLogRet2 = jsonRet2 as OkNegotiatedContentResult <AppErrLog>;
                    Assert.IsNotNull(appErrLogRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because AppErrLogID of 0 does not exist
                    appErrLogRet.AppErrLogID = 0;
                    IHttpActionResult jsonRet3 = appErrLogController.Put(appErrLogRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <AppErrLog> appErrLogRet3 = jsonRet3 as OkNegotiatedContentResult <AppErrLog>;
                    Assert.IsNull(appErrLogRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
Exemplo n.º 4
0
        public void AppErrLog_CRUD_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    AppErrLogService appErrLogService = new AppErrLogService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    AppErrLog appErrLog = GetFilledRandomAppErrLog("");

                    // -------------------------------
                    // -------------------------------
                    // CRUD testing
                    // -------------------------------
                    // -------------------------------

                    count = appErrLogService.GetAppErrLogList().Count();

                    Assert.AreEqual(count, (from c in dbTestDB.AppErrLogs select c).Count());

                    appErrLogService.Add(appErrLog);
                    if (appErrLog.HasErrors)
                    {
                        Assert.AreEqual("", appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(true, appErrLogService.GetAppErrLogList().Where(c => c == appErrLog).Any());
                    appErrLogService.Update(appErrLog);
                    if (appErrLog.HasErrors)
                    {
                        Assert.AreEqual("", appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count + 1, appErrLogService.GetAppErrLogList().Count());
                    appErrLogService.Delete(appErrLog);
                    if (appErrLog.HasErrors)
                    {
                        Assert.AreEqual("", appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    }
                    Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count());
                }
            }
        }
Exemplo n.º 5
0
        public void SetupTest(ContactModel contactModelToDo, CultureInfo culture)
        {
            Thread.CurrentThread.CurrentCulture   = culture;
            Thread.CurrentThread.CurrentUICulture = culture;

            contactModel      = contactModelToDo;
            user              = new GenericPrincipal(new GenericIdentity(contactModel.LoginEmail, "Forms"), null);
            appErrLogService  = new AppErrLogService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            testDBService     = new TestDBService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user, TableName, Plurial);
            randomService     = new RandomService((culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en), user);
            appErrLogModelNew = new AppErrLogModel();
            appErrLog         = new AppErrLog();
        }
Exemplo n.º 6
0
        public AppErrLogModel PostUpdateAppErrLogDB(AppErrLogModel appErrLogModel)
        {
            string retStr = AppErrLogModelOK(appErrLogModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            AppErrLog appErrLogToUpdate = GetAppErrLogWithAppErrLogIDDB(appErrLogModel.AppErrLogID);

            if (appErrLogToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.AppErrLog)));
            }


            retStr = FillAppErrLog(appErrLogToUpdate, appErrLogModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("AppErrLogs", appErrLogToUpdate.AppErrLogID, LogCommandEnum.Change, appErrLogToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }

            return(GetAppErrLogModelWithAppErrLogIDDB(appErrLogToUpdate.AppErrLogID));
        }
Exemplo n.º 7
0
        // Post
        public AppErrLogModel PostAddAppErrLogDB(AppErrLogModel appErrLogModel)
        {
            string retStr = AppErrLogModelOK(appErrLogModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }


            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }


            AppErrLog appErrLogNew = new AppErrLog();

            retStr = FillAppErrLog(appErrLogNew, appErrLogModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }


            using (TransactionScope ts = new TransactionScope())
            {
                db.AppErrLogs.Add(appErrLogNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("AppErrLogs", appErrLogNew.AppErrLogID, LogCommandEnum.Add, appErrLogNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetAppErrLogModelWithAppErrLogIDDB(appErrLogNew.AppErrLogID));
        }
        public bool Update(AppErrLog appErrLog)
        {
            appErrLog.ValidationResults = Validate(new ValidationContext(appErrLog), ActionDBTypeEnum.Update);
            if (appErrLog.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.AppErrLogs.Update(appErrLog);

            if (!TryToSave(appErrLog))
            {
                return(false);
            }

            return(true);
        }
        private bool TryToSave(AppErrLog appErrLog)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                appErrLog.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
0
        public void AppErrLogService_GetAppErrLogWithAppErrLogIDDB_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                using (TransactionScope ts = new TransactionScope())
                {
                    AppErrLogModel appErrLogModelRet = AddAppErrLogModel();

                    AppErrLog appErrLogRet2 = appErrLogService.GetAppErrLogWithAppErrLogIDDB(appErrLogModelRet.AppErrLogID);
                    Assert.IsNotNull(appErrLogRet2);
                    Assert.AreEqual(appErrLogModelRet.AppErrLogID, appErrLogRet2.AppErrLogID);

                    AppErrLog appErrLogRet3 = appErrLogService.GetAppErrLogWithAppErrLogIDDB(0);
                    Assert.IsNull(appErrLogRet3);
                }
            }
        }
        public void AppErrLog_Controller_GetAppErrLogWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    AppErrLogController appErrLogController = new AppErrLogController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(appErrLogController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, appErrLogController.DatabaseType);

                    AppErrLog appErrLogFirst = new AppErrLog();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        AppErrLogService appErrLogService = new AppErrLogService(new Query(), db, ContactID);
                        appErrLogFirst = (from c in db.AppErrLogs select c).FirstOrDefault();
                    }

                    // ok with AppErrLog info
                    IHttpActionResult jsonRet = appErrLogController.GetAppErrLogWithID(appErrLogFirst.AppErrLogID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <AppErrLog> Ret = jsonRet as OkNegotiatedContentResult <AppErrLog>;
                    AppErrLog appErrLogRet = Ret.Content;
                    Assert.AreEqual(appErrLogFirst.AppErrLogID, appErrLogRet.AppErrLogID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = appErrLogController.GetAppErrLogWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <AppErrLog> appErrLogRet2 = jsonRet2 as OkNegotiatedContentResult <AppErrLog>;
                    Assert.IsNull(appErrLogRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([FromBody] AppErrLog appErrLog, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                AppErrLogService appErrLogService = new AppErrLogService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!appErrLogService.Delete(appErrLog))
                {
                    return(BadRequest(String.Join("|||", appErrLog.ValidationResults)));
                }
                else
                {
                    appErrLog.ValidationResults = null;
                    return(Ok(appErrLog));
                }
            }
        }
Exemplo n.º 13
0
        // Fill
        public string FillAppErrLog(AppErrLog appErrLog, AppErrLogModel appErrLogModel, ContactOK contactOK)
        {
            appErrLog.DBCommand          = (int)appErrLogModel.DBCommand;
            appErrLog.Tag                = appErrLogModel.Tag;
            appErrLog.LineNumber         = appErrLogModel.LineNumber;
            appErrLog.Source             = appErrLogModel.Source;
            appErrLog.Message            = appErrLogModel.Message;
            appErrLog.DateTime_UTC       = appErrLogModel.DateTime_UTC;
            appErrLog.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                appErrLog.LastUpdateContactTVItemID = 2;
            }
            else
            {
                appErrLog.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }


            return("");
        }
Exemplo n.º 14
0
        public void GetAppErrLogList_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    AppErrLogService appErrLogService = new AppErrLogService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);
                    AppErrLog appErrLog = (from c in dbTestDB.AppErrLogs select c).FirstOrDefault();
                    Assert.IsNotNull(appErrLog);

                    List <AppErrLog> appErrLogDirectQueryList = new List <AppErrLog>();
                    appErrLogDirectQueryList = (from c in dbTestDB.AppErrLogs select c).Take(200).ToList();

                    foreach (string extra in new List <string>()
                    {
                        null, "A", "B", "C", "D", "E"
                    })
                    {
                        appErrLogService.Query.Extra = extra;

                        if (string.IsNullOrWhiteSpace(extra))
                        {
                            List <AppErrLog> appErrLogList = new List <AppErrLog>();
                            appErrLogList = appErrLogService.GetAppErrLogList().ToList();
                            CheckAppErrLogFields(appErrLogList);
                        }
                        else
                        {
                            //Assert.AreEqual(true, false);
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        public AppErrLogModel PostDeleteAppErrLogDB(int AppErrLogID)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            AppErrLog appErrLogToDelete = GetAppErrLogWithAppErrLogIDDB(AppErrLogID);

            if (appErrLogToDelete == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.AppErrLog)));
            }


            using (TransactionScope ts = new TransactionScope())
            {
                db.AppErrLogs.Remove(appErrLogToDelete);
                string retStr = DoDeleteChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("AppErrLogs", appErrLogToDelete.AppErrLogID, LogCommandEnum.Delete, appErrLogToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(ReturnError(""));
        }
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string    retStr    = "";
            Enums     enums     = new Enums(LanguageRequest);
            AppErrLog appErrLog = validationContext.ObjectInstance as AppErrLog;

            appErrLog.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (appErrLog.AppErrLogID == 0)
                {
                    appErrLog.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "AppErrLogID"), new[] { "AppErrLogID" }));
                }

                if (!(from c in db.AppErrLogs select c).Where(c => c.AppErrLogID == appErrLog.AppErrLogID).Any())
                {
                    appErrLog.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppErrLog", "AppErrLogID", appErrLog.AppErrLogID.ToString()), new[] { "AppErrLogID" }));
                }
            }

            if (string.IsNullOrWhiteSpace(appErrLog.Tag))
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Tag"), new[] { "Tag" }));
            }

            if (!string.IsNullOrWhiteSpace(appErrLog.Tag) && appErrLog.Tag.Length > 100)
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Tag", "100"), new[] { "Tag" }));
            }

            if (appErrLog.LineNumber < 1)
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MinValueIs_, "LineNumber", "1"), new[] { "LineNumber" }));
            }

            if (string.IsNullOrWhiteSpace(appErrLog.Source))
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Source"), new[] { "Source" }));
            }

            //Source has no StringLength Attribute

            if (string.IsNullOrWhiteSpace(appErrLog.Message))
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Message"), new[] { "Message" }));
            }

            //Message has no StringLength Attribute

            if (appErrLog.DateTime_UTC.Year == 1)
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "DateTime_UTC"), new[] { "DateTime_UTC" }));
            }
            else
            {
                if (appErrLog.DateTime_UTC.Year < 1980)
                {
                    appErrLog.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "DateTime_UTC", "1980"), new[] { "DateTime_UTC" }));
                }
            }

            if (appErrLog.LastUpdateDate_UTC.Year == 1)
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (appErrLog.LastUpdateDate_UTC.Year < 1980)
                {
                    appErrLog.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == appErrLog.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", appErrLog.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    appErrLog.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                appErrLog.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Exemplo n.º 17
0
        public void AppErrLog_Properties_Test()
        {
            foreach (CultureInfo culture in AllowableCulture)
            {
                ChangeCulture(culture);

                using (CSSPDBContext dbTestDB = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                {
                    AppErrLogService appErrLogService = new AppErrLogService(new Query()
                    {
                        Lang = culture.TwoLetterISOLanguageName
                    }, dbTestDB, ContactID);

                    int count = 0;
                    if (count == 1)
                    {
                        // just so we don't get a warning during compile [The variable 'count' is assigned but its value is never used]
                    }

                    count = appErrLogService.GetAppErrLogList().Count();

                    AppErrLog appErrLog = GetFilledRandomAppErrLog("");

                    // -------------------------------
                    // -------------------------------
                    // Properties testing
                    // -------------------------------
                    // -------------------------------


                    // -----------------------------------
                    // [Key]
                    // Is NOT Nullable
                    // appErrLog.AppErrLogID   (Int32)
                    // -----------------------------------

                    appErrLog             = null;
                    appErrLog             = GetFilledRandomAppErrLog("");
                    appErrLog.AppErrLogID = 0;
                    appErrLogService.Update(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "AppErrLogID"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);

                    appErrLog             = null;
                    appErrLog             = GetFilledRandomAppErrLog("");
                    appErrLog.AppErrLogID = 10000000;
                    appErrLogService.Update(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "AppErrLog", "AppErrLogID", appErrLog.AppErrLogID.ToString()), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [StringLength(100))]
                    // appErrLog.Tag   (String)
                    // -----------------------------------

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("Tag");
                    Assert.AreEqual(false, appErrLogService.Add(appErrLog));
                    Assert.AreEqual(1, appErrLog.ValidationResults.Count());
                    Assert.IsTrue(appErrLog.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Tag")).Any());
                    Assert.AreEqual(null, appErrLog.Tag);
                    Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count());

                    appErrLog     = null;
                    appErrLog     = GetFilledRandomAppErrLog("");
                    appErrLog.Tag = GetRandomString("", 101);
                    Assert.AreEqual(false, appErrLogService.Add(appErrLog));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MaxLengthIs_, "Tag", "100"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // [Range(1, -1)]
                    // appErrLog.LineNumber   (Int32)
                    // -----------------------------------

                    appErrLog            = null;
                    appErrLog            = GetFilledRandomAppErrLog("");
                    appErrLog.LineNumber = 0;
                    Assert.AreEqual(false, appErrLogService.Add(appErrLog));
                    Assert.AreEqual(string.Format(CSSPServicesRes._MinValueIs_, "LineNumber", "1"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count());

                    // -----------------------------------
                    // Is NOT Nullable
                    // appErrLog.Source   (String)
                    // -----------------------------------

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("Source");
                    Assert.AreEqual(false, appErrLogService.Add(appErrLog));
                    Assert.AreEqual(1, appErrLog.ValidationResults.Count());
                    Assert.IsTrue(appErrLog.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Source")).Any());
                    Assert.AreEqual(null, appErrLog.Source);
                    Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count());


                    // -----------------------------------
                    // Is NOT Nullable
                    // appErrLog.Message   (String)
                    // -----------------------------------

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("Message");
                    Assert.AreEqual(false, appErrLogService.Add(appErrLog));
                    Assert.AreEqual(1, appErrLog.ValidationResults.Count());
                    Assert.IsTrue(appErrLog.ValidationResults.Where(c => c.ErrorMessage == string.Format(CSSPServicesRes._IsRequired, "Message")).Any());
                    Assert.AreEqual(null, appErrLog.Message);
                    Assert.AreEqual(count, appErrLogService.GetAppErrLogList().Count());


                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // appErrLog.DateTime_UTC   (DateTime)
                    // -----------------------------------

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("");
                    appErrLog.DateTime_UTC = new DateTime();
                    appErrLogService.Add(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "DateTime_UTC"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("");
                    appErrLog.DateTime_UTC = new DateTime(1979, 1, 1);
                    appErrLogService.Add(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "DateTime_UTC", "1980"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPAfter(Year = 1980)]
                    // appErrLog.LastUpdateDate_UTC   (DateTime)
                    // -----------------------------------

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("");
                    appErrLog.LastUpdateDate_UTC = new DateTime();
                    appErrLogService.Add(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);
                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("");
                    appErrLog.LastUpdateDate_UTC = new DateTime(1979, 1, 1);
                    appErrLogService.Add(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);

                    // -----------------------------------
                    // Is NOT Nullable
                    // [CSSPExist(ExistTypeName = "TVItem", ExistPlurial = "s", ExistFieldID = "TVItemID", AllowableTVtypeList = Contact)]
                    // appErrLog.LastUpdateContactTVItemID   (Int32)
                    // -----------------------------------

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("");
                    appErrLog.LastUpdateContactTVItemID = 0;
                    appErrLogService.Add(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", appErrLog.LastUpdateContactTVItemID.ToString()), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);

                    appErrLog = null;
                    appErrLog = GetFilledRandomAppErrLog("");
                    appErrLog.LastUpdateContactTVItemID = 1;
                    appErrLogService.Add(appErrLog);
                    Assert.AreEqual(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), appErrLog.ValidationResults.FirstOrDefault().ErrorMessage);


                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // appErrLog.HasErrors   (Boolean)
                    // -----------------------------------

                    // No testing requied

                    // -----------------------------------
                    // Is NOT Nullable
                    // [NotMapped]
                    // appErrLog.ValidationResults   (IEnumerable`1)
                    // -----------------------------------

                    // No testing requied
                }
            }
        }
        public IHttpActionResult GetAppErrLogWithID([FromUri] int AppErrLogID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                AppErrLogService appErrLogService = new AppErrLogService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                appErrLogService.Query = appErrLogService.FillQuery(typeof(AppErrLog), lang, 0, 1, "", "", extra);

                if (appErrLogService.Query.Extra == "A")
                {
                    AppErrLogExtraA appErrLogExtraA = new AppErrLogExtraA();
                    appErrLogExtraA = appErrLogService.GetAppErrLogExtraAWithAppErrLogID(AppErrLogID);

                    if (appErrLogExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(appErrLogExtraA));
                }
                else if (appErrLogService.Query.Extra == "B")
                {
                    AppErrLogExtraB appErrLogExtraB = new AppErrLogExtraB();
                    appErrLogExtraB = appErrLogService.GetAppErrLogExtraBWithAppErrLogID(AppErrLogID);

                    if (appErrLogExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(appErrLogExtraB));
                }
                else if (appErrLogService.Query.Extra == "C")
                {
                    AppErrLogExtraC appErrLogExtraC = new AppErrLogExtraC();
                    appErrLogExtraC = appErrLogService.GetAppErrLogExtraCWithAppErrLogID(AppErrLogID);

                    if (appErrLogExtraC == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(appErrLogExtraC));
                }
                else if (appErrLogService.Query.Extra == "D")
                {
                    AppErrLogExtraD appErrLogExtraD = new AppErrLogExtraD();
                    appErrLogExtraD = appErrLogService.GetAppErrLogExtraDWithAppErrLogID(AppErrLogID);

                    if (appErrLogExtraD == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(appErrLogExtraD));
                }
                else
                {
                    AppErrLog appErrLog = new AppErrLog();
                    appErrLog = appErrLogService.GetAppErrLogWithAppErrLogID(AppErrLogID);

                    if (appErrLog == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(appErrLog));
                }
            }
        }
Exemplo n.º 19
0
 public AppErrLogTest()
 {
     appErrLog       = new AppErrLog();
     appErrLogExtraA = new AppErrLogExtraA();
     appErrLogExtraB = new AppErrLogExtraB();
 }
        public void AppErrLog_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    AppErrLogController appErrLogController = new AppErrLogController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(appErrLogController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, appErrLogController.DatabaseType);

                    AppErrLog appErrLogLast = new AppErrLog();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        AppErrLogService appErrLogService = new AppErrLogService(query, db, ContactID);
                        appErrLogLast = (from c in db.AppErrLogs select c).FirstOrDefault();
                    }

                    // ok with AppErrLog info
                    IHttpActionResult jsonRet = appErrLogController.GetAppErrLogWithID(appErrLogLast.AppErrLogID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <AppErrLog> Ret = jsonRet as OkNegotiatedContentResult <AppErrLog>;
                    AppErrLog appErrLogRet = Ret.Content;
                    Assert.AreEqual(appErrLogLast.AppErrLogID, appErrLogRet.AppErrLogID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Post to return CSSPError because AppErrLogID exist
                    IHttpActionResult jsonRet2 = appErrLogController.Post(appErrLogRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <AppErrLog> appErrLogRet2 = jsonRet2 as OkNegotiatedContentResult <AppErrLog>;
                    Assert.IsNull(appErrLogRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest2);

                    // Post to return newly added AppErrLog
                    appErrLogRet.AppErrLogID               = 0;
                    appErrLogController.Request            = new System.Net.Http.HttpRequestMessage();
                    appErrLogController.Request.RequestUri = new System.Uri("http://localhost:5000/api/appErrLog");
                    IHttpActionResult jsonRet3 = appErrLogController.Post(appErrLogRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <AppErrLog> appErrLogRet3 = jsonRet3 as CreatedNegotiatedContentResult <AppErrLog>;
                    Assert.IsNotNull(appErrLogRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = appErrLogController.Delete(appErrLogRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <AppErrLog> appErrLogRet4 = jsonRet4 as OkNegotiatedContentResult <AppErrLog>;
                    Assert.IsNotNull(appErrLogRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
        public void AppErrLog_Controller_GetAppErrLogList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    AppErrLogController appErrLogController = new AppErrLogController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(appErrLogController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, appErrLogController.DatabaseType);

                    AppErrLog appErrLogFirst = new AppErrLog();
                    int       count          = -1;
                    Query     query          = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        AppErrLogService appErrLogService = new AppErrLogService(query, db, ContactID);
                        appErrLogFirst = (from c in db.AppErrLogs select c).FirstOrDefault();
                        count          = (from c in db.AppErrLogs select c).Count();
                        count          = (query.Take > count ? count : query.Take);
                    }

                    // ok with AppErrLog info
                    IHttpActionResult jsonRet = appErrLogController.GetAppErrLogList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <AppErrLog> > ret = jsonRet as OkNegotiatedContentResult <List <AppErrLog> >;
                    Assert.AreEqual(appErrLogFirst.AppErrLogID, ret.Content[0].AppErrLogID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <AppErrLog> appErrLogList = new List <AppErrLog>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        AppErrLogService appErrLogService = new AppErrLogService(query, db, ContactID);
                        appErrLogList = (from c in db.AppErrLogs select c).OrderBy(c => c.AppErrLogID).Skip(0).Take(2).ToList();
                        count         = (from c in db.AppErrLogs select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with AppErrLog info
                        jsonRet = appErrLogController.GetAppErrLogList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <AppErrLog> >;
                        Assert.AreEqual(appErrLogList[0].AppErrLogID, ret.Content[0].AppErrLogID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with AppErrLog info
                            IHttpActionResult jsonRet2 = appErrLogController.GetAppErrLogList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <AppErrLog> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <AppErrLog> >;
                            Assert.AreEqual(appErrLogList[1].AppErrLogID, ret2.Content[0].AppErrLogID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }