Exemple #1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiProductServerModelMapper();
            var model  = new ApiProductServerResponseModel();

            model.SetProperties(1, true, "A", "A", 1m, 1);
            ApiProductServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Active.Should().Be(true);
            response.Description.Should().Be("A");
            response.Name.Should().Be("A");
            response.Price.Should().Be(1m);
            response.Quantity.Should().Be(1);
        }
Exemple #2
0
        public void CreatePatch()
        {
            var mapper = new ApiProductServerModelMapper();
            var model  = new ApiProductServerRequestModel();

            model.SetProperties(true, "A", "A", 1m, 1);

            JsonPatchDocument <ApiProductServerRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiProductServerRequestModel();

            patch.ApplyTo(response);
            response.Active.Should().Be(true);
            response.Description.Should().Be("A");
            response.Name.Should().Be("A");
            response.Price.Should().Be(1m);
            response.Quantity.Should().Be(1);
        }
        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 ApiProductServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IProductService               service = testServer.Host.Services.GetService(typeof(IProductService)) as IProductService;
            ApiProductServerResponseModel model   = await service.Get(1);

            ApiProductClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiProductClientResponseModel> updateResponse = await client.ProductUpdateAsync(model.Id, request);

            context.Entry(context.Set <Product>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Product>().ToList()[0].Active.Should().Be(true);
            context.Set <Product>().ToList()[0].Description.Should().Be("B");
            context.Set <Product>().ToList()[0].Name.Should().Be("B");
            context.Set <Product>().ToList()[0].Price.Should().Be(2m);
            context.Set <Product>().ToList()[0].Quantity.Should().Be(2);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Active.Should().Be(true);
            updateResponse.Record.Description.Should().Be("B");
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.Price.Should().Be(2m);
            updateResponse.Record.Quantity.Should().Be(2);
        }