Esempio n. 1
0
        public void GetFlagsDoesNotAddUrgentCoverFlagToCoveredEvent()
        {
            var testEvent = GetTestEvent();

            var urgentThreshold = 15;

            var options = new FlagServiceOptions
            {
                UrgentCoverThreshold = urgentThreshold
            };

            testEvent.Date = DateTime.Today.AddDays(urgentThreshold - 1);
            testEvent.Deployments.Clear();
            testEvent.Deployments.Add(_fixture.Create <Deployment>());
            testEvent.Deployments.Add(_fixture.Create <Deployment>());
            testEvent.Deployments.Add(_fixture.Create <Deployment>());
            testEvent.CyclistsRequested = 3;
            testEvent.DateConfirmed     = true;

            var expectedFlag = Flags.UrgentCoverNeeded;

            var flagService = new FlagService(Options.Create(options));

            var actualFlag = flagService.GetFlags(testEvent, expectedFlag);

            actualFlag.Should().NotContain(expectedFlag);
        }
Esempio n. 2
0
        private async void CountrySearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            _cancellationTokenSource?.Cancel();

            _cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = _cancellationTokenSource.Token;

            try
            {
                await Task.Delay(500, cancellationToken);

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                var countries = await Task.Run(async() =>
                                               await FlagService.GetFlagsTask(e.NewTextValue), cancellationToken);

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                Device.BeginInvokeOnMainThread(() =>
                                               Countries.ReplaceRange(countries));
            }
            catch (OperationCanceledException)
            {
                // we cancelled so do nothing... (ugly!)
            }
        }
            public TestSetup()
            {
                var dataContext = new FakeDataContext();

                AnswerFlagsRepository           = new Repository <AnswerFlag>(dataContext);
                AnswerDescriptionFlagRepository = new Repository <AnswerDescriptionFlag>(dataContext);
                CacheMock         = new TestCacheManager().CacheMock;
                TestLoggerFactory = new TestLoggerFactory();

                AnswerDescriptionServiceMock = new Mock <IAnswerDescriptionService>();
                // Suppose we always adding answer 15
                AnswerDescriptionServiceMock.Setup(
                    x => x.FindByAnswerDescriptionId(It.IsAny <int>())
                    ).Returns(new AnswerDescriptionDto()
                {
                    AnswerId = EXISTING_ANSWER_ID
                });
                TestLoggerFactory = new TestLoggerFactory();

                FlagService = new FlagService(
                    AnswerDescriptionServiceMock.Object,
                    CacheMock.Object,
                    AnswerFlagsRepository,
                    AnswerDescriptionFlagRepository,
                    TestLoggerFactory);
            }
Esempio n. 4
0
        public void GetFlagsDoesNotAddBriefingNotesReadyIfEventIsDistant()
        {
            var testEvent = GetTestEvent();

            var notesThreshold = 14;

            var options = new FlagServiceOptions
            {
                SendBriefingNotesThreshold = notesThreshold
            };

            testEvent.Date = DateTime.Today.AddDays(notesThreshold + 1);
            testEvent.Schedule.Add(_fixture.Create <ScheduleItem>());
            testEvent.Deployments.Add(_fixture.Create <Deployment>());
            testEvent.ExpectedIncidents.Add(_fixture.Create <ExpectedIncident>());
            testEvent.BriefingNotesSent = false;

            var expectedFlag = Flags.BriefingNotesReady;

            var flagService = new FlagService(Options.Create(options));

            var actualFlag = flagService.GetFlags(testEvent, expectedFlag);

            actualFlag.Should().NotContain(expectedFlag);
        }
Esempio n. 5
0
        private async void CountrySearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            await Task.Delay(500);

            var countries = await FlagService.GetFlagsTask(e.NewTextValue);

            Device.BeginInvokeOnMainThread(() =>
                                           Countries.ReplaceRange(countries));
        }
Esempio n. 6
0
        public IHttpActionResult Update(int id, FlagModel flag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ResponseModel response = FlagService.UpdateFlag(id, flag);

            return(Ok(response));
        }
