public void Setup()
 {
     jokeService = new JokeService();
     testJoke    = new HashSet <string> {
         "this is a test joke with name Chuck Norris that should be replaced."
     };
 }
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            try
            {
                var item = args.SelectedItem as Joke;
                if (item == null)
                {
                    return;
                }

                if (CrossConnectivity.Current.IsConnected)
                {
                    var _jokeService = new JokeService();
                    item = await _jokeService.GetJoke(item.JokeID, false);
                }
                if (this.UserID < 0)
                {
                    await Navigation.PushAsync(new ItemDetailPage(new JokeDetailViewModel(item)));
                }
                else
                {
                    await Navigation.PushAsync(new ItemDetailPage(new JokeDetailViewModel(item), UserID));
                }

                // Manually deselect item
                ItemsListView.SelectedItem = null;
            }
            catch (Exception)
            {
                Navigation.InsertPageBefore(new ItemsPage(), this);
                await Navigation.PopAsync();
            }
        }
        public async void OnDelete(object sender, EventArgs e)
        {
            var joke = jokeModel.Item as Joke;

            btnDelete.IsEnabled = false;
            if (UserID > 0)
            {
                bool accepted = await DisplayAlert("Delete Context Action", joke.Title + " delete context action", "OK", "Cancel");

                if (accepted)
                {
                    var _jokeService = new JokeService();
                    int result       = await _jokeService.DeleteAsync(joke.JokeID);

                    if (result == -2)
                    {
                        await DisplayAlert("No internet connection", "You must be online!", "Ok");
                    }
                    else if (result == 0)
                    {
                        await DisplayAlert("Error", "We are sorry! An error has occured!", "Ok");
                    }
                    else
                    {
                        MessagingCenter.Send(this, "DeleteJoke", joke);
                        //await Navigation.PopToRootAsync();
                        Navigation.InsertPageBefore(new ItemsPage(UserID), this);
                        await Navigation.PopAsync();
                    }
                }
            }
            btnDelete.IsEnabled = true;
        }
        public async Task Joke(IDialogContext context, LuisResult result)
        {
            //TODO - remove dependency
            IJokeService joke = new JokeService();

            await context.PostAsync(await joke.GetRandomJoke());

            context.Wait(MessageReceived);
        }
 public ProgramRunner(
     UserInteractions userInteractions,
     JokeRepository jokeRepository,
     NameRepository nameRepository,
     JokeService jokeService)
 {
     this.userInteractions = userInteractions;
     this.jokeRepository   = jokeRepository;
     this.nameRepository   = nameRepository;
     this.jokeService      = jokeService;
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            getJoke.TouchUpInside += async(sender, e) =>
            {
                var jokeService = new JokeService();

                jokeText.Text = (await jokeService.GetJoke()).Joke;
            };
        }
        public JokeDetailViewModel(Joke item = null)
        {
            Title = item?.Title;
            Item  = item;

            MessagingCenter.Subscribe <ItemDetailPage, string>(this, "LikeJoke", async(obj, jokeid) =>
            {
                var _jokeService = new JokeService();
                var joke         = await _jokeService.GetJoke(jokeid, true);
                item.NoLikes     = joke.NoLikes;
                item.NoUnlikes   = joke.NoUnlikes;
            });
        }
        async void CheckStatus(Object state)
        {
            TimerExampleState s = (TimerExampleState)state;

            s.counter++;
            Console.WriteLine("{0} Checking Status {1}.", DateTime.Now.TimeOfDay, s.counter);

            var jokeid       = jokeModel.Item.JokeID;
            var _jokeService = new JokeService();
            var joke         = await _jokeService.GetJoke(jokeid, true);

            this.jokeModel.Item.NoLikes   = joke.NoLikes;
            this.jokeModel.Item.NoUnlikes = joke.NoUnlikes;
        }
        protected async void CallMethodForLike(bool isLike)
        {
            var jokeid       = jokeModel.Item.JokeID;
            var _jokeService = new JokeService();
            var result       = await _jokeService.LikeOrUnlike(isLike, jokeid);

            if (result)
            {
                //MessagingCenter.Send(this, "LikeJoke", jokeid);
                var joke = await _jokeService.GetJoke(jokeid, true);

                this.jokeModel.Item.NoLikes   = joke.NoLikes;
                this.jokeModel.Item.NoUnlikes = joke.NoUnlikes;
            }
        }
