public virtual async void TestCreate() { 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; var model = new ApiPostLinkClientRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1); CreateResponse <ApiPostLinkClientResponseModel> result = await client.PostLinkCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <PostLink>().ToList()[1].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <PostLink>().ToList()[1].LinkTypeId.Should().Be(1); context.Set <PostLink>().ToList()[1].PostId.Should().Be(1); context.Set <PostLink>().ToList()[1].RelatedPostId.Should().Be(1); result.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); result.Record.LinkTypeId.Should().Be(1); result.Record.PostId.Should().Be(1); result.Record.RelatedPostId.Should().Be(1); }
public virtual ApiPostLinkClientRequestModel MapServerResponseToClientRequest( ApiPostLinkServerResponseModel response) { var request = new ApiPostLinkClientRequestModel(); request.SetProperties( response.CreationDate, response.LinkTypeId, response.PostId, response.RelatedPostId); return(request); }
public void MapClientRequestToResponse() { var mapper = new ApiPostLinkModelMapper(); var model = new ApiPostLinkClientRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1); ApiPostLinkClientResponseModel response = mapper.MapClientRequestToResponse(1, model); response.Should().NotBeNull(); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkTypeId.Should().Be(1); response.PostId.Should().Be(1); response.RelatedPostId.Should().Be(1); }
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 ApiPostLinkServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IPostLinkService service = testServer.Host.Services.GetService(typeof(IPostLinkService)) as IPostLinkService; ApiPostLinkServerResponseModel model = await service.Get(1); ApiPostLinkClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1); UpdateResponse <ApiPostLinkClientResponseModel> updateResponse = await client.PostLinkUpdateAsync(model.Id, request); context.Entry(context.Set <PostLink>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <PostLink>().ToList()[0].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <PostLink>().ToList()[0].LinkTypeId.Should().Be(1); context.Set <PostLink>().ToList()[0].PostId.Should().Be(1); context.Set <PostLink>().ToList()[0].RelatedPostId.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.LinkTypeId.Should().Be(1); updateResponse.Record.PostId.Should().Be(1); updateResponse.Record.RelatedPostId.Should().Be(1); }