public void MapServerResponseToRequest()
        {
            var mapper = new ApiTagServerModelMapper();
            var model  = new ApiTagServerResponseModel();

            model.SetProperties(1, 1, 1, "A", 1);
            ApiTagServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Count.Should().Be(1);
            response.ExcerptPostId.Should().Be(1);
            response.TagName.Should().Be("A");
            response.WikiPostId.Should().Be(1);
        }
        public void CreatePatch()
        {
            var mapper = new ApiTagServerModelMapper();
            var model  = new ApiTagServerRequestModel();

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

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

            patch.ApplyTo(response);
            response.Count.Should().Be(1);
            response.ExcerptPostId.Should().Be(1);
            response.TagName.Should().Be("A");
            response.WikiPostId.Should().Be(1);
        }
Ejemplo n.º 3
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 ApiTagServerModelMapper();
            ApplicationDbContext      context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ITagService               service = testServer.Host.Services.GetService(typeof(ITagService)) as ITagService;
            ApiTagServerResponseModel model   = await service.Get(1);

            ApiTagClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiTagClientResponseModel> updateResponse = await client.TagUpdateAsync(model.Id, request);

            context.Entry(context.Set <Tag>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Tag>().ToList()[0].Count.Should().Be(2);
            context.Set <Tag>().ToList()[0].ExcerptPostId.Should().Be(1);
            context.Set <Tag>().ToList()[0].TagName.Should().Be("B");
            context.Set <Tag>().ToList()[0].WikiPostId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Count.Should().Be(2);
            updateResponse.Record.ExcerptPostId.Should().Be(1);
            updateResponse.Record.TagName.Should().Be("B");
            updateResponse.Record.WikiPostId.Should().Be(1);
        }