public virtual async void TestDelete() { 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; IPostLinkService service = testServer.Host.Services.GetService(typeof(IPostLinkService)) as IPostLinkService; var model = new ApiPostLinkServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, 1); CreateResponse <ApiPostLinkServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.PostLinkDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPostLinkServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
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); }