Example #1
0
        public Log GetByID(int LogID)
        {
            Log LogEntity = null;
            Logqso.mvc.DataModel.LogData.DataModels.Log Log = null;
            //LogRepository LogRepository1 = new LogRepository();
            //LogDto  LogDto = LogRepository1.GetByID(LogCallsignID);
           // dependency injection

            Log = _logRepository.GetByID(LogID);

#if noautomap
            var log = new Log();
            log.LogID = LogDto.LogID;
            log.CallsignID = LogDto.CallsignID;
            log.ContestYear = LogDto.ContestYear;
            log.ContestID = LogDto.ContestID;
#else
            if (Log == null)
            {
                LogNotFoundException LogNotFoundException = new LogNotFoundException("Log does not exist for ");
                LogNotFoundException.LogID = LogID; 
                throw LogNotFoundException;
            }else {
                LogEntity = AutoMapper.Mapper.Map<Logqso.mvc.DataModel.LogData.DataModels.Log, Log>(Log);
            }
#endif
            return LogEntity;
        }
         public void Unit_LogNotFoundException_DefaultConstructor_ValidException()
         {

             //arrange
             bool caught = false;
             LogNotFoundException e = new LogNotFoundException();
             e.LogID = LogId;

             try
             {
                 throw e;
             }
             catch (LogNotFoundException ex)
             {
                 Assert.IsTrue(ex.LogID == LogId);
                 Assert.IsTrue(ex.InnerException == null);
                 Assert.IsTrue(ex.Message.Length > 0);
                 Assert.IsTrue(ex.Source.Length > 0);
                 Assert.IsTrue(ex.StackTrace.Length > 0);
                 Assert.IsTrue(ex.TargetSite.Module.Name.Length > 0);
                 Assert.IsTrue(ex.TargetSite.Name.Length > 0);
                 caught = true;
             }

             Assert.IsTrue(caught);
         }
         public void Unit_LogNotFoundException_MessageConstructor_ValidException()
         {

             //arrange
             bool caught = false;
             var message1 = StringOps.GetRandomString(60);
             LogNotFoundException e = new LogNotFoundException(message1);
             e.LogID = LogId;

             try
             {
                 throw e;
             }
             catch (LogNotFoundException ex)
             {
                 Assert.IsTrue(ex.Message.Contains(message1));
                 Assert.IsTrue(ex.LogID == LogId);
                 Assert.IsTrue(ex.InnerException == null);
                 Assert.IsTrue(ex.Message.Length > 0);
                 Assert.IsTrue(ex.Source.Length > 0);
                 Assert.IsTrue(ex.StackTrace.Length > 0);
                 Assert.IsTrue(ex.TargetSite.Module.Name.Length > 0);
                 Assert.IsTrue(ex.TargetSite.Name.Length > 0);
                 caught = true;
             }

             Assert.IsTrue(caught);
         }
         public void Unit_LogNotFoundException_Serialization_ValidLogID()
        {
            //http://blog.gurock.com/articles/creating-custom-exceptions-in-dotnet/
            LogNotFoundException e = new LogNotFoundException();
            e.LogID = LogId;

            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, e);
                s.Position = 0; // Reset stream position
                e = (LogNotFoundException)formatter.Deserialize(s);
            }

            Assert.AreEqual<int>(LogId, e.LogID);
        }