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

            model.SetProperties("B");
            var model2 = new ApiUnitClientRequestModel();

            model2.SetProperties("C");
            var request = new List <ApiUnitClientRequestModel>()
            {
                model, model2
            };
            CreateResponse <List <ApiUnitClientResponseModel> > result = await client.UnitBulkInsertAsync(request);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();

            context.Set <Unit>().ToList()[1].CallSign.Should().Be("B");

            context.Set <Unit>().ToList()[2].CallSign.Should().Be("C");
        }
        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 ApiUnitServerModelMapper();
            ApplicationDbContext       context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IUnitService               service = testServer.Host.Services.GetService(typeof(IUnitService)) as IUnitService;
            ApiUnitServerResponseModel model   = await service.Get(1);

            ApiUnitClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiUnitClientResponseModel> updateResponse = await client.UnitUpdateAsync(model.Id, request);

            context.Entry(context.Set <Unit>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Unit>().ToList()[0].CallSign.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CallSign.Should().Be("B");
        }
        public virtual ApiUnitClientRequestModel MapServerResponseToClientRequest(
            ApiUnitServerResponseModel response)
        {
            var request = new ApiUnitClientRequestModel();

            request.SetProperties(
                response.CallSign);
            return(request);
        }
Exemple #4
0
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiUnitModelMapper();
            var model  = new ApiUnitClientRequestModel();

            model.SetProperties("A");
            ApiUnitClientResponseModel response = mapper.MapClientRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.CallSign.Should().Be("A");
        }