Ejemplo n.º 1
0
 void MakeInstance()
 {
     if(instance == null)
     {
         instance = this;
     }
 }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        characterA = GameObject.FindWithTag("characterA");
        GameObject ply = GameObject.FindWithTag("Player");

        player             = ply.transform;
        _transform         = transform;
        _rigidbody         = rigidbody;
        normalForwardSpeed = forwardSpeed;
        chaseTarget        = characterA;
        characterAScript   = characterA.GetComponent <BirdsController> ();

        water = GameObject.FindWithTag("water").transform;
    }
Ejemplo n.º 3
0
        public async Task GetBirds_ReturnsOkObjectResult_WithABirdsObject()
        {
            // Arrange
            var mockRepo = new Mock <IBirdRepository>();

            mockRepo.Setup(repo => repo.GetBirdsAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <BirderStatus>()))
            .ReturnsAsync(GetQueryResult(30));

            var controller = new BirdsController(_mapper, _cache, _logger.Object, mockRepo.Object);

            // Act
            var result = await controller.GetBirdsAsync(1, 25, BirderStatus.Common);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);
        }
Ejemplo n.º 4
0
        public async Task GetBird_ReturnsOkObjectResult_WithABirdObject()
        {
            // Arrange
            var mockRepo = new Mock <IBirdRepository>();

            mockRepo.Setup(repo => repo.GetBirdAsync(It.IsAny <int>()))
            .ReturnsAsync(GetTestBird());

            var controller = new BirdsController(_mapper, _cache, _logger.Object, mockRepo.Object);

            // Act
            var result = await controller.GetBirdAsync(It.IsAny <int>());

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);
        }
Ejemplo n.º 5
0
        public async Task GetBirds_ReturnsNotFoundResult_WhenRepositoryReturnsNull()
        {
            // Arrange
            var mockRepo = new Mock <IBirdRepository>();

            mockRepo.Setup(repo => repo.GetBirdsDdlAsync())
            .Returns(Task.FromResult <IEnumerable <Bird> >(null));

            var controller = new BirdsController(_mapper, _cache, _logger.Object, mockRepo.Object);

            // Act
            var result = await controller.GetBirdsAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <BirderStatus>());

            // Assert
            Assert.IsType <ObjectResult>(result);
            var objectResult = result as ObjectResult;

            Assert.Equal(StatusCodes.Status500InternalServerError, objectResult.StatusCode);
            Assert.Equal($"bird repository returned null", objectResult.Value);
        }
Ejemplo n.º 6
0
        public async Task GetBird_ReturnsBadRequestResult_WhenExceptionIsRaised()
        {
            // Arrange
            var mockRepo = new Mock <IBirdRepository>();

            mockRepo.Setup(repo => repo.GetBirdAsync(It.IsAny <int>()))
            .ThrowsAsync(new InvalidOperationException());

            var controller = new BirdsController(_mapper, _cache, _logger.Object, mockRepo.Object);

            // Act
            var result = await controller.GetBirdAsync(It.IsAny <int>());

            // Assert
            Assert.IsType <ObjectResult>(result);
            var objectResult = result as ObjectResult;

            Assert.Equal(StatusCodes.Status500InternalServerError, objectResult.StatusCode);
            Assert.Equal("an unexpected error occurred", objectResult.Value);
        }
Ejemplo n.º 7
0
        public async Task GetBirds_ReturnsOkObjectResult_WithBirdSummaryViewModel()
        {
            // Arrange
            var mockRepo = new Mock <IBirdRepository>();

            mockRepo.Setup(repo => repo.GetBirdsAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <BirderStatus>()))
            //.ReturnsAsync(GetTestBirds());
            .ReturnsAsync(GetQueryResult(30));

            var controller = new BirdsController(_mapper, _cache, _logger.Object, mockRepo.Object);

            // Act
            var result = await controller.GetBirdsAsync(1, 25, BirderStatus.Common);

            // Assert
            var objectResult = result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.True(objectResult is OkObjectResult);
            Assert.Equal(StatusCodes.Status200OK, objectResult.StatusCode);
            Assert.IsAssignableFrom <BirdsListDto>(objectResult.Value);
        }
Ejemplo n.º 8
0
        public async Task GetBird_ReturnsOkObjectResult_WithBirdDetailViewModel()
        {
            // Arrange
            var birdId   = 1;
            var mockRepo = new Mock <IBirdRepository>();

            mockRepo.Setup(repo => repo.GetBirdAsync(birdId))
            .ReturnsAsync(GetTestBird());

            var controller = new BirdsController(_mapper, _cache, _logger.Object, mockRepo.Object);

            // Act
            var result = await controller.GetBirdAsync(birdId);

            // Assert
            var objectResult = result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.True(objectResult is OkObjectResult);
            Assert.Equal(StatusCodes.Status200OK, objectResult.StatusCode);
            var model = Assert.IsType <BirdDetailDto>(objectResult.Value);

            Assert.Equal(birdId, model.BirdId);
        }