예제 #1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiCommentServerModelMapper();
            var model  = new ApiCommentServerResponseModel();

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

            response.Should().NotBeNull();
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostId.Should().Be(1);
            response.Score.Should().Be(1);
            response.Text.Should().Be("A");
            response.UserId.Should().Be(1);
        }
예제 #2
0
        public void CreatePatch()
        {
            var mapper = new ApiCommentServerModelMapper();
            var model  = new ApiCommentServerRequestModel();

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

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

            patch.ApplyTo(response);
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostId.Should().Be(1);
            response.Score.Should().Be(1);
            response.Text.Should().Be("A");
            response.UserId.Should().Be(1);
        }
예제 #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 ApiCommentServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ICommentService               service = testServer.Host.Services.GetService(typeof(ICommentService)) as ICommentService;
            ApiCommentServerResponseModel model   = await service.Get(1);

            ApiCommentClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiCommentClientResponseModel> updateResponse = await client.CommentUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.PostId.Should().Be(1);
            updateResponse.Record.Score.Should().Be(2);
            updateResponse.Record.Text.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }