public virtual async void TestCreate()
        {
            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;

            var model = new ApiLocationClientRequestModel();

            model.SetProperties(2, 2, "B");
            CreateResponse <ApiLocationClientResponseModel> result = await client.LocationCreateAsync(model);

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

            result.Record.GpsLat.Should().Be(2);
            result.Record.GpsLong.Should().Be(2);
            result.Record.LocationName.Should().Be("B");
        }
        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");
        }
Beispiel #3
0
        public virtual ApiLocationClientRequestModel MapServerResponseToClientRequest(
            ApiLocationServerResponseModel response)
        {
            var request = new ApiLocationClientRequestModel();

            request.SetProperties(
                response.GpsLat,
                response.GpsLong,
                response.LocationName);
            return(request);
        }
        public void MapClientResponseToRequest()
        {
            var mapper = new ApiLocationModelMapper();
            var model  = new ApiLocationClientResponseModel();

            model.SetProperties(1, 1, 1, "A");
            ApiLocationClientRequestModel response = mapper.MapClientResponseToRequest(model);

            response.Should().NotBeNull();
            response.GpsLat.Should().Be(1);
            response.GpsLong.Should().Be(1);
            response.LocationName.Should().Be("A");
        }