Inheritance: MonoBehaviour
Beispiel #1
0
    //private float testCounter;
    //private float testIterative;

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
    }
Beispiel #2
0
        public async void BulkInsert_No_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

            var mockResponse = new CreateResponse <ApiTweetResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiTweetResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTweetRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTweetResponseModel> >(mockResponse));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiTweetRequestModel>();

            records.Add(new ApiTweetRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as List <ApiTweetResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTweetRequestModel>()));
        }
Beispiel #3
0
        public async void Patch_No_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiTweetResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiTweetRequestModel>()))
            .Callback <int, ApiTweetRequestModel>(
                (id, model) => model.Content.Should().Be("A")
                )
            .Returns(Task.FromResult <UpdateResponse <ApiTweetResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTweetResponseModel>(new ApiTweetResponseModel()));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiTweetModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiTweetRequestModel>();

            patch.Replace(x => x.Content, "A");

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiTweetRequestModel>()));
        }
Beispiel #4
0
        public List <TweetModel> GetValueSets(params TweetModel[] content)
        {
            var controller = new TweetController();
            var viewModels = controller.GetAllTweets();

            List <TweetModel> FetchTweets = new List <TweetModel>();

            foreach (var tweet in viewModels)
            {
                FetchTweets.Add(new TweetModel()
                {
                    Username       = tweet.Username,
                    Avatar         = tweet.Avatar,
                    Content        = tweet.Content,
                    ScreenName     = tweet.ScreenName,
                    TweetedOn      = tweet.TweetedOn,
                    NumberOfTweets = FetchTweets.Count(),
                    ReplyToTweet   = tweet.ReplyToTweet,
                    Url            = tweet.Url
                });
            }
            ;

            return(FetchTweets);
        }
        public void Return_View_When_Provided_Correct_Parameter()
        {
            //Arrange
            var apiCallerServiceMock     = new Mock <ITwitterApiCallService>();
            var tweetServiceMock         = new Mock <ITweetService>();
            var followeeServiceMock      = new Mock <IFolloweeService>();
            var userManagerMock          = MockUserManager.New;
            var userTweetServiceMock     = Mock.Of <IUserTweetService>();
            var cascadeDeleteServiceMock = Mock.Of <ICascadeDeleteService>();
            var sut = new TweetController(apiCallerServiceMock.Object, tweetServiceMock.Object, userManagerMock.Object,
                                          userTweetServiceMock, cascadeDeleteServiceMock, followeeServiceMock.Object);

            var tweetFromApiCollection = new[] { new TweetFromApiDto(), new TweetFromApiDto() };

            apiCallerServiceMock.Setup(s => s.GetTweetsByUserId(It.IsAny <string>())).Returns(tweetFromApiCollection);

            //Act
            var result = sut.TweetSearchResult("123");

            // Assert
            result
            .Should()
            .BeOfType <ViewResult>()
            .Subject
            .Model
            .Should()
            .Match(m => m.As <TweetSearchResultViewModel>().TweetSearchResults == tweetFromApiCollection);
        }
Beispiel #6
0
    private void InstantiateTweetObject(Tweet t, Vector3 worldPosition)
    {
        GameObject tweetObj = Instantiate(_tweetPrefab);
        Bounds     bounds   = GetOrthographicBoundsForCamera(Camera.main);

        // Set the parent and position of the Tweet
        tweetObj.transform.SetParent(_tweetContainer);

        float scale = UnityEngine.Random.Range(0.9f, 1.5f);

        tweetObj.transform.localScale = new Vector3(scale, scale, 1.0f);

        // Get a position on a circular path around the world position and clamp to scene
        Vector3 tweetSpriteExtents = tweetObj.GetComponent <SpriteRenderer> ().sprite.bounds.extents;
        Vector3 position           = GetRandomPointOnCircle(worldPosition,
                                                            UnityEngine.Random.Range(0.0f, Mathf.PI * 2.0f),
                                                            2.0f);

        tweetObj.transform.position =
            new Vector3(Mathf.Clamp(position.x, bounds.min.x + tweetSpriteExtents.x, bounds.max.x - tweetSpriteExtents.x),
                        Mathf.Clamp(position.y, bounds.min.y + tweetSpriteExtents.y, bounds.max.y - tweetSpriteExtents.y),
                        0.0f);

        // Set the Tweet content including the background sprite
        TweetController tweetController = tweetObj.GetComponent <TweetController> ();

        tweetController.Title.text            = t.Author;
        tweetController.Description.text      = t.Description;
        tweetController.PubDate.text          = t.PubDate;
        tweetController.SpriteRenderer.sprite = _tweetBackgrounds[UnityEngine.Random.Range(0, _tweetBackgrounds.Count)];
    }
