Esempio n. 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 ApiAddressClientRequestModel();

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

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Address>().ToList()[1].Address1.Should().Be("B");
            context.Set <Address>().ToList()[1].Address2.Should().Be("B");
            context.Set <Address>().ToList()[1].City.Should().Be("B");
            context.Set <Address>().ToList()[1].State.Should().Be("B");
            context.Set <Address>().ToList()[1].Zip.Should().Be("B");

            result.Record.Address1.Should().Be("B");
            result.Record.Address2.Should().Be("B");
            result.Record.City.Should().Be("B");
            result.Record.State.Should().Be("B");
            result.Record.Zip.Should().Be("B");
        }
        public virtual ApiAddressClientRequestModel MapServerResponseToClientRequest(
            ApiAddressServerResponseModel response)
        {
            var request = new ApiAddressClientRequestModel();

            request.SetProperties(
                response.Address1,
                response.Address2,
                response.City,
                response.State,
                response.Zip);
            return(request);
        }
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiAddressModelMapper();
            var model  = new ApiAddressClientRequestModel();

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

            response.Should().NotBeNull();
            response.Address1.Should().Be("A");
            response.Address2.Should().Be("A");
            response.City.Should().Be("A");
            response.State.Should().Be("A");
            response.Zip.Should().Be("A");
        }
Esempio n. 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 ApiAddressServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IAddressService               service = testServer.Host.Services.GetService(typeof(IAddressService)) as IAddressService;
            ApiAddressServerResponseModel model   = await service.Get(1);

            ApiAddressClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiAddressClientResponseModel> updateResponse = await client.AddressUpdateAsync(model.Id, request);

            context.Entry(context.Set <Address>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Address>().ToList()[0].Address1.Should().Be("B");
            context.Set <Address>().ToList()[0].Address2.Should().Be("B");
            context.Set <Address>().ToList()[0].City.Should().Be("B");
            context.Set <Address>().ToList()[0].State.Should().Be("B");
            context.Set <Address>().ToList()[0].Zip.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Address1.Should().Be("B");
            updateResponse.Record.Address2.Should().Be("B");
            updateResponse.Record.City.Should().Be("B");
            updateResponse.Record.State.Should().Be("B");
            updateResponse.Record.Zip.Should().Be("B");
        }