public void MapServerResponseToRequest() { var mapper = new ApiReplyServerModelMapper(); var model = new ApiReplyServerResponseModel(); model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("01:00:00")); ApiReplyServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.Content.Should().Be("A"); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ReplierUserId.Should().Be(1); response.Time.Should().Be(TimeSpan.Parse("01:00:00")); }
public void CreatePatch() { var mapper = new ApiReplyServerModelMapper(); var model = new ApiReplyServerRequestModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("01:00:00")); JsonPatchDocument <ApiReplyServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiReplyServerRequestModel(); patch.ApplyTo(response); response.Content.Should().Be("A"); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ReplierUserId.Should().Be(1); response.Time.Should().Be(TimeSpan.Parse("01:00:00")); }
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 ApiReplyServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IReplyService service = testServer.Host.Services.GetService(typeof(IReplyService)) as IReplyService; ApiReplyServerResponseModel model = await service.Get(1); ApiReplyClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, TimeSpan.Parse("02:00:00")); UpdateResponse <ApiReplyClientResponseModel> updateResponse = await client.ReplyUpdateAsync(model.ReplyId, request); context.Entry(context.Set <Reply>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.ReplyId.Should().Be(1); context.Set <Reply>().ToList()[0].Content.Should().Be("B"); context.Set <Reply>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Reply>().ToList()[0].ReplierUserId.Should().Be(1); context.Set <Reply>().ToList()[0].Time.Should().Be(TimeSpan.Parse("02:00:00")); updateResponse.Record.ReplyId.Should().Be(1); updateResponse.Record.Content.Should().Be("B"); updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.ReplierUserId.Should().Be(1); updateResponse.Record.Time.Should().Be(TimeSpan.Parse("02:00:00")); }