Exemple #10
0
        public void GetCountsShouldReturnCorrectNumber()
        {
            var jokesRepository = new Mock <IRepository <Joke> >();

            jokesRepository.Setup(r => r.All()).Returns(new List <Joke>
            {
                new Joke(),
                new Joke(),
                new Joke()
            }
                                                        .AsQueryable());

            var service = new JokeService(jokesRepository.Object, null);

            Assert.Equal(3, service.GetCount());
        }
        public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.JokeFragment, container, false);

            var getJoke = view.FindViewById <Android.Widget.Button>(Resource.Id.getJoke);

            getJoke.Click += async(sender, e) =>
            {
                var jokeText = view.FindViewById <Android.Widget.TextView>(Resource.Id.joke);

                var jokeService = new JokeService();
                jokeText.Text = (await jokeService.GetJoke()).Joke;
            };

            return(view);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var getJoke  = FindViewById <Button>(Resource.Id.getJoke);
            var jokeText = FindViewById <TextView>(Resource.Id.jokeText);

            //1. Handle event
            getJoke.Click += async(sender, e) =>
            {
                var jokeService = new JokeService();
                var theJoke     = await jokeService.GetJoke();

                jokeText.Text = theJoke.Joke;
            };
        }
Exemple #13
0
        public async Task GetCountShouldReturnCorrectNumberUsingDbContext()
        {
            var options = new DbContextOptionsBuilder <FunAppContext>()
                          .UseInMemoryDatabase(databaseName: "Find_User_Database")
                          .Options;

            var dbContext = new FunAppContext(options);

            dbContext.Jokes.Add(new Joke());
            dbContext.Jokes.Add(new Joke());
            dbContext.Jokes.Add(new Joke());
            await dbContext.SaveChangesAsync();

            var repository  = new DbRepository <Joke>(dbContext);
            var jokeService = new JokeService(repository, null);
            var count       = jokeService.GetCount();

            Assert.Equal(3, count);
        }
 public WindowsBackgroundService(
     JokeService jokeService,
     ILogger <WindowsBackgroundService> logger) =>
 (_jokeService, _logger) = (jokeService, logger);
        // GET: JokeController
        public async Task <IActionResult> Index(JokeService jokeService, int amount = 10)
        {
            List <Joke> jokes = await jokeService.getJokes(amount);

            return(View(jokes));
        }
 public BotCommandManager(TelegramBotClient bot, MessageService messageService, JokeService jokeService)
 {
     _messageService = messageService;
     _jokeService    = jokeService;
     _bot            = bot;
 }
Exemple #17
0
 public JokeModule(JokeService jokeService, IStringLocalizer <General> localizer)
 {
     _jokeService = jokeService;
     _localizer   = localizer;
 }
Exemple #18
0
 public WindowsBackgroundService(
     JokeService jokeService,
     KillProcessService killProcessService,
     ILogger <WindowsBackgroundService> logger) =>
 (_jokeService, _killProcessService, _logger) = (jokeService, killProcessService, logger);
        public JokeServiceTests()
        {
            _mockJokeLogic = new Mock <IJokeLogic>();

            _objectToTest = new JokeService(_mockJokeLogic.Object);
        }
Exemple #20
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector = null;
                try
                {
                    connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                    // calculate something for us to return
                    var faceTraits = new List <Trait>();
                    // return our reply to the user


                    if (activity.Attachments.Count == 1)
                    {
                        FaceConnector faceConnector = new FaceConnector();
                        var           faces         = await faceConnector.UploadAndDetectFaces(activity);

                        if (faces.Length > 0)
                        {
                            faceTraits = FaceAnalizer.GetTraitsFromFace(faces[0]);
                        }
                        else
                        {
                            await connector.Conversations.ReplyToActivityAsync(activity.CreateReply("You're so dumb, you can't even take a selfie"));

                            return(Request.CreateResponse(HttpStatusCode.OK));;
                        }


                        var jokeService = new JokeService();
                        var joke        = jokeService.GetJoke(faceTraits);

                        Activity reply = activity.CreateReply(joke);
                        await connector.Conversations.ReplyToActivityAsync(reply);
                    }
                    else
                    {
                        JObject r = await WatsonService.TalkToWatson(activity.Text, activity.Conversation.Id);

                        Dictionary <string, double> map = new Dictionary <string, double>();
                        foreach (JObject entity in r["entities"])
                        {
                            map[entity["value"].Value <string>()] = entity["confidence"].Value <double>();
                        }
                        if (map.Keys.Count > 0)
                        {
                            var jokeService = new JokeService();
                            var joke        = jokeService.GetJoke(new List <Trait> {
                                new Trait {
                                    Name = map.Keys.First(), Accuracy = 1.0
                                }
                            });

                            Activity reply = activity.CreateReply($"{joke}");
                            await connector.Conversations.ReplyToActivityAsync(reply);
                        }

                        //var entities = ((IEnumerable<object>)r.Result).ToList()[1];
                        // var replyText = ((Newtonsoft.Json.Linq.JProperty )entities);
                    }
                    // faceConnector.UploadAndDetectFaces(activity.Attachments)
                }

                catch (Exception ex)
                {
                    if (connector != null)
                    {
                        Activity reply = activity.CreateReply(ex.Message);
                        await connector.Conversations.ReplyToActivityAsync(reply);
                    }
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }