Exemplo 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 ApiDestinationServerModelMapper();
            ApplicationDbContext context            = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IDestinationService  service            = testServer.Host.Services.GetService(typeof(IDestinationService)) as IDestinationService;
            ApiDestinationServerResponseModel model = await service.Get(1);

            ApiDestinationClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiDestinationClientResponseModel> updateResponse = await client.DestinationUpdateAsync(model.Id, request);

            context.Entry(context.Set <Destination>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Destination>().ToList()[0].CountryId.Should().Be(1);
            context.Set <Destination>().ToList()[0].Name.Should().Be("B");
            context.Set <Destination>().ToList()[0].Order.Should().Be(2);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CountryId.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.Order.Should().Be(2);
        }
Exemplo n.º 2
0
        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 ApiDestinationClientRequestModel();

            model.SetProperties(1, "B", 2);
            CreateResponse <ApiDestinationClientResponseModel> result = await client.DestinationCreateAsync(model);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Destination>().ToList()[1].CountryId.Should().Be(1);
            context.Set <Destination>().ToList()[1].Name.Should().Be("B");
            context.Set <Destination>().ToList()[1].Order.Should().Be(2);

            result.Record.CountryId.Should().Be(1);
            result.Record.Name.Should().Be("B");
            result.Record.Order.Should().Be(2);
        }
Exemplo n.º 3
0
        public virtual ApiDestinationClientRequestModel MapServerResponseToClientRequest(
            ApiDestinationServerResponseModel response)
        {
            var request = new ApiDestinationClientRequestModel();

            request.SetProperties(
                response.CountryId,
                response.Name,
                response.Order);
            return(request);
        }
Exemplo n.º 4
0
        public void MapClientResponseToRequest()
        {
            var mapper = new ApiDestinationModelMapper();
            var model  = new ApiDestinationClientResponseModel();

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

            response.Should().NotBeNull();
            response.CountryId.Should().Be(1);
            response.Name.Should().Be("A");
            response.Order.Should().Be(1);
        }