public void Integration_LogDataContext_LogService_Log_GetLogById_Return_Log()
        {
            Logqso.mvc.Entities.LogDataEntity.Log LogforId1 = null;
            // context object LogDataContext matches the same name used for LogqsoData DB
            using (IDataContextAsync context = new ContestqsoDataContext())
            //IUnitOfWorkDataAsync and UnitOfWorkData are used in order for Dependency Injection to inject the DataDB
            using (IUnitOfWorkAsync unitOfWorkData = new UnitOfWork(context))
            {
                bool caught = false;
                IRepositoryAsync<Log> _logRepository = new Repository<Log>(context, unitOfWorkData);

                var logService = new LogService(_logRepository);
                try
                {
                    var Logtask= logService.GetLogById(LogId);
                    LogforId1 = Logtask.Result;
                  
                }
                catch (Exception ex)
                {
                    TestContext.WriteLine(string.Format("Integration_LogDataContext_LogService_Log_GetLogById_Return_Log exception {0}",ex.Message) );
                    caught = true;
                }
                Assert.IsFalse(caught);  //exception
                Assert.IsNotNull(LogforId1);
                Assert.IsInstanceOfType(LogforId1, typeof(Logqso.mvc.Entities.LogDataEntity.Log));
                Assert.AreEqual(LogId, LogforId1.LogId);
                Assert.IsInstanceOfType(LogforId1.ContestYear, typeof(DateTime));
                Assert.AreEqual( 1,LogforId1.CallsignId );

            }
        }
        public void Integration_LogControlContext_CreateControlCatOperator_ValidIndex_Exception_Duplicate_Key()
        {

            // Create new customer
            // context object LogControlContext matches the same name used for Logqso DB
            using (IDataContextAsync context = new ContestqsoContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                bool caught = false;
                IRepositoryAsync<CatOperator> CatOperatorRepository = new Repository<CatOperator>(context, unitOfWork);
                var CatOperator = new CatOperator
                {
                    CatOperatorEnum = (int)CatOperatorEnum.SINGLE_OP,
                    CatOprName = CatOprName,
                    Index = 2,
                    ObjectState = ObjectState.Added,
                };

                try
                {
                    CatOperatorRepository.Insert(CatOperator);
                    unitOfWork.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {

                }
                catch (System.Data.Entity.Core.UpdateException)
                {
                    //caught = true;
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException)
                {
                    caught = true;
                }

                Assert.IsTrue(caught);

            }


            ////  Query for newly created CatOperator by ID from a new context, to ensure it's not pulling from cache
            //using (IDataContextAsync context = new LogControlContext())
            //using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            //{
            //    IRepositoryAsync<CatOperator> CatOperatorRepository = new Repository<CatOperator>(context, unitOfWork);
            //    var Query = CatOperatorRepository.Query(c => c.CatOprName == CatOprName);
            //    var list = Query.Select(c=>c.CatOprName);
            //    //Query.Select().

            //    //var CatOperator1 = (CatOperatorRepository.Query(c => c.CatOprName == CatOprName);
            //    //if (CatOperator1 != null)
            //    //{
            //    //    var CatOperator2 = CatOperatorRepository.Find(CatOperator1);
            //    //    Assert.AreEqual(CatOperator2.CatOprName, CatOprName);
            //    //}
            //    //Assert.AreEqual(CatOperator1.CatOprName, CatOprName); 
            //}

        }
Exemplo n.º 3
0
        /// <summary>
        /// We dont want to have to deal with the complexity of using databases at this stage.
        /// This basic setup allows us to have an in memory database of sorts without adding 
        /// </summary>
        private static void StartupConfig()
        {
            UnitOfWork = new UnitOfWork(new InMemoryRepository());
            PolicyService = new PolicyApplicationService(UnitOfWork);

            PolicyService.CreatePolicy("0011", 20000);
            PolicyService.CreatePolicy("0011", 1000);
        }
Exemplo n.º 4
0
        /// <summary>
        /// We dont want to have to deal with the complexity of using databases at this stage.
        /// This basic setup allows us to have an in memory database of sorts without adding 
        /// </summary>
        private static void StartupConfig()
        {
            UnitOfWork = new UnitOfWork(new InMemoryRepository());
            PolicyService = new PolicyApplicationService(UnitOfWork);

            PolicyService.CreatePolicy(Guid.Parse("EBA620CF-3414-4F72-997F-0F956D33377A"), "0011", 20000);
            PolicyService.CreatePolicy(Guid.Parse("EBA620CF-3414-4F72-997F-0F956D33377B"), "0011", 1000);
        }
        public void Integration_LogControlContext_CreateControlCatOperator_NoIndex_Exception()
        {

            // Create new customer
            // context object LogControlContext matches the same name used for Logqso DB
            using (IDataContextAsync context = new ContestqsoContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                bool caught = false;
                IRepositoryAsync<CatOperator> CatOperatorRepository = new Repository<CatOperator>(context, unitOfWork);
                var CatOperator = new CatOperator
                {
                    CatOperatorEnum = (int)CatOperatorEnum.SINGLE_OP,
                    CatOprName = CatOprName,
                    ObjectState = ObjectState.Added,
                };

                try
                {
                    CatOperatorRepository.Insert(CatOperator);
                    unitOfWork.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException)
                {

                }
                catch (System.Data.Entity.Core.UpdateException)
                {
                    //caught = true;
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException)
                {
                    caught = true;
                }

                Assert.IsTrue(caught);
            }
        }
        public void Integration_LogDataContext_LogService_Query_Log_Include_LogCategory_Return_LogCategories()
        {
            List<Logqso.mvc.Entities.LogDataEntity.Log> LogforId1s = null;
            // context object LogDataContext matches the same name used for LogqsoData DB
            using (IDataContextAsync context = new ContestqsoDataContext())
            //IUnitOfWorkDataAsync and UnitOfWorkData are used in order for Dependency Injection to inject the DataDB
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                bool caught = false;
                IRepositoryAsync<Log> _logRepository = new Repository<Log>(context, unitOfWork);

                var logService = new LogService(_logRepository);
                try
                {
                    var Logtask = logService.Query(x => x.LogId == 1)
                    .Include(x => x.LogCategory)
                    .Select();

                    LogforId1s = Logtask.ToList();
                }
                catch (Exception ex)
                {
                    TestContext.WriteLine(string.Format("Integration_LogDataContext_LogService_Log_GetLogById_Return_Log exception {0}", ex.Message));
                    caught = true;
                }
                Assert.IsFalse(caught);  //exception
                Assert.IsNotNull(LogforId1s);
                Assert.IsTrue(LogforId1s.Count > 0);
                Assert.IsInstanceOfType(LogforId1s[0], typeof(Logqso.mvc.Entities.LogDataEntity.Log));
                Assert.AreEqual(LogId, LogforId1s[0].LogId );
                Assert.IsInstanceOfType(LogforId1s[0].ContestYear, typeof(DateTime));
                Assert.AreEqual(1, LogforId1s[0].CallsignId );
                Assert.IsNotNull(LogforId1s[0].LogCategory);

            }
        }
