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 ApiTagClientRequestModel(); model.SetProperties(2, 1, "B", 1); CreateResponse <ApiTagClientResponseModel> result = await client.TagCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Tag>().ToList()[1].Count.Should().Be(2); context.Set <Tag>().ToList()[1].ExcerptPostId.Should().Be(1); context.Set <Tag>().ToList()[1].TagName.Should().Be("B"); context.Set <Tag>().ToList()[1].WikiPostId.Should().Be(1); result.Record.Count.Should().Be(2); result.Record.ExcerptPostId.Should().Be(1); result.Record.TagName.Should().Be("B"); result.Record.WikiPostId.Should().Be(1); }
public virtual ApiTagClientRequestModel MapServerResponseToClientRequest( ApiTagServerResponseModel response) { var request = new ApiTagClientRequestModel(); request.SetProperties( response.Count, response.ExcerptPostId, response.TagName, response.WikiPostId); return(request); }
public void MapClientRequestToResponse() { var mapper = new ApiTagModelMapper(); var model = new ApiTagClientRequestModel(); model.SetProperties(1, 1, "A", 1); ApiTagClientResponseModel response = mapper.MapClientRequestToResponse(1, 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 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); }