Beispiel #7
0
    public void Yes()
    {
        TweetController tc;

        if (TweetController.TryGetManager(out tc))
        {
            tc.YesButton();
        }
    }
Beispiel #8
0
        public void that_saving_a_tweet_over_140_chars_()
        {
            TweetController classUnderTest = new TweetController();
            Tweet           tweet          = new Tweet()
            {
            };

            classUnderTest.Tweet(tweet);
        }
Beispiel #9
0
    public void No()
    {
        TweetController tc;

        if (TweetController.TryGetManager(out tc))
        {
            tc.NoButton();
        }
    }
    public static bool TryGetManager(out TweetController manager)
    {
        manager = instance;
        if (instance == null)
        {
            Debug.LogError("Trying to access TweetController when no TweetController is in the scene");
        }

        return(instance != null);
    }
        public void TweetsResultsNotNull()
        {
            // Arrange
            TweetController controller = new TweetController();

            // Act
            ViewResult result = controller.Tweets() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void TweetsAsyncEndDateGreaterThanEqualStartDate()
        {
            // Arrange
            TweetController controller = new TweetController();

            // Act
            ViewResult result = controller.TweetsAsync() as ViewResult;

            // Assert
            //Assert.AreEqual("TweetsAsync", result.ViewBag.Title);
            Assert.IsTrue(result.ViewBag.endDate >= result.ViewBag.startDate);
        }
Beispiel #13
0
        public void Get_CorrectLink_TweetString()
        {
            //Arrange
            string          tweetLink       = "https://twitter.com/tweeter/status/489879052157595649";
            string          expected        = "Stay safe. Love one another. Life is hard for everyone, so spread peace and happiness. #tweetlove";
            TweetController tweetController = new TweetController();

            //Act
            var result = tweetController.Get(tweetLink);

            //Assert
            Assert.AreEqual(expected, result.Result);
        }
Beispiel #14
0
        public void GetAllTweetsSqlDB()
        {
            //Arrange
            var expectedResultSQL = new string[] { "Tweet1", "Tweet2", "Tweet3" };
            var mySqlDatabase     = new SqlDatabase();
            var tweetController   = new TweetController(mySqlDatabase);

            //Act
            var result = tweetController.Get();

            // Assert
            Assert.Equal(expectedResultSQL, result);
        }
Beispiel #15
0
        public void GetAllTweetsMongoDB()
        {
            //Arrange

            var expectedResultMongo = new string[] { "sheep", "pencilcase" };
            var myMongoDB           = new Repository();
            var tweetController     = new TweetController(myMongoDB);

            //Act
            var result = tweetController.Get();

            // Assert
            Assert.Equal(expectedResultMongo, result);
        }
Beispiel #16
0
        public void GetAll_CorrectLink_TweetsStringListFormat()
        {
            //Arrange
            string          username        = "******";
            TweetController tweetController = new TweetController();
            Regex           rx = new Regex(@"^\[.*\]$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            //Act
            var             result  = tweetController.GetAll(username).Result;
            MatchCollection matches = rx.Matches(result);

            //Assert
            Assert.IsInstanceOfType(result, typeof(string));
            Assert.IsTrue(matches.Count != 0);
        }
Beispiel #17
0
        public void PostATweet_WhenPosted_ShouldReturnOKstatusCode()
        {
            //Arrange

            var mySqlDatabase   = new SqlDatabase();
            var tweetController = new TweetController(mySqlDatabase);
            var blogPost        = GetValidPost();


            //Act
            var result = tweetController.Post(blogPost);

            //Assert
            Assert.IsType <OkObjectResult>(result);
        }
        private void Login(object sender, EventArgs e)
        {
            var tweetController = new TweetController();
            var cookie          = tweetController.Login(tvLogin.Text, tvPassword.Text);

            if (cookie != null)
            {
                var intent = new Intent(this, typeof(LogoutActivity));
                intent.PutExtra("Cookie", cookie);
                StartActivity(intent);
            }
            else
            {
                Toast.MakeText(this, "Login failed. Try again!!!", ToastLength.Short).Show();
            }
        }
Beispiel #19
0
        public async void Get_Not_Exists()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTweetResponseModel>(null));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #20
0
        public void PostATweet_WhenPosted_ShouldReturnSameString()
        {
            //Arrange

            var mySqlDatabase   = new SqlDatabase();
            var tweetController = new TweetController(mySqlDatabase);
            var blogPost        = GetValidPost();
            var expectedResult  = blogPost.Content;

            //Act
            var result = tweetController.Post(blogPost);
            var model  = result as OkObjectResult;

            //Assert
            Assert.Equal(expectedResult, model.Value);
        }
Beispiel #21
0
        public async void Delete_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
Beispiel #22
0
        public async void Update_NotFound()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiTweetResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiTweetRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiTweetResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTweetResponseModel>(null));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiTweetModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Update(default(int), new ApiTweetRequestModel());

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #23
0
        public async void All_Not_Exists()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiTweetResponseModel> >(new List <ApiTweetResponseModel>()));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiTweetResponseModel>;

            items.Should().BeEmpty();
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        public void CreateInstance_WhenInvokedWithValidParameters()
        {
            //Arrange
            var tweetServiceMock    = new Mock <ITweetService>();
            var mappingProviderMock = new Mock <IMappingProvider>();
            var userManagerMock     = MockUserManager <User>();


            //Act
            var controller =
                new TweetController
                (
                    tweetServiceMock.Object,
                    userManagerMock.Object,
                    mappingProviderMock.Object);

            //Assert
            Assert.IsNotNull(controller);
            Assert.IsInstanceOfType(controller, typeof(TweetController));
        }