Exemplo n.º 7
0
 public PolicyApplicationService(UnitOfWork unitOfWork)
 {
     this.unitOfWork = unitOfWork;
 }
        public void Integration_ControlService_GetsAsync()
        {
            using (IDataContextAsync context = new ContestqsoContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                IRepositoryAsync<FiltPrefix> FiltCountryRepository = new Repository<FiltPrefix>(context, unitOfWork);
                //Service.Pattern.IService<FiltCountry> CountryService = new Service.Pattern.Service<FiltCountry>(CatOperatorRepository);

                //var asyncTask = ContolService
                //    .Query(x => x.Country == "United States")
                //    .Include(x => x
                //        .Orders
                //        .Select(y => y.OrderDetails))
                //    .OrderBy(x => x
                //        .OrderBy(y => y.CompanyName)
                //        .ThenBy(z => z.ContactName))
                //    .SelectAsync();

                // var customers = asyncTask.Result;

                //Assert.IsTrue(customers.Count() > 1);
                //Assert.IsFalse(customers.Count(x => x.Country == "USA") == 0);
            }
        }
        public void Integration_ControlService_GetContestControlNamesAsync()
        {
            using (IDataContextAsync context = new ContestqsoContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                IRepositoryAsync<CatOperator> CatOperatorRepository = new Repository<CatOperator>(context, unitOfWork);
                IControlService ContolService = new ControlService(CatOperatorRepository);

                var asyncTask = ContolService.GetContestControlNames();
                var ContestControl = asyncTask.Result;

                Assert.IsTrue(ContestControl.ControlCategoryDto.CatOperator.Count > 1);
                Assert.IsTrue(ContestControl.ControlCategoryDto.CatAssisted.Count > 1);
                Assert.IsTrue(ContestControl.ControlCategoryDto.CatBand.Count > 1);
                Assert.IsTrue(ContestControl.ControlCategoryDto.CatNoOfTx.Count > 1);
                Assert.IsTrue(ContestControl.ControlCategoryDto.CatPower.Count > 1);
                Assert.IsTrue(ContestControl.ControlCategoryDto.CatOperator.Contains("SINGLE-OP"));
                
                Assert.IsTrue(ContestControl.ControlFiltersDto.FiltBand.Count > 1);
                Assert.IsTrue(ContestControl.ControlFiltersDto.FiltContinent.Count > 1);
                Assert.IsTrue(ContestControl.ControlFiltersDto.FiltCountryInnerHTML.Count > 1);
                Assert.IsTrue(ContestControl.ControlFiltersDto.FiltCQZone.Count > 1);

                Assert.IsTrue(ContestControl.ControlXaxisDto.XaxisDuration.Count > 1);
                Assert.IsTrue(ContestControl.ControlXaxisDto.XaxisStarttime.Count > 1);

                Assert.IsTrue(ContestControl.ControlYaxisDto.YaxisFunction.Count > 1);
                Assert.IsTrue(ContestControl.ControlYaxisDto.YaxisInterval.Count > 1);
                Assert.IsTrue(ContestControl.ControlYaxisDto.YaxisViewType.Count > 1);
            }
        }
        public async Task Integration_LogDataContext_LogService_Log_await_GetDataCallInfoSelectionsAsync_Return_DataCalls()
        {
            bool caught = false;
            // context object LogDataContext matches the same name used for LogqsoData DB
            using (IDataContextAsync context = new ContestqsoDataContext())
            //IUnitOfWorkDataAsync and UnitOfWorkData are used in order for Dependency Injection to inject the DataDB
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {

                IRepositoryAsync<Log> _logRepository = new Repository<Log>(context, unitOfWork);
                //Task<DataCalls> DataCalls = null;
                DataCalls DataCalls = null;
                string SelectedCall=  "CN2R";

                var logService = new LogService(_logRepository);
                try
                {


                    dataCallObjDTO dataCallObjDTO = new Dto.LogData.dataCallObjDTO()
                    {
                        ControlCategorySettingsDto = new   ControlCategorySettingsDto()
                        {
                            CatAssisted = Enum.GetName( typeof(CatAssistedEnum), CatAssistedEnum.ASSISTED ).Replace('_','-'),
                            CatBand = Enum.GetName( typeof(CatBandEnum), CatBandEnum.ALL ),
                            CatNoOfTx = Enum.GetName( typeof(CatNoOfTxEnum), CatNoOfTxEnum.TWO ),
                            CatOperator = Enum.GetName(typeof(CatOperatorEnum), CatOperatorEnum.MULTI_OP).Replace('_', '-'),
                            CatPower = Enum.GetName( typeof(CatPowerEnum), CatPowerEnum.HIGH ),
                            CatOperatorOverlay = Enum.GetName( typeof(CatOperatorOverlayEnum), CatOperatorOverlayEnum.NONE )
                        },
                        DataCallInfoDto = new DataCallInfoDto()
                        {
                            CallGroup =   CallGroupEnum.CALL1,
                            SelectedCall =  SelectedCall,
                            SelectedContestName = "Cqww Ssb 2002"
                        },
                        CallTab = "C"
                    };

                    DataCalls = await logService.GetCategorizedCallsAsync(dataCallObjDTO, "default");
                    //GetCategorizedCallsAsync() is  async method of Logservice.
                    //awaut on logService.GetCategorizedCallsAsync() runs asynchronously
                    //converts return type Task<DataCalls> to DataCalls
                    //it will return a DataCalls

                    Assert.IsNotNull(DataCalls);
                    Assert.IsInstanceOfType(DataCalls, typeof(DataCalls) );
                    Assert.AreEqual(CallGroupEnum.CALL1, DataCalls.CallGroup );
                    Assert.AreEqual( "C", DataCalls.SelectedCall );
                    Assert.IsInstanceOfType(DataCalls.Calls, typeof(ICollection<CallGroupCall>));
                    Assert.AreNotEqual(0, DataCalls.Calls.Count() );
                    Assert.AreEqual( SelectedCall.Substring(0,1), DataCalls.Calls.ElementAt(0).Call.Substring(0,1) );
              }
                catch (Exception ex)
                {
                    TestContext.WriteLine(string.Format("Integration_LogDataContext_LogService_Log_await_GetDataCallInfoSelectionsAsync_Return_DataCalls exception {0}", ex.Message));
                    caught = true;
                }
                Assert.IsFalse(caught);  //exception

            }
        }
        [TestMethod]  //task is required for async TestMerhod return type. return type of void not supported
        public async Task Integration_LogDataContext_LogService_Log_await_GetDataCallInfoSelectionsAsync_Return_DataCallInfoDto()
        {
            bool caught = false;
            // context object LogDataContext matches the same name used for LogqsoData DB
            using (IDataContextAsync context = new ContestqsoDataContext())
            //IUnitOfWorkDataAsync and UnitOfWorkData are used in order for Dependency Injection to inject the DataDB
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {

                IRepositoryAsync<Log> _logRepository = new Repository<Log>(context, unitOfWork);

                var logService = new LogService(_logRepository);
                try
                {
                    List<DataCallInfoDto> Dtos = null;

                    //awaut cinverts Task<IEnumerable<DataCallInfoDto>> to IEnumerable<DataCallInfoDto>
                    IEnumerable<DataCallInfoDto> DataCallInfoDtos = await logService.GetDataCallInfoSelectionsAsync("default");
                    //GetDataCallInfoSelections() is  async method of Logservice.
                    //awaut on logService.GetDataCallInfoSelections() runs asynchronously
                    //converts return type toTask<IEnumerable<DataCallInfoDto>> to IEnumerable<DataCallInfoDto>
                    //it will return a IEnumerable<DataCallInfoDto>
                    //This must be converted to a List<DataCallInfoDto> that is used in the asseert.
                    Dtos = DataCallInfoDtos as List<DataCallInfoDto>;

                    Assert.IsNotNull(Dtos);
                    Assert.IsInstanceOfType(DataCallInfoDtos, typeof(IEnumerable<DataCallInfoDto>));
                    Assert.IsInstanceOfType(Dtos[0].RadioNames, typeof(ICollection<RadioNamestype>));
                    Assert.IsInstanceOfType(Dtos[0].StationNames, typeof(ICollection<StationNamestype>));
                    Assert.IsInstanceOfType(Dtos[0].ContestNames, typeof(ICollection<ContestNamestype>));
                    Assert.AreNotEqual(Dtos[0].SelectedCall, string.Empty);
                    var LogIDDto = Dtos.Where(x => x.LogId == 1).SingleOrDefault();
                    Assert.IsNotNull(LogIDDto);
                    Assert.AreEqual(1, LogIDDto.LogId );
                }
                catch (Exception ex)
                {
                    TestContext.WriteLine(string.Format("Integration_LogDataContext_LogService_Log_await_GetDataCallInfoSelections_Return_DataCallInfoDtoo exception {0}", ex.Message));
                    caught = true;
                }
                Assert.IsFalse(caught);  //exception

            }
        }
        public void Integration_LogDataContext_LogResository_Log_GetContestLogs_Return_LogPageDTO()
        {
             using (IDataContextAsync context = new ContestqsoDataContext())

             using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
             {
                 bool caught = false;
                 IRepositoryAsync<Log> _logRepository = new Repository<Log>(context, unitOfWork);
                 LogPageDTO LogPageDTO = null;

                 try
                 {
                     LogCtlDataSettingsDto LogCtlDataSettingsDto = new Dto.LogData.LogCtlDataSettingsDto()
                     {
                         ControlSettingsDto = new ControlSettingsDto()
                         {
                             ControlCategorySettingsDto = new Dto.LogControl.ControlCategorySettingsDto()
                             {
                                 CatAssisted = "ALL",
                                 CatBand = "ALL",
                                 CatNoOfTx = "ALL",
                                 CatOperator = "ALL",
                                 CatOperatorOverlay = null,
                                 CatPower = "ALL",
                                 Disabled = false
                             },
                             ControlFiltersSettingsDto = new Dto.LogControl.ControlFiltersSettingsDto()
                             {
                                 Disabled = false,
                                 FiltBand = "ALL",
                                 FiltContinent = "ALL",
                                 FiltCountryInnerHTML = new CountryPrefixtype
                                 {
                                     key = 8,
                                     value = "ALL&nbsp;&nbsp;&nbsp;&nbsp;-"
                                 },
                                 FiltCQZone = "ALL",
                             },
                             ControlXaxisSettingsDto = new Dto.LogControl.ControlXaxisSettingsDto()
                             {
                                 XaxisDuration = "48",
                                 XaxisStarttime = "00:00z  Day1",
                                 XaxisStarttimeIndex = 0
                             },
                             ControlYaxisSettingsDto = new Dto.LogControl.ControlYaxisSettingsDto()
                             {
                                 YaxisFunction = "QSO  Rate",
                                 YaxisFunctionIndex = 0,
                                 YaxisInterval = "60",
                                 YaxisViewType = "Column",
                             }
                             
                         },
                         DataCallInfoDtos = new DataCallInfoDto[]
                        {
                                new DataCallInfoDto()
                                {
                                    CallGroup = CallGroupEnum.CALL1,
                                    Disabled = false,
                                    LogId = 1,
                                    QsoRadioType = QsoRadioTypeEnum.R1,
                                    SelectedCall = "CN2R",
                                    SelectedContestName = "Cqww Ssb 2002",
                                    SelectedStationName = "STN1"
                                },
                                new DataCallInfoDto()
                                {
                                    CallGroup = CallGroupEnum.CALL2,
                                    Disabled = false,
                                    LogId= 2,
                                    QsoRadioType = QsoRadioTypeEnum.R2,
                                    SelectedCall = "CN3A",
                                    SelectedContestName = "Cqww Ssb 2002",
                                    SelectedStationName = "STN2"
                                },
                                new DataCallInfoDto()
                                {
                                    CallGroup = CallGroupEnum.CALL3,
                                    Disabled = false,
                                    LogId=3,
                                    QsoRadioType = QsoRadioTypeEnum.R1,
                                    SelectedCall = "CN2AA",
                                    SelectedContestName = "Cqww Ssb 2002",
                                    SelectedStationName = null,
                                },
                        },
                         LogPageRequestDTO = new LogPageRequestDTO()
                         {
                             sidx = "",
                             sord = "asc",
                             page = 1,
                             rows = 16,
                             _search = false
                         }

                     };

                     string username = "******";
                     LogPageDTO = _logRepository.GetContestLogs(LogCtlDataSettingsDto, username).Result;

                     //TestContext.WriteLine("Integration_LogDataContext_LogRepository_Query_Log_Include_LogCategory_Return_LogCategorie_Qsoes_Stations_Callsign exception");


                     //LogforId1s = Logtask as List<Log>;

                 }
                 catch (Exception ex)
                 {
                     TestContext.WriteLine(string.Format("Integration_LogDataContext_LogResository_Log_GetContestLogs_Return_LogPageDTO exception {0}", ex.Message));
                     caught = true;
                 }
                 Assert.IsFalse(caught);  //exception
             }
       }
        public void Integration_LogDataContext_LogRepository_Query_Log_Include_LogCategory_Return_LogCategory_Qsoes_Stations_CallSign()
        {
            //List<Logqso.mvc.Entities.LogDataEntity.Log> LogforId1s = null;
            // context object LogDataContext matches the same name used for LogqsoData DB
            using (IDataContextAsync context = new ContestqsoDataContext())
            //IUnitOfWorkDataAsync and UnitOfWorkData are used in order for Dependency Injection to inject the DataDB
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
            {
                bool caught = false;
                IRepositoryAsync<Log> _logRepository = new Repository<Log>(context, unitOfWork);
                Log Logtask = null;

                try
                {
                    Logtask = _logRepository.Query(x => x.LogId == 1)
                     .Include(x => x.Qsoes).Include(x=>x.Stations).Include(x=>x.LogCategory).Include(x=>x.CallSign)
                     .Select()
                     .SingleOrDefault();
                     
                    //TestContext.WriteLine("Integration_LogDataContext_LogRepository_Query_Log_Include_LogCategory_Return_LogCategorie_Qsoes_Stations_Callsign exception");


                    //LogforId1s = Logtask as List<Log>;

                }
                catch (Exception ex)
                {
                    TestContext.WriteLine(string.Format("Integration_LogDataContext_LogRepository_Query_Log_Include_LogCategory_Return_LogCategorie_Qsoes_Stations_Callsign exception {0}", ex.Message));
                    caught = true;
                }
                Assert.IsFalse(caught);  //exception
                Assert.IsNotNull(Logtask);
                Assert.IsInstanceOfType(Logtask, typeof(Logqso.mvc.Entities.LogDataEntity.Log));
                Assert.AreEqual(LogId, Logtask.LogId );
                Assert.IsInstanceOfType(Logtask.ContestYear, typeof(DateTime));
                Assert.AreEqual(1, Logtask.CallsignId );
                 Assert.IsNotNull(Logtask.LogCategory);
                 Assert.AreEqual(Logtask.LogCategory.CatBandEnum, (int)Logqso.mvc.common.Enum.CatBandEnum.ALL);
                Assert.IsNotNull(Logtask.Qsoes);

                Assert.AreEqual(2, Logtask.Qsoes.Count );
                Assert.IsNotNull(Logtask.Stations);
                Assert.AreEqual(4, Logtask.Stations.Count );
                Assert.IsNotNull(Logtask.CallSign);
                Assert.AreEqual( "CN2R", Logtask.CallSign.Call );

            }
        }