Ejemplo n.º 1
0
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiLocationServerModelMapper();
            ApplicationDbContext           context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ILocationService               service = testServer.Host.Services.GetService(typeof(ILocationService)) as ILocationService;
            ApiLocationServerResponseModel model   = await service.Get(1);

            ApiLocationClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(2, 2, "B");

            UpdateResponse <ApiLocationClientResponseModel> updateResponse = await client.LocationUpdateAsync(model.LocationId, request);

            context.Entry(context.Set <Location>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.LocationId.Should().Be(1);
            context.Set <Location>().ToList()[0].GpsLat.Should().Be(2);
            context.Set <Location>().ToList()[0].GpsLong.Should().Be(2);
            context.Set <Location>().ToList()[0].LocationName.Should().Be("B");

            updateResponse.Record.LocationId.Should().Be(1);
            updateResponse.Record.GpsLat.Should().Be(2);
            updateResponse.Record.GpsLong.Should().Be(2);
            updateResponse.Record.LocationName.Should().Be("B");
        }
Ejemplo n.º 2
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            ILocationService service = testServer.Host.Services.GetService(typeof(ILocationService)) as ILocationService;
            var model = new ApiLocationServerRequestModel();

            model.SetProperties(2, 2, "B");
            CreateResponse <ApiLocationServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.LocationDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiLocationServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Ejemplo n.º 3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiLocationServerResponseModel response = await this.LocationService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 4
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiLocationServerModelMapper();
            var model  = new ApiLocationServerResponseModel();

            model.SetProperties(1, 1, 1, "A");
            ApiLocationServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.GpsLat.Should().Be(1);
            response.GpsLong.Should().Be(1);
            response.LocationName.Should().Be("A");
        }
Ejemplo n.º 5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <ILocationService, ILocationRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Location>(null));
            var service = new LocationService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LocationModelValidatorMock.Object,
                                              mock.DALMapperMockFactory.DALLocationMapperMock,
                                              mock.DALMapperMockFactory.DALTweetMapperMock,
                                              mock.DALMapperMockFactory.DALUserMapperMock);

            ApiLocationServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 6
0
        public async void Create_Errors()
        {
            LocationControllerMockFacade mock = new LocationControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLocationServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLocationServerResponseModel> >(mockResponse.Object));
            LocationController controller = new LocationController(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 ApiLocationServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLocationServerRequestModel>()));
        }
Ejemplo n.º 7
0
        public async void All_Exists()
        {
            LocationControllerMockFacade mock = new LocationControllerMockFacade();
            var record  = new ApiLocationServerResponseModel();
            var records = new List <ApiLocationServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            LocationController controller = new LocationController(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, string.Empty);

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Ejemplo n.º 8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiLocationServerRequestModel> patch)
        {
            ApiLocationServerResponseModel record = await this.LocationService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiLocationServerRequestModel model = await this.PatchModel(id, patch) as ApiLocationServerRequestModel;

                UpdateResponse <ApiLocationServerResponseModel> result = await this.LocationService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }