// Update is called once per frame void Update() { //increase infection if (timeSinceSpread > timeBetweenSpread) { IncreaseInfection(); } else { timeSinceSpread += Time.deltaTime; } //timer for spreading to new region if (timeSinceInfectedNewRegion > timeBetweenInfectingNewRegion && percentInfected > .2f) { SpreadToNewRegion(); } else { timeSinceInfectedNewRegion += Time.deltaTime; } //change color ChangeColor(); percentInfected = (float)((float)infectedTrees / (float)trees); percentInfected = (float)Math.Round((Double)percentInfected, 3); //update counter if (showing) { infectionCounter.text = "Region: " + regionID + "\nHealthy Trees: " + (trees - infectedTrees).ToString() + "\nInfected Trees: " + infectedTrees.ToString() + "\nPercent Infected: " + (percentInfected * 100).ToString() + "%"; } if (infectedTrees > 0) { timeSinceFirstInfested += Time.deltaTime; } if (timeSinceFirstInfested > 10 && firstDonation == false) { FindObjectOfType <MoneyController>().AddToBankroll(firstDonationAmount); firstDonation = true; string newNews = "Region " + regionID.ToString() + " has donated $" + firstDonationAmount.ToString() + " to slow the spread"; newsController.ChangeNews(newNews); } }
public void Modify_NonExisting_News_Should_Return_400BadRequest() { // Arrange int id = this.GenerateNonExistingId(); var newNews = new NewsBindingModel { Title = "Modified title", Content = "Modified content", PublishDate = new DateTime(2013, 12, 12) }; var mockContext = new Mock <INewsData>(); mockContext.Setup(c => c.News) .Returns(this.mock.NewsRepositoryMock.Object); var newsController = new NewsController(mockContext.Object); this.SetupController(newsController); // Act var response = newsController.ChangeNews(id, newNews) .ExecuteAsync(CancellationToken.None).Result; // Assert Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); mockContext.Verify(c => c.SaveChanges(), Times.Never); }
public void Modify_Existing_News_With_InCorrect_Data_Should_Return_400BadRequest() { // Arrange var fakeNewsToModify = this.mock.NewsRepositoryMock.Object.All().FirstOrDefault(); var newNews = new NewsBindingModel { Title = "T", // invalid MinLength Content = "Modified content", PublishDate = new DateTime(2013, 12, 12) }; var mockContext = new Mock <INewsData>(); mockContext.Setup(c => c.News) .Returns(this.mock.NewsRepositoryMock.Object); var newsController = new NewsController(mockContext.Object); this.SetupController(newsController); newsController.ModelState.AddModelError("Title", "Title MinLength is 5."); // Act var response = newsController.ChangeNews(fakeNewsToModify.Id, newNews) .ExecuteAsync(CancellationToken.None).Result; // Assert var fakeNews = this.mock.NewsRepositoryMock.Object.All().ToList(); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); mockContext.Verify(c => c.SaveChanges(), Times.Never); Assert.AreEqual(fakeNewsToModify.Title, fakeNews[0].Title); Assert.AreEqual(fakeNewsToModify.Content, fakeNews[0].Content); Assert.AreEqual(fakeNewsToModify.PublishDate, fakeNews[0].PublishDate); }
public void Modify_Existing_News_With_Correct_Data_Should_Return_200OK_And_Modify_News_In_Repository() { // Arrange var fakeNewsToModify = this.mock.NewsRepositoryMock.Object.All().FirstOrDefault(); var newNews = new NewsBindingModel { Title = "Modified Title", Content = "Modified content", PublishDate = new DateTime(2013, 12, 12) }; var mockContext = new Mock <INewsData>(); mockContext.Setup(c => c.News) .Returns(this.mock.NewsRepositoryMock.Object); var newsController = new NewsController(mockContext.Object); this.SetupController(newsController); // Act var response = newsController.ChangeNews(fakeNewsToModify.Id, newNews) .ExecuteAsync(CancellationToken.None).Result; // Assert var fakeNews = this.mock.NewsRepositoryMock.Object.All().ToList(); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); mockContext.Verify(c => c.SaveChanges(), Times.Once); Assert.AreEqual(newNews.Title, fakeNews[4].Title); Assert.AreEqual(newNews.Content, fakeNews[4].Content); Assert.AreEqual(newNews.PublishDate, fakeNews[4].PublishDate); }