示例#1
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 ApiHandlerClientRequestModel();

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

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Handler>().ToList()[1].CountryId.Should().Be(2);
            context.Set <Handler>().ToList()[1].Email.Should().Be("B");
            context.Set <Handler>().ToList()[1].FirstName.Should().Be("B");
            context.Set <Handler>().ToList()[1].LastName.Should().Be("B");
            context.Set <Handler>().ToList()[1].Phone.Should().Be("B");

            result.Record.CountryId.Should().Be(2);
            result.Record.Email.Should().Be("B");
            result.Record.FirstName.Should().Be("B");
            result.Record.LastName.Should().Be("B");
            result.Record.Phone.Should().Be("B");
        }
示例#2
0
        public virtual ApiHandlerClientRequestModel MapServerResponseToClientRequest(
            ApiHandlerServerResponseModel response)
        {
            var request = new ApiHandlerClientRequestModel();

            request.SetProperties(
                response.CountryId,
                response.Email,
                response.FirstName,
                response.LastName,
                response.Phone);
            return(request);
        }
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiHandlerModelMapper();
            var model  = new ApiHandlerClientRequestModel();

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

            response.Should().NotBeNull();
            response.CountryId.Should().Be(1);
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
示例#4
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 ApiHandlerServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IHandlerService               service = testServer.Host.Services.GetService(typeof(IHandlerService)) as IHandlerService;
            ApiHandlerServerResponseModel model   = await service.Get(1);

            ApiHandlerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiHandlerClientResponseModel> updateResponse = await client.HandlerUpdateAsync(model.Id, request);

            context.Entry(context.Set <Handler>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Handler>().ToList()[0].CountryId.Should().Be(2);
            context.Set <Handler>().ToList()[0].Email.Should().Be("B");
            context.Set <Handler>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Handler>().ToList()[0].LastName.Should().Be("B");
            context.Set <Handler>().ToList()[0].Phone.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CountryId.Should().Be(2);
            updateResponse.Record.Email.Should().Be("B");
            updateResponse.Record.FirstName.Should().Be("B");
            updateResponse.Record.LastName.Should().Be("B");
            updateResponse.Record.Phone.Should().Be("B");
        }