コード例 #1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiPostHistoryServerModelMapper();
            var model  = new ApiPostHistoryServerResponseModel();

            model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1);
            ApiPostHistoryServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Comment.Should().Be("A");
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostHistoryTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RevisionGUID.Should().Be("A");
            response.Text.Should().Be("A");
            response.UserDisplayName.Should().Be("A");
            response.UserId.Should().Be(1);
        }
コード例 #2
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 ApiPostHistoryServerModelMapper();
            ApplicationDbContext context            = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IPostHistoryService  service            = testServer.Host.Services.GetService(typeof(IPostHistoryService)) as IPostHistoryService;
            ApiPostHistoryServerResponseModel model = await service.Get(1);

            ApiPostHistoryClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, "B", "B", "B", 1);

            UpdateResponse <ApiPostHistoryClientResponseModel> updateResponse = await client.PostHistoryUpdateAsync(model.Id, request);

            context.Entry(context.Set <PostHistory>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <PostHistory>().ToList()[0].Comment.Should().Be("B");
            context.Set <PostHistory>().ToList()[0].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <PostHistory>().ToList()[0].PostHistoryTypeId.Should().Be(1);
            context.Set <PostHistory>().ToList()[0].PostId.Should().Be(1);
            context.Set <PostHistory>().ToList()[0].RevisionGUID.Should().Be("B");
            context.Set <PostHistory>().ToList()[0].Text.Should().Be("B");
            context.Set <PostHistory>().ToList()[0].UserDisplayName.Should().Be("B");
            context.Set <PostHistory>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Comment.Should().Be("B");
            updateResponse.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.PostHistoryTypeId.Should().Be(1);
            updateResponse.Record.PostId.Should().Be(1);
            updateResponse.Record.RevisionGUID.Should().Be("B");
            updateResponse.Record.Text.Should().Be("B");
            updateResponse.Record.UserDisplayName.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }
コード例 #3
0
        public void CreatePatch()
        {
            var mapper = new ApiPostHistoryServerModelMapper();
            var model  = new ApiPostHistoryServerRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", "A", "A", 1);

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

            patch.ApplyTo(response);
            response.Comment.Should().Be("A");
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostHistoryTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RevisionGUID.Should().Be("A");
            response.Text.Should().Be("A");
            response.UserDisplayName.Should().Be("A");
            response.UserId.Should().Be(1);
        }