Beispiel #25
0
        public async void Patch_Record_Not_Found()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTweetResponseModel>(null));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiTweetRequestModel>();

            patch.Replace(x => x.Content, "A");

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #26
0
    /// <summary>
    /// Starts events associated with the secondary event clock and frequency
    /// </summary>
    private void StartSecondaryEvent()
    {
        //Start Events
        if (timeSinceLastSecondaryEvent > altEventFrequency)
        {
            timeSinceLastSecondaryEvent = 0;
            //Currently, there's a 40% chance of dialogue, 40% chance of tweets, and 20% chance of the nuke button
            int randInt = Random.Range(0, 5);
            if ((randInt >= 0 && randInt <= 2) && !buttonEventActive)
            {
                ButtonController bc;
                if (ButtonController.TryGetManager(out bc))
                {
                    bc.StartEvent();
                    buttonEventActive = true;
                }
            }
            else if ((randInt == 3) && !dialogueEventActive)
            {
                DialogueController dc;
                if (DialogueController.TryGetManager(out dc))
                {
                    dc.StartEvent();
                    dialogueEventActive = true;
                }
            }
            else if (!tweetEventActive)
            {
                TweetController tc;
                if (TweetController.TryGetManager(out tc))
                {
                    tc.StartEvent();
                    tweetEventActive = true;
                }
            }


            //Debug.Log("SPAWNING SECONDARY EVENT");
        }
    }
        public async void Create_No_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiTweetServerResponseModel> .CreateResponse(null as ApiTweetServerResponseModel);

            mockResponse.SetRecord(new ApiTweetServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTweetServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTweetServerResponseModel> >(mockResponse));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiTweetServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiTweetServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTweetServerRequestModel>()));
        }
        public async void BulkInsert_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiTweetServerResponseModel> >(null as ApiTweetServerResponseModel);

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTweetServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTweetServerResponseModel> >(mockResponse.Object));
            TweetController controller = new TweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiTweetServerRequestModel>();

            records.Add(new ApiTweetServerRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTweetServerRequestModel>()));
        }
Beispiel #29
0
 /// <summary>
 /// Starts events associated with the primary event clock and frequency
 /// </summary>
 private void StartPrimaryEvent()
 {
     //Start Events
     if (timeSinceLastEvent > eventFrequency)
     {
         timeSinceLastEvent = 0;
         int randInt = Random.Range(0, 5);
         if ((randInt >= 0 && randInt <= 1) && !dialogueEventActive)
         {
             DialogueController dc;
             if (DialogueController.TryGetManager(out dc))
             {
                 dc.StartEvent();
                 dialogueEventActive = true;
             }
         }
         else if ((randInt >= 2 && randInt <= 3) && !tweetEventActive)
         {
             TweetController tc;
             if (TweetController.TryGetManager(out tc))
             {
                 tc.StartEvent();
                 tweetEventActive = true;
             }
         }
         else if (!buttonEventActive)
         {
             ButtonController bc;
             if (ButtonController.TryGetManager(out bc))
             {
                 bc.StartEvent();
                 buttonEventActive = true;
             }
         }
     }
 }
 private void Awake()
 {
     instance = this;
 }