public virtual async void TestDelete()
        {
            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;

            IProductService service = testServer.Host.Services.GetService(typeof(IProductService)) as IProductService;
            var             model   = new ApiProductServerRequestModel();

            model.SetProperties(true, "B", "B", 2m, 2);
            CreateResponse <ApiProductServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.ProductDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiProductServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
示例#2
0
        public void MapServerRequestToResponse()
        {
            var mapper = new ApiProductServerModelMapper();
            var model  = new ApiProductServerRequestModel();

            model.SetProperties(true, "A", "A", 1m, 1);
            ApiProductServerResponseModel response = mapper.MapServerRequestToResponse(1, 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);
        }
示例#3
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);
        }