public async void GetAll_ReturnsData()
        {
            // arrange
            var errorCodeConverter = new ErrorCodeConverter();

            var locationServiceMoq = new Mock <ILocationService>();

            locationServiceMoq.Setup(x => x.GetAll())
            .ReturnsAsync(() => new Result <IEnumerable <Location> >(ResultCode.Success, TestLocations()));

            var dataStructureConverterMoq = new Mock <IDataStructureConverter>();

            dataStructureConverterMoq.Setup(x => x.ConvertAndMap <IEnumerable <LocationModel>, IEnumerable <Location> >(It.IsAny <string>(), It.IsAny <IEnumerable <Location> >()))
            .Returns(new Dictionary <string, object>
            {
                { "locations", TestLocations() }
            });

            var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object)
            {
                ControllerContext = DefaultControllerContext()
            };

            // act
            var result = await sut.GetAll();

            var okResult = result as OkObjectResult;
            var response = okResult.Value as Dictionary <string, object>;

            // assert
            Assert.NotNull(response.Values);
        }
        public async void GetAll_WhenFound()
        {
            // arrange
            var errorCodeConverter = new ErrorCodeConverter();

            var locationServiceMoq = new Mock <ILocationService>();

            locationServiceMoq.Setup(x => x.GetAll())
            .ReturnsAsync(() => new Result <IEnumerable <Location> >(ResultCode.Success, TestLocations()));

            var dataStructureConverterMoq = new Mock <IDataStructureConverter>();

            var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object)
            {
                ControllerContext = DefaultControllerContext()
            };

            // act
            var result = await sut.GetAll();

            var okResult = result as OkObjectResult;
            var response = okResult.Value as Dictionary <string, object>;

            // assert
            Assert.Equal(200, okResult.StatusCode);
        }
        public async void GetAll_WhenNotFound()
        {
            // arrange
            var errorCodeConverter = new ErrorCodeConverter();

            var locationServiceMoq = new Mock <ILocationService>();

            locationServiceMoq.Setup(x => x.GetAll())
            .ReturnsAsync(() => new Result <IEnumerable <Location> >(ResultCode.NotFound));

            var dataStructureConverterMoq = new Mock <IDataStructureConverter>();

            var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object)
            {
                ControllerContext = DefaultControllerContext()
            };

            // act
            var result = await sut.GetAll();

            var notFoundResult = result as NotFoundResult;

            // assert
            Assert.NotNull(notFoundResult);
        }
        public void LocationControllerShouldReturnAll()
        {
            Locations location1 = new Locations
            {
                Id            = 1,
                City          = "Somehwere",
                PostalCode    = "something",
                States        = "Somewhere",
                StreetAddress = "somewhere"
            };
            var location2 = new Locations
            {
                Id            = 2,
                City          = "Somehwere1",
                PostalCode    = "something1",
                States        = "Somewhere1",
                StreetAddress = "somewhere1"
            };

            var repoMock = new Mock <IZVRPubRepository>();

            repoMock.Setup(c => c.GetLocations()).Returns(new List <Locations>
            {
                location1, location2
            });

            var controller = new LocationsController(repoMock.Object);
            var result     = controller.GetAll();

            Assert.NotNull(result.Value);

            Assert.Same(location1, result.Value[0]);
        }
Пример #5
0
        public async void GetAllLocationsReturnsList()
        {
            //A -arrange
            var mockRepo = new Mock <ILocationRepository>();

            mockRepo.Setup(repo => repo.GetAllAsync())
            .Returns(Task.FromResult(GetTestLocations()));
            var controller = new LocationsController(mockRepo.Object);
            //A -act
            var result = await controller.GetAll();

            //A -assert
            var viewResult = Assert.IsType <ActionResult <ICollection <Location> > >(result);
            var model      = Assert.IsAssignableFrom <ICollection <Location> >(
                (viewResult.Result as ObjectResult).Value);

            Assert.Equal(2, model.Count);
        }