Esempio n. 7
0
        //Source: https://byteloom.marek-mierzwa.com/mobile/2018/06/18/search-as-you-type-in-xamarin-forms.html

        private async void CountrySearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            _cancellationTokenSource?.Cancel();

            if (e.NewTextValue.Length < 3 && searchTerm == e.NewTextValue)
            {
                return;
            }

            _cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = _cancellationTokenSource.Token;

            try
            {
                await Task.Delay(500, cancellationToken);

                searchTerm = e.NewTextValue;

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                var timeoutTask   = Task.Delay(TimeSpan.FromSeconds(30), cancellationToken);
                var countriesTask = Task.Run(async() => await FlagService.GetFlagsTask(e.NewTextValue),
                                             cancellationToken);

                if (await Task.WhenAny(countriesTask, timeoutTask) == timeoutTask)
                {
                    throw new TimeoutException();
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                var countries = await countriesTask;

                Device.BeginInvokeOnMainThread(() =>
                                               Countries.ReplaceRange(countries));
            }
            catch (OperationCanceledException)
            {
                // we cancelled so do nothing... (ugly!)
            }
            catch (TimeoutException timeoutEx)
            {
                //Handle timeout here...
                Console.WriteLine("Timeout!");
            }
        }
Esempio n. 8
0
        public IHttpActionResult Create(FlagModel flag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            ResponseModel response = FlagService.CreateFlag(flag);

            return(Ok(response));
            //return Ok(customerFake);
        }
Esempio n. 9
0
        /// <summary>
        /// Binds data contexts ASAP to prevent flickering.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            SettingsService.Upgrade();

            // Network tasks
            Task.Run(async() => { await FlagService.CheckAllFlags(); });
            Task.Run(async() => { await UpdateService.CheckForUpdates(); });

            // Bind data contexts
            DataContext = _styleBinding;
            AppraisalInfo.DataContext     = _infoBinding;
            AppraisalControls.DataContext = _controlsBinding;
        }
Esempio n. 10
0
        public void GetFlagsAddsBriefingNotesSentIfBriefingHasBeenSent()
        {
            var testEvent = GetTestEvent();

            var options = new FlagServiceOptions();

            testEvent.BriefingNotesSent = true;

            var expectedFlag = Flags.BriefingNotesSent;

            var flagService = new FlagService(Options.Create(options));

            var actualFlag = flagService.GetFlags(testEvent, expectedFlag);

            actualFlag.Should().Contain(expectedFlag);
        }
Esempio n. 11
0
        private static void Main(string[] args)
        {
            CountryDBSettings countryDBSettings = new CountryDBSettings()
            {
                ConnectionString = "mongodb://127.0.0.1:27017",
                DatabaseName     = "CountryDB"
            };

            FlagService    flagService    = new FlagService(countryDBSettings);
            CountryService countryService = new CountryService(countryDBSettings);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var dataSeeding = new Seeding(countryService, flagService);

            dataSeeding.Run();
            sw.Stop();

            Console.WriteLine($"Load Complete : {sw.Elapsed.TotalSeconds}");

            Console.ReadKey();
        }
Esempio n. 12
0
        public void GetFlagsAddsNeedsEmailingToSoonEventNotRecentlyEmailed()
        {
            var testEvent = GetTestEvent();

            var sendEmailThreshold    = 90;
            var emailCautionThreshold = 45;

            var options = new FlagServiceOptions
            {
                SendEmailThreshold    = sendEmailThreshold,
                EmailCautionThreshold = emailCautionThreshold
            };

            testEvent.Date           = DateTime.Today.AddDays(sendEmailThreshold - 1);
            testEvent.LastEmailedOut = DateTime.Today.AddDays(-(emailCautionThreshold + 1));

            var expectedFlag = Flags.NeedsEmailing;

            var flagService = new FlagService(Options.Create(options));

            var actualFlag = flagService.GetFlags(testEvent, expectedFlag);

            actualFlag.Should().Contain(expectedFlag);
        }
Esempio n. 13
0
 public SetFlagCommandProcessor(FlagService flagService
                                , LineService lineService) : base(Keyword.SetFlag, lineService)
 {
     _flagService = flagService;
     _lineService = lineService;
 }
Esempio n. 14
0
        public IHttpActionResult Delete(int id)
        {
            ResponseModel response = FlagService.DeleteFlag(id);

            return(Ok(response));
        }
Esempio n. 15
0
 public SeedingController(CountryService countryService, FlagService flagService)
 {
     _countryService = countryService;
     _flagService    = flagService;
     _seeding        = new Seeding(_countryService, _flagService);
 }
Esempio n. 16
0
        public IHttpActionResult Flags(int id)
        {
            ResponseModel response = FlagService.SelectFlags(id);

            return(Ok(response));
        }
Esempio n. 17
0
 public FlagController(FlagService flagService)
 {
     _flagService = flagService;
 }
Esempio n. 18
0
 public Seeding(CountryService countryService, FlagService flagService)
 {
     _countryService = countryService;
     _flagService    = flagService;
 }