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 ApiCustomerClientRequestModel();

            model.SetProperties("B", "B", "B", "B");
            CreateResponse <ApiCustomerClientResponseModel> result = await client.CustomerCreateAsync(model);

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

            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 ApiCustomerClientRequestModel MapServerResponseToClientRequest(
            ApiCustomerServerResponseModel response)
        {
            var request = new ApiCustomerClientRequestModel();

            request.SetProperties(
                response.Email,
                response.FirstName,
                response.LastName,
                response.Phone);
            return(request);
        }
        public void MapClientResponseToRequest()
        {
            var mapper = new ApiCustomerModelMapper();
            var model  = new ApiCustomerClientResponseModel();

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

            response.Should().NotBeNull();
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
        }
        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 ApiCustomerServerModelMapper();
            ApplicationDbContext           context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ICustomerService               service = testServer.Host.Services.GetService(typeof(ICustomerService)) as ICustomerService;
            ApiCustomerServerResponseModel model   = await service.Get(1);

            ApiCustomerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiCustomerClientResponseModel> updateResponse = await client.CustomerUpdateAsync(model.Id, request);